Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do part B following the steps in c++ Overview In this assignment, you will simulate a simple board game. The board is a grid, and

Do part B following the steps in c++ image text in transcribed
image text in transcribed
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 (..) 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. Warning: The test programs used in this course sometimes capture and tests the output from the cout buffer. Therefore, you must use cout to print your output. If you print it in some other way, (e.g. using print for cerr), the test program will not see it. Then you will get a mark of zero for that portion of the assignment. 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 'O' 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 $1 $1 $1 $1 $2 $2 $2 $ 2 $2 $1 $2 $3 $3 $3 $2 $1 $2 $3 $4 $3 $2 $1 $2 $3 $3 $3 $2 $1 $2 $2 $2 $2 $2 $1 $1 $1 $1 $1 $1 $1 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); In Part E, you will add helper functions with the following prototypes: void boardprintColumnNameRow (); void boardPrintBorder Row (); void boardprintEmptyRow 0); void boardprintDataRow (const Board board, int row): 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 tinclude "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 boardPrintDatakow. You can use the same syntax on Hercules (or any similar system) when entering commands. For example, g++ -e ..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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions

Question

Discuss the key ambient conditions and their effects on customers.

Answered: 1 week ago

Question

Be familiar with the integrative servicescape model.

Answered: 1 week ago

Question

Understand the role of corporate design in communications.

Answered: 1 week ago