Can someone help me write a basic c code for the game battle

Can someone help me write a basic c++ code for the game battle ship
Can someone help me write a basic c++ code for the game battle ship

Solution

The following is a very basic code for battle ship game-

#include <iostream>
#include <string>
#include <stdlib.h>
#include <iomanip>
#include <vector>

const int empty = 0; // for water
const int occupied = 1; // for ship
const int missed = 2; // shot missed in ocean
const int hit = 3; // shot hit the target

using namespace std;

int game[ 10 ][ 10 ]; // 2-D array defined for gamefield

void initialize_game( int array1[ 10 ][ 10 ] ) // Function to provide initial value to the gamefield.
{
// create a blank field   
for (int x=0; x<10; x++) {
for (int y=0; y<10; y++) {
array1[x][y] = occupied;
}   
}   
}

void print_game(int array2[10][10]) {
for(char a = \'A\'; a <= \'J\'; a++) { //coordinates of letters
       cout << setw(5) << a;
}
cout << endl;

for(int i = 1; i <= 10; i++) { //coordinates of number
if(i == 10)
       cout << i;
   else
       cout << \" \" << i ;

for(int j = 0; j < 10 ; j++) {

   if(array2[i][j] == occupied || array2[i][j] == empty){
               cout << setw(5) << \" |\" ;
           }
else if(array2[i][j] == missed ) {
cout << setw(5) << \"O|\";
           }
   else if(array2[i][j] == hit ) {
       cout << setw(5) << \"X|\";
   }
   }
cout << \"\ \";
}
}

class cShip //Unused so far
{
   int a1, b1, a2, b2; // front and back position of the ship
   int size;
   int damage[]; // in order to sort the damage.
   public:
   cShip(int a1, int b1, int a2, int b2, int size); // constructor is defined
   ~cShip(); // destructor to destroy sorted array (damage array)
   bool isDestroyed(); // in order to polling the destroyed
   bool is3(int x, int y); // in order to polling the 3      
};

int main()
{
   initialize_game(game);
   determine_player_choice();
   print_gamegame);
  
   return 0;
}

Can someone help me write a basic c++ code for the game battle ship Can someone help me write a basic c++ code for the game battle shipSolutionThe following is
Can someone help me write a basic c++ code for the game battle ship Can someone help me write a basic c++ code for the game battle shipSolutionThe following is

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site