Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

c++ image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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 (.1) 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 Parte, 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 printf or 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$2 $2 $2 $2 $1 S1 $2 S3 $3 $2 $2 $3 $3 $3 $2 $2 $1 $1 $1 $1 $3 $3 $2 $1 $4 $3 $2 $1 $2 $2 $2 $1 $1 $1 $1 $1 $1 $2 $1 $1 In Part E the display of the game board will be revised to look as follows: 0 1 2 3 4 5 1 $1 $1 $1 $1 $1 $1 $1 $1 $2 92 $2 1 IB $2 52 $1 1 $1 $2 $3 $3 $3 $2 $2 $1 $2 $3 $4 $3 $2 $1 1 D 1 El 1 1 ID 1 E $1 $2 $3 $3 $3 $2 $1 $2 $2 $2 $2 $2 $1 1 $1 $1 1 $1 $1 $1 $1 $1 $1 0 1 2 3 4 5 6 +-------+ 111101 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 ---- | 21 31 Here, row 2 + 3 - 5 and column I 0 - 1 were rolled, so the cell chosen is F1. Requirements Part A: The Board Size (20% test program] In Part A, you will create constants and functions related to the board size. Put the constants and function prototypes in a file named Boardsize.h and the function implementations in a file named Boardsize.cpp. Throughout this course, make sure that you use exactly the specified file names, which are case sensitive. Here, B and s are uppercase and the remaining letters are lowercase. By the end of Part A, you will have functions with the following prototypes: char getRowName (int row): char getColumnName (int column) Perform the following steps: 1. As the first line in Boardsize.h and every other header (. h) file for the rest of the course, put the following line: pragma once This line tells the C++ compiler to only compile this file once even if it happens to be #included multiple times: 2. In Boardsize.h, define BOARD_SIZE and BOARD_CELL_COUNT as integer constants BOARD_SIZE should have a value of 7 and BOARD CELL_COUNT should have a value of BOARD_SIZE. BOARD_SIZE. 3. In Boardsize. h. copy in the function prototypes shown above. You are now finished BoardSize.h 4. Near the top of Boards ize.cpp, add the following command: #include "Boardsize.h" 5. Add an implementation for the getRowName function that returns the name character for that row. For example, if o is passed in as the row parameter, then the name character is 'A', so *A' should be returned. Hint: You can use mathematical operators, such as addition and Subtraction on chars. The uppercase letters form a sequence, so you can add 'A' + 2 and get C'. The same kinds of operations apply to lowercase letters and to digits. 6. Add an implementation for the getColumnName function that returns the character name of that column. Hint: Column names are chars starting with 'O' and ' + 3 -3 7. Test your Boardsize module using the TestBoardSizel.cpp program provided. You will also need the TestHelper.h and Test Helper.cpp files. Note: All the test programs for the game will use the same TestHelper.h and TestHelper.cpp files Note: For additional information on compiling programs consisting of multiple files, please consult link Part B: The Game Board (25% = 20% test program + 2% output + 3% code] In Part 8, 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 boardprintBorderRow (): void boardprintEmptyRow(); 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 chars with dimensions BOARD_SIZE and BOARD_SIZE. The typedef uses the BOARD_SIZE constant, so Board.h should include "Boardsize.h". 3. In Boardin, 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. S. 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 boarderint is a common computer science convention for "anything". So boardprint means boardprintcolumnName Row, boardprintBorder RowboardprintEmptyRow, and boardprintDataRow. You can use the same syntax on Hercules (or any similar system) when entering commands. For example, 9++ -c.cpp will compile all the files in the current directory that have a .cpp extension 8. Test your Board module using the TestBoardl.cpp program provided. Again, you will need Tent Helper.h and TentHelper.cpp Part C:Simulated Dice (10% = 7% test program + 3% output) In Part C. you will add constants and functions related to rolling dice. Put the constants and functions in Dice.h and the function implementations in Dice.cpp: By the end of Part C. you will have functions with the following prototypes: void diceInit(); int diceroll (): void dicePrint2and2 (int ri, int r2, int cl, int c2): Perform the following steps: 1. Indice.cpp include the , cestdlib>, and

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

Students also viewed these Databases questions

Question

a neglect of quality in relationship to international competitors;

Answered: 1 week ago