Question: So I am having trouble here the code is Okay but here is my problem this part : player[3]; can not be a global any
So I am having trouble here the code is "Okay" but here is my problem this part : player[3]; can not be a global any idea on how to change it so it is not? the rest of the code is below this part where i am having trouble
struct PLAYER { char grid[BOARD_WIDTH][BOARD_HEIGHT]; }player[3]; //Ignore player 0, just using player's 1 & 2 ================================================================================ #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<3; ++aplyr) { //Loop through each ship type to place for (int thisShip=0; thisShip > x >> y; if (x<0 || x>=BOARD_WIDTH) return goodInput; if (y<0 || y>=BOARD_HEIGHT) return goodInput; goodInput = true; return goodInput; } PLACESHIPS UserInputShipPlacement() { int d, x, y; PLACESHIPS tmp; //Using this as a bad return tmp.shipType.onGrid[0].X = -1; //Get 3 integers from user cin >> d >> x >> y; if (d!=0 && d!=1) return tmp; if (x<0 || x>=BOARD_WIDTH) return tmp; if (y<0 || y>=BOARD_HEIGHT) return tmp; //Good data tmp.direction = (DIRECTION)d; tmp.shipType.onGrid[0].X = x; tmp.shipType.onGrid[0].Y = y; return tmp; } void LoadShips() { //Sets the default data for the ships //we plan to include in the game //IMPORTANT!! > MUST MATCH SHIP_TYPES -Default=5 (0-4) ship[0].name = "Cruiser"; ship[0].length = 2; ship[1].name = "Frigate"; ship[1].length = 3; ship[2].name = "Submarine"; ship[2].length = 3; ship[3].name = "Escort"; ship[3].length = 4; ship[4].name = "Battleship"; ship[4].length = 5; } void ResetBoard() { //Loop through each player for (int plyr=1; plyr<3; ++plyr) { //For each grid point, set contents to 'water' for (int w=0; w = 10) //Numbers 2 characters long, add only 1 space after cout << w << " "; } cout << " "; //Loop through each grid point and display to console for (int h=0; h
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
