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

I am working on a final project in C++ and am required to write a classic game o

ID: 1858383 • Letter: I

Question

I am working on a final project in C++ and am required to write a classic game of Battleship that will print out two grids at the same time. One is for the computer and the other is for human. "Here are the instructions that needs to be followed": You will have two six by six grids on which you will place two adjacent 0’s. The computer will also select locations for the two adjacent 0’s on the second grid but will not display them. Then you and the computer will alternately guess the location of the 0’s on the other grid. The winner will be the side that guesses the location first. I need the code as soon as possible.

Explanation / Answer

#include #include using namespace std; const int BOARD_WIDTH = 15; const int BOARD_HEIGHT = 10; const int SHIP_TYPES = 5; const char isWATER = 247; //ASCII Character Code const char isHIT = 'X'; const char isSHIP = 'S'; const char isMISS = '0'; struct POINT { //A location on the grid defined //by X(horizontal) Y(vertical) coordinates int X; int Y; }; struct SHIP { //Ship name string name; //Total points on the grid int length; //Coordinates of those points POINT onGrid[5]; //0-4 max length of biggest ship //Whether or not those points are a "hit" bool hitFlag[5]; }ship[SHIP_TYPES]; struct PLAYER { char grid[BOARD_WIDTH][BOARD_HEIGHT]; }player[3]; //Ignore player 0, just using player's 1 & 2 enum DIRECTION {HORIZONTAL,VERTICAL}; struct PLACESHIPS { DIRECTION direction; SHIP shipType; }; bool gameRunning = false; //Functions void LoadShips(); void ResetBoard(); void DrawBoard(int); PLACESHIPS UserInputShipPlacement(); bool UserInputAttack(int&,int&,int); bool GameOverCheck(int); int main() { LoadShips(); ResetBoard(); //"PLACE SHIPS" phase of game //Loop through each player... for (int aplyr=1; aplyr
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