THIS IS A C++ CODE. Please dont use the one found online. Use object oriented pr
ID: 3888207 • Letter: T
Question
THIS IS A C++ CODE. Please dont use the one found online. Use object oriented programming techniques.
Program the game of battleship against the computer. Each side
has 2 grids. The first grid contains the location of the player’s ships. The second grid contains the location of the player’s shots and the outcome of the shot (hit or miss). The objective is to hit and sink all 5 enemy ships before they do the same to you. Each side recieves ships listed in figure 1.
Add statements to the main() function to do the following:
The grids are 10 x 10 squares.
Use whatever method is expedient to generate the computer
moves; this isn’t an AI class.
Constraints.
• Filter the input for valid numbers.
• Use Object Oriented Programming techniques.
• Use a Ship class.
• Use an assert to protect at least two of your methods.
carrier- size 5
Battleship- size 4
crusier- size 3
sub- size 3
destroyer- size 2
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'; 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; }placeShip; //Functions void LoadShips(); void ResetBoard(); void DrawBoard(int); PLACESHIPS UserInputShipPlacement(); int main() { LoadShips(); ResetBoard(); //"PLACE SHIPS" phase of game //Loop through each player... for (int aplyr=1; aplyrRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.