G
gonzo86
Hey, Im kind of new to C++ and I'm working on making a Battleship
program. I need to be able to output a screen with just dots on it for
when people havent tried those spots and then be able to switch it with
the characters in my array after they have been picked. This is the
code I have so far. Right now all all I want to do is make a game where
you have to sink the computers ships in less than 50 turns. Thanks for
any help that I get.
void battleShip:lay()
{
char map [8][8];
map[0][0] = '*';
map[0][1] = '*';
map[0][2] = '*';
map[0][3] = 'x';
map[0][4] = 'x';
map[0][5] = 'x';
map[0][6] = 'x';
map[0][7] = 'x';
map[0][8] = 'x';
map[1][0] = 'x';
map[1][1] = 'x';
map[1][2] = 'x';
map[1][3] = 'x';
map[1][4] = 'x';
map[1][5] = 'x';
map[1][6] = 'x';
map[1][7] = 'x';
map[1][8] = 'x';
map[2][0] = 'x';
map[2][1] = 'x';
map[2][2] = 'x';
map[2][3] = 'x';
map[2][4] = 'x';
map[2][5] = 'x';
map[2][6] = 'x';
map[2][7] = 'x';
map[2][8] = '*';
map[3][0] = 'x';
map[3][1] = 'x';
map[3][2] = 'x';
map[3][3] = 'x';
map[3][4] = 'x';
map[3][5] = '*';
map[3][6] = 'x';
map[3][7] = 'x';
map[3][8] = '*';
map[4][0] = 'x';
map[4][1] = 'x';
map[4][2] = 'x';
map[4][3] = 'x';
map[4][4] = 'x';
map[4][5] = '*';
map[4][6] = 'x';
map[4][7] = 'x';
map[4][8] = '*';
map[5][0] = 'x';
map[5][1] = 'x';
map[5][2] = 'x';
map[5][3] = 'x';
map[5][4] = 'x';
map[5][5] = '*';
map[5][6] = 'x';
map[5][7] = 'x';
map[5][8] = 'x';
map[6][0] = 'x';
map[6][1] = '*';
map[6][2] = '*';
map[6][3] = 'x';
map[6][4] = 'x';
map[6][5] = '*';
map[6][6] = 'x';
map[6][7] = 'x';
map[6][8] = 'x';
map[7][0] = 'x';
map[7][1] = 'x';
map[7][2] = 'x';
map[7][3] = 'x';
map[7][4] = 'x';
map[7][5] = 'x';
map[7][6] = 'x';
map[7][7] = 'x';
map[7][8] = 'x';
map[8][0] = 'x';
map[8][1] = 'x';
map[8][2] = '*';
map[8][3] = '*';
map[8][4] = '*';
map[8][5] = '*';
map[8][6] = '*';
map[8][7] = 'x';
map[8][8] = 'x';
system("cls");
cout<< endl;
cout<< " RADAR SCREEN " <<endl;
cout<< " |=====================================| " <<endl;
cout<< " | 1 2 3 4 5 6 7 8 9 | " <<endl;
cout<< " |1 . . . . . . . . . | " <<endl;
cout<< " |2 . . . . . . . . . | " <<endl;
cout<< " |3 . . . . . . . . . | " <<endl;
cout<< " |4 . . . . . . . . . | " <<endl;
cout<< " |5 . . . . . . . . . | " <<endl;
cout<< " |6 . . . . . . . . . | " <<endl;
cout<< " |7 . . . . . . . . . | " <<endl;
cout<< " |8 . . . . . . . . . | " <<endl;
cout<< " |9 . . . . . . . . . | " <<endl;
cout<< " |=====================================| " <<endl<<endl;
for(z=0; z<50; z++)
{
cout<< " Enter the coordinates to fire at: ";
cin>> x;
cin>> y;
cout<< map[x-1][y-1];
}
}
program. I need to be able to output a screen with just dots on it for
when people havent tried those spots and then be able to switch it with
the characters in my array after they have been picked. This is the
code I have so far. Right now all all I want to do is make a game where
you have to sink the computers ships in less than 50 turns. Thanks for
any help that I get.
void battleShip:lay()
{
char map [8][8];
map[0][0] = '*';
map[0][1] = '*';
map[0][2] = '*';
map[0][3] = 'x';
map[0][4] = 'x';
map[0][5] = 'x';
map[0][6] = 'x';
map[0][7] = 'x';
map[0][8] = 'x';
map[1][0] = 'x';
map[1][1] = 'x';
map[1][2] = 'x';
map[1][3] = 'x';
map[1][4] = 'x';
map[1][5] = 'x';
map[1][6] = 'x';
map[1][7] = 'x';
map[1][8] = 'x';
map[2][0] = 'x';
map[2][1] = 'x';
map[2][2] = 'x';
map[2][3] = 'x';
map[2][4] = 'x';
map[2][5] = 'x';
map[2][6] = 'x';
map[2][7] = 'x';
map[2][8] = '*';
map[3][0] = 'x';
map[3][1] = 'x';
map[3][2] = 'x';
map[3][3] = 'x';
map[3][4] = 'x';
map[3][5] = '*';
map[3][6] = 'x';
map[3][7] = 'x';
map[3][8] = '*';
map[4][0] = 'x';
map[4][1] = 'x';
map[4][2] = 'x';
map[4][3] = 'x';
map[4][4] = 'x';
map[4][5] = '*';
map[4][6] = 'x';
map[4][7] = 'x';
map[4][8] = '*';
map[5][0] = 'x';
map[5][1] = 'x';
map[5][2] = 'x';
map[5][3] = 'x';
map[5][4] = 'x';
map[5][5] = '*';
map[5][6] = 'x';
map[5][7] = 'x';
map[5][8] = 'x';
map[6][0] = 'x';
map[6][1] = '*';
map[6][2] = '*';
map[6][3] = 'x';
map[6][4] = 'x';
map[6][5] = '*';
map[6][6] = 'x';
map[6][7] = 'x';
map[6][8] = 'x';
map[7][0] = 'x';
map[7][1] = 'x';
map[7][2] = 'x';
map[7][3] = 'x';
map[7][4] = 'x';
map[7][5] = 'x';
map[7][6] = 'x';
map[7][7] = 'x';
map[7][8] = 'x';
map[8][0] = 'x';
map[8][1] = 'x';
map[8][2] = '*';
map[8][3] = '*';
map[8][4] = '*';
map[8][5] = '*';
map[8][6] = '*';
map[8][7] = 'x';
map[8][8] = 'x';
system("cls");
cout<< endl;
cout<< " RADAR SCREEN " <<endl;
cout<< " |=====================================| " <<endl;
cout<< " | 1 2 3 4 5 6 7 8 9 | " <<endl;
cout<< " |1 . . . . . . . . . | " <<endl;
cout<< " |2 . . . . . . . . . | " <<endl;
cout<< " |3 . . . . . . . . . | " <<endl;
cout<< " |4 . . . . . . . . . | " <<endl;
cout<< " |5 . . . . . . . . . | " <<endl;
cout<< " |6 . . . . . . . . . | " <<endl;
cout<< " |7 . . . . . . . . . | " <<endl;
cout<< " |8 . . . . . . . . . | " <<endl;
cout<< " |9 . . . . . . . . . | " <<endl;
cout<< " |=====================================| " <<endl<<endl;
for(z=0; z<50; z++)
{
cout<< " Enter the coordinates to fire at: ";
cin>> x;
cin>> y;
cout<< map[x-1][y-1];
}
}