////////////////////////////////////////////////////////////////////////// // Sink the Fleet declarations // by Paul Bladek // compiled using MS Visual C++.Net 2005 // March 4, 2006 ////////////////////////////////////////////////////////////////////////// #ifndef FLEET_H #define FLEET_H #include #include #include #include #include #include #include "textGraphics.h" #include "safeio.h" using namespace std; // Graphic characters const short NUMPLAYERS = 2; // number of players in game const short SMALLROWS = 8; // number of rows/columns in small sea array const short LARGEROWS = 10; // number of rows/columns in large sea array const short SMALLCOLS = 12; // number of rows/columns in small sea array const short LARGECOLS = 24; // number of rows/columns in large sea array const short BOXWIDTH = 79; // maximum screen line length const int SHIP_SIZE_ARRAYSIZE = 6; // size of the shipSize array const short shipSize[SHIP_SIZE_ARRAYSIZE] = {0, 2, 3, 3, 4, 5}; // number of elements for each ship enum Ship // enumerated type for ships { NOSHIP, // 0 MINESWEEPER, // 1 (1-5) -- used only for owner SUB, // 2 FRIGATE, // 3 BATTLESHIP, // 4 CARRIER, // 5 HIT, // 6 (6-7)-- used only for other side MISSED, // 7 }; enum Direction // enumerated type for direction on grid { HORIZONTAL, // 0 VERTICAL // 1 }; struct Cell // row and column location { unsigned short m_row; // row unsigned short m_col; // column }; struct ShipInfo // needed info about each ship { Ship m_name; // which ship? Direction m_orientation;// which direction is the ship facing? Cell m_bowLocation; // which cell is the bow location? short m_piecesLeft; // how many sections of the ship are left undestroyed? }; struct Player // needed info about each player { Ship ** m_gameGrid[NUMPLAYERS]; // one 2-d array for each player // [0] is player's grid; [1] is apponant's grid ShipInfo m_ships[SHIP_SIZE_ARRAYSIZE]; // the ships in the fleet-- [0] is blank short m_piecesLeft; // how many sections of the ships in the fleet are left undestroyed? }; // function prototypes for ship void printShip(ostream & sout, Ship thisShip);// prints to sout one individual ship Ship inputShip(istream & sin); // inputs a ship number from sin and returns a ship bool isSunk(Ship thisShip); // returns true if ship has been sunk (no points left) void printGrid(ostream& sout, Ship** grid, char size); // prints a specific game grid // function prototypes for ShipInfo void setShipInfo(ShipInfo * shipInfoPtr, Ship name = NOSHIP, Direction orientation = HORIZONTAL, unsigned short row = 0, unsigned short col = 0); // sets ShipInfo fields // function prototypes for Player void initializePlayer(Player* playerPtr); // sets initial values for m_ships and m_piecesLeft void allocMem(Player players[], char size); // allocates memory for grids void deleteMem(Player players[], char size); // deletes memory for grids void saveGrid(Player players[],short whichPlayer, char size); // saves the ship grid to a file bool getGrid(Player players[], short whichPlayer, char size, string fileName); // reads grid from a file void setShips(Player players[], char size, short whichPlayer); // allows user to put ships in grid Cell getCoord(istream& sin, char size); // returns a cell with coordinates set by user bool validLocation(const Player& player, short shipNumber, char size); // can the ship go there? // prints out the full order to sout // ... // other function prototypes void header(ostream& sout); // prints opening graphic void endBox(short player); // prints closinging graphic // ... #endif