Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So this is basic BattleShip game written in C++ language. it should use 6*6 boar

ID: 3816125 • Letter: S

Question

So this is basic BattleShip game written in C++ language.

it should use 6*6 board. This is a single player game where player tries to guess where computer placed 2 ships. (size 2 and 3)

Basic explaination and requirement is printed below.

It must use arrays and no strings.

Thank you very much.

Learning objectives: The intent of this programing project is to allow you the opportunity to demonstrate your ability to solve problems using procedural C++ programming. This project will focus on using loops, functions, random numbers, and arrays in the implementation of a modified version of the board game Battleship Program Description: In this project, you will write a C++ program that simulates a modified version of the board game Battleship. In this version there will only be one player who will try to find the two ships, a Destroyer and a Submarine, that the computer has randomly placed somewhere on the 6x6 grid board (i.e. the ocean) The Destroyer take-up two positions in the 6x6 grid whereas the Submarine takes up three positions. Ships can only be place horizontally or vertically on the 6x6 grid. Destroyer Submarine

Explanation / Answer

A)

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

const int empty = 0; // contains water
const int occupied = 1; // contains a ship
const int missed = 2; // shot into ocean
const int hit = 3; // shot and hit

using namespace std;

int board[ 10 ][ 10 ]; // Two-dimensional array for gameboard.

void initialize_board( int array1[ 10 ][ 10 ] ) // Function to initialize the gameboard.
{
// create a blank board   
for (int x=0; x<10; x++) {
for (int y=0; y<10; y++) {
array1[x][y] = occupied;
}   
}   
}

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

for(int i = 1; i <= 10; i++) { //number coordinates
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 x1, y1, x2, y2; // The position of the front and back of the ship
   int size;
   int damage[]; // for storing the damage.
   public:
   cShip(int x1, int y1, int x2, int y2, int size); // constructor
   ~cShip(); // destructor for destroying the damage array
   bool isDestroyed(); // for polling the destroyed
   bool is3(int x, int y); // for polling the 3      
};
int main()
{
   initialize_board(board);
   determine_player_choice();
   print_board(board);
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote