Using Battleship.cpp (included) : Aircraft carrier = \'A\' =length 5 Battleship
ID: 3695908 • Letter: U
Question
Using Battleship.cpp (included) :
Aircraft carrier = 'A' =length 5
Battleship = 'B' = length 4
Submarine = 'S' =length 3
Cruiser = 'C' =length 3
Destroyer = 'D' =length 2
For this part, you need to make your program work for 5 pieces. The program should work as before, except you need to place 5 pieces and sink all 5 of the opponents pieces to win. [Hint: It will be much easier to use arrays and loops to do this.] You do not need to adjust the logic for reading from file (it will error and exit if there are not enough ships defined in the file). Ensure you can place/hit all 5 ships and win when all 5 of their ships are sunk.
Battleship.cpp
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; aplyrRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.