Question: Overview In this assignment, you will simulate a simple board game. The board is a grid, and starts with a pile of money in each

Overview

In this assignment, you will simulate a simple board game. The board is a grid, and starts with a pile of money in each cell. Players take turns rolling four dice to pick a cell, and then taking the money from there. If the cell is rolled again, the money will already be gone. The program will be divided into a main function and three supporting modules. A C++ module is a combination of a header (.h) file and a source (.cpp) file with the same base file name, e.g., Dice.h and Dice.cpp. A test program will be provided for each module. When the game runs, it will print out the board, the numbers rolled and the cell hit, and how much money the player receives. Then, the player will have the chance to quit the game. If he/she doesn't, the process will be repeated for the next player.

The main purpose of this assignment is to give you practice using two-dimensional arrays, including passing two-dimensional arrays to functions. For Part A, you will add constants and functions relating to the size of the game board. For Part B, you will add functions to handle the game board itself. For Part C, you will add constants and functions related to simulated dice. For Part D, you will use the constants and functions from Parts A, B, and C to write the game program. Then, for Part E, you will improve the display of the game board.

Another purpose of this assignment is to familiarize you with multi-file programs. To keep the assignment from getting to be too long, the files are small and the functions are mostly short. Many functions only contain a single line of code.

The Game Board

The game board will be represented as a 2-dimensional array. It is 7 x 7 cells in size. The elements of the array will store the amount of money in the different grid cells. The grid rows will be named using the (uppercase) letters 'A' to 'G', and the grid columns will be named using the digits '0' to '6'. Thus, each cell will have a unique name such as A2 (row 0, column 2) or E6 (row 4, column 6).

The cells on the board will start with more or less money depending on how close they are to the center. Specifically, the cells on the edge will each have $1, the next row of cells inside them will each have $2, then $3, and the center cell will have $4. At game start, the board will look as follows:

$1 $1 $1 $1 $1 $1 $1

$1 $2 $2 $2 $2 $2 $1

$1 $2 $3 $3 $3 $2 $1

$1 $2 $3 $4 $3 $2 $1

$1 $2 $3 $3 $3 $2 $1

$1 $2 $2 $2 $2 $2 $1

$1 $1 $1 $1 $1 $1 $1

In Part E the display of the game board will be revised to look as follows:

0 1 2 3 4 5 6

+-------------------------------------+

| |

A | $1 $1 $1 $1 $1 $1 $1 | A

| |

B | $1 $2 $2 $2 $2 $2 $1 | B

| |

C | $1 $2 $3 $3 $3 $2 $1 | C

| |

D | $1 $2 $3 $4 $3 $2 $1 | D

| |

E | $1 $2 $3 $3 $3 $2 $1 | E

| |

F | $1 $2 $2 $2 $2 $2 $1 | F

| |

G | $1 $1 $1 $1 $1 $1 $1 | G

| |

+-------------------------------------+

0 1 2 3 4 5 6

The Dice

The simulated dice have four sides with the values 0, 1, 2, and 3. When choosing a grid cell in the game, two dice are rolled and their values are added to give the row number. For example, if 1 and 3 were rolled, the row would be 1 + 3 = 4. Another two dice are rolled and added to choose the column. As a result, the cells near the center will be chosen more frequently.

The program will use symbols to print the dice values so that they look like they are on dice. For example:

Row Column

+---+ +---+ +---+ +---+

| 2 | | 3 | | 1 | | 0 |

+---+ +---+ +---+ +---+

Here, row 2 + 3 = 5 and column 1 + 0 = 1 were rolled, so the cell chosen is F1.

Requirements

Part B: The Game Board [25% = 20% test program + 2% output + 3% code]

In Part B, you will create functions related to the board itself. Put the function prototypes in a file named Board.h and the function implementations in a file named Board.cpp.

By the end of Part B, you will have functions with the following prototypes:

void boardInit (Board board);

int boardGetAt (const Board board, int row, int column);

void boardSetAt (Board board, int row, int column, int value);

void boardPrint (const Board board);

Perform the following steps:

  1. In Board.cpp, use #include to include the library, "BoardSize.h", and "Board.h". Remember to put using namespace std;.
  2. In Board.h, use typedef to define a Board type corresponding to a 2D array of ints with dimensions BOARD_SIZE and BOARD_SIZE. The typedef uses the BOARD_SIZE constant, so Board.h should #include "BoardSize.h".
  3. In Board.h, copy in the function prototypes shown above.
  4. In Board.cpp, add an implementation for the boardInit function that sets all the elements of the array. The values should depend on the array position, as described in The Game Board above. You must use at least two loops in the implementation.
    • Hint: Use a pair of nested for loops for the initialization.
    • Hint: Start by initializing all the elements of the board to the same value, such as 1. Then, after that works, change your function to set them to the correct values.
    • Hint: The abs function from the library returns the absolute value of a variable. So abs(v - MIDDLE) will return how far v is from MIDDLE. It will help you to figure out how far you are from the middle of the array.
  5. Add an implementation for the boardGetAt function that returns the amount of money at the specified position. The function must determine the value from the array.
  6. Add an implementation for the boardSetAt function that sets the amount of money at the specified array position to the specified value.
  7. Add an implementation for the boardPrint function that prints the array contents in the first (simpler) format shown under The Game Board above. The four functions named boardPrint* listed above will be used in Part E to print the board in the second format.
    • Note: The * in boardPrint* is a common computer science convention for "anything". So boardPrint* means boardPrintColumnNameRow, boardPrintBorderRow, boardPrintEmptyRow, and boardPrintDataRow. You can use the same syntax on Hercules (or any similar system) when entering commands. For example, g++ -c *.cpp will compile all the files in the current directory that have a .cpp extension.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!