the whole thing is there and the scaf is if highlighed
Code:
#include <iostream>
#include <windows.h>
using namespace std;
int choose(){
int numb;
scanf( "%d", &numb );
system("color 12");
cout << " S I N K M Y B A T T L E S H I P!!!!!\n";
if(numb < 0 || numb > 12){
cout<<"Invalid choice, choose again.\n";
numb = choose();
}
return numb;
}
void board(int graph[][12])
{
int i;
int j;
cout << " A B C D E F G H I J K L\n";
cout << "----------------------------\n";
for(i = 0; i < 12; i++){
printf( "%d", i );
for(j = 0; j < 12; j++){
if(graph[i][j] == 0)
cout<< " " ;
else if(graph[i][j] == 1)
cout<< "X" ;
else if(graph[i][j] == 2)
cout<<"-" ;
}
cout<<"\n" ;
}
cout<<"\n" ;
}
void shoot(int graph[][12], int ships[][12], int y, int x, int *game)
{
if(graph[y][x] == 1 || graph[y][x] == 2){
cout<<"This space has already been chosen, choose another space\n" ;
cout<< "Row:" ;
y = choose();
cout<<"Column:";
x = choose();
shoot(graph, ships, y, x, game);
}
else{
if(ships[y][x] == 1){
cout<<"HIT!\n";
graph[y][x] = 1;
ships[y][x] = 0;
}
else if(ships[y][x] == 0){
cout<< "Miss.\n" ;
graph[y][x] = 2;
}
}
int k;
int l;
int check = 0;
for(k = 0; k < 12; k++){
for(l = 0; l < 12; l++){
if(ships[k][l] == 1)
check = 1;
}
}
if(check == 1)
game = 0;
}
int main()
{
int graph1[12][12] = {{0}, {0}};
int ships1[12][12] = {{0}, {0}};
int graph2[12][12] = {{0}, {0}};
int ships2[12][12] = {{0}, {0}};
int y;
int x;
int gamestatus = 1;
while(gamestatus == 1){
cout<< "\nPlayer 1's turn\n" ;
board(graph2);
cout<<"Row:" ;
y = choose();
cout<<"Column:" ;
x = choose();
shoot(graph2, ships2, y - 1, x - 1, &gamestatus);
if(gamestatus == 0){
cout<< "PLAYER 1 WINS!\n" ;
break;
}
cout<<"\nPlayer 2's turn.\n" ;
board(graph1);
cout<<"Row:" ;
y = choose();
cout<<"Column:" ;
x = choose();
shoot(graph1, ships1, y - 1, x - 1, &gamestatus);
if(gamestatus == 0)
cout<<"PLAYER 2 WINS!\n" ;
else
cout<<"\nNext round.\n" ;
}
return 0;
}