Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Part D, you will convert the game board to contain tiles instead of ints. By the end of Part D, the function prototypes will
In Part D, you will convert the game board to contain tiles instead of ints.
By the end of Part D, the function prototypes will be:
void boardInit (Board board);
const Tile& boardGetAt (const Board board, int row, int column);
void boardSetAt (Board board, int row, int column, const Tile& value, unsigned int owner);
void boardPrint (const Board board);
void boardPrintColumnNameRow ();
void boardPrintBorderRow ();
void boardPrintEmptyRow ();
void boardPrintDataRow (const Board board, int row);
Perform the following steps:
- Add an #include for "Tile.h" in Board.cpp. The function prototypes will need to refer to tiles, so also add it in Board.h.
- Change the Board type so it corresponds to a 2D array of Tiles instead of integers. Change the boardGetAt function to return a constant reference to a Tile. Change the boardSetAt function to take a constant reference to a Tile as the value parameter.
- Change the function implementations for boardGetAt and boardSetAt to match the changes to the prototypes. The boardGetAt function should return a const reference to a Tile. The boardSetAt function should take a const reference to a Tile as a parameter.
- Hint: In boardSetAt, you should return the value directly from the array. Do not create a temporary Tile variable. If you do, the calling function will get a reference to a variable that doesn't exist anymore and Bad Stuff will happen.
- In boardInit, initialize the tiles by calling the tileCreate function. All of the tiles should have genus GENUS_MONEY. The old money value should become the tile species.
- Example: The command to set the board will look something like the following, although it will not use GENUS_INVALID or 47: my_board[here][there] = tileCreate(GENUS_INVALID, 47);
- Change the boardPrintDataRow function to display tiles instead of printing spaces, dollar signs, and numbers. Call a function from the Tile module to display a tile. Print a suitable number of spaces between the tiles. If your board matches the example exactly, you will need to print two spaces between tiles.
- Change the boardSetAt function to also set the tile owner. Add an additional parameter in the interface (.h) and implementation (.cpp) files (if you haven't already). After setting the element of the array, it should call a function from the Tile module to set that tile's owner.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started