Thread: Problems in creating a Battleships board

  1. #1
    Registered User TheYeIIowDucK's Avatar
    Join Date
    Aug 2010
    Posts
    3

    Problems in creating a Battleships board

    Hey there, i'm new to C++ programming (as you can probably can tell). After learning the basics from the Cprogramming.com site, i decided to create my own little game (Battleships).
    I just started working and i already got a problem. For some reason, my board() function doesn't work and it doesn't display the player's board when i call it.
    I don't know what could be the problem. I checked it several times and i can't see anything wrong with it.
    Here's my entire code, i case my problem lays somewhere else:
    Code:
    #include <iostream>
    
    using namespace std;
    
    short plyrBoard[9][9];//The player's board status, his ships' locations and stuff like that.
    short plyrView[9][9];//The PC's status as the player sees it (hits/misses).
    short aiBoard[9][9];//The PC's full board status
    short aiView[9][9];//The player's status as the PC sees it
    short brd[9][9];//The basic board
    /* Key:
    0 = Empty
    1 = Boat
    2 = Ship
    3 = Submarine
    4 = Aircarrier
    5 = Damaged or destroyed */
    
    void board(); //Displaying the player's board
    void boardCreate(); //Creating the diffrent boards (should only used once)
    
    int main()
    {
        cout<<"Welcome to BattleshipsAI by TheYeIIowDucK!\n\n\n\n\n\n\n"<<endl;
        cout<<"Start by choosing your ships' positions."<<endl;
        void boardCreate();
        void board();
        short rdy;
        do
        {
              //This part is under construction...
        } while (rdy == 0);
    }
    
    
    void boardCreate()
    {
        short i;
        short l;
        short k = 8;
        for (i = 0 ; i < 9 ; i++)
        {
            k = k + 2;
            for (l = 0 ; l < 9 ; l++)
            {
                k++;
                brd[i][l] = k;
                plyrBoard[i][l] = 0;
                plyrView[i][l] = 0;
                aiBoard[i][l] = 0;
                aiView[i][l] = 0;
            }
        }
    }
    
    void board()
    {
        short i;
        short l;
        for (i = 0 ; i < 9 ; i++)
        {
            for (l = 0 ; l < 9 ;l++)
            {
                switch (plyrBoard[i][l])
                {
                    case 0:
                        cout<<brd[i][l]<<" ";
                        break;
                    case 1:
                        cout<<"BO ";
                        break;
                    case 2:
                        cout<<"SH ";
                        break;
                    case 3:
                        cout<<"SU ";
                        break;
                    case 4:
                        cout<<"AI ";
                        break;
                    case 5:
                        cout<<"XX ";
                        break;
                    default:
                        cout<<"ERROR";
                        break;
                }
            }
            cout<<"\n"<<flush;
        }
    }
    That's what i get:
    http://img837.imageshack.us/img837/3...8201014024.png

    Any help on this one?

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    35
    Quote Originally Posted by TheYeIIowDucK View Post
    Code:
        void boardCreate();
        void board();
        short rdy;
        do
        {
              //This part is under construction...
        } while (rdy == 0);
    }
    There is your problem. You're not actually calling these functions here.

    Code:
        boardCreate();
        board();
        short rdy;
        do
        {
              //This part is under construction...
        } while (rdy == 0);
    }

  3. #3
    Registered User TheYeIIowDucK's Avatar
    Join Date
    Aug 2010
    Posts
    3
    Oh thank you dear sir!
    That worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling GNU MP
    By mattnp12 in forum C Programming
    Replies: 3
    Last Post: 06-23-2011, 03:58 PM
  2. C# vs ASM board
    By Yarin in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 01-28-2009, 05:18 AM
  3. Put the board on "watch"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 11-14-2001, 09:27 AM
  4. Welcome to the FAQ Board
    By kermi3 in forum FAQ Board
    Replies: 0
    Last Post: 11-01-2001, 10:33 AM
  5. Where's the old board...?
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 09-18-2001, 01:16 PM