Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the bottom of the main loop (after getting user input), increment the current player. Then, if the number is too high, reset it to 0.

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

the bottom of the main loop (after getting user input), increment the current player. Then, if the number is too high, reset it to 0.

  1. Before printing whose turn it is, print the board using one of your functions.

  2. After printing whose turn it is, get four dice rolls, two for the row and two for the column. You will need to call one of your functions four times and save the results in four variables. Print them out using another one of your functions. Calculate the row and column of the cell and then print "Rolled cell: " followed by the cell name. Use the two functions from the BoardSize module when printing the cell name.

    Example: If the values rolled were 0, 1, 2, and 3, the output would be: Row Column

    +---+ +---+ +---+ +---+ |0||1| |2||3| +---+ +---+ +---+ +---+ Rolled cell: F1

  3. Determine how much money was in the cell using the boardGetAt function. Increase the current player's money by that amount. Remove the money from the board, using a function to set it to 0.

    Print a message showing how much the player's money increased, such as:

     Money: $4 + $2 = $6 

Part E: Improved Game Board Display [10% output]

In Part E, you will improve the display of the game board. By the end, it will look like the revised game board shown under The Game Board above.

Perform the following steps:

  1. Add an implementation for the boardPrintDataRow function. It should print the values for one row of the board in the same format as in Part B. Change your boardPrint function to call theboardPrintDataRow function.

  2. Add the border to the game board. Add an implementation for the boardPrintBorderRow function. You will also need to call it and update the boardPrintDataRow function.

    Note: At this point, your game boarder will be smaller than the one in the example output.

  3. Increase the spacing between the values on the game board. Add an implementation for the

    boardPrintEmptyRowfunction. YouwillneedtoupdateboardPrintandtwootherfunctions.

  4. Print the row and column labels on the four sides of the game board. Add an implementation for theboardPrintColumnNameRowfunction. CallthegetRowNameandgetColumnNamefunctions. Update the appropriate other functions.

CS 115: Assignment 1 2021-01-21, 2:15 PM CS 115: Assignment 1 2021-01-21, 2:15 PM the bottom of the main loop (after getting user input), increment the current player. Then, if the number is too high, reset it to 0. 7. Before printing whose turn it is, print the board using one of your functions. 8. After printing whose turn it is, get four dice rolls, two for the row and two for the column. You will need to call one of your functions four times and save the results in four variables. Print them out using another one of your functions. Calculate the row and column of the cell and then print "Rolled cell: " followed by the cell name. Use the two functions from the BoardSize module when printing the cell name. Example: If the values rolled were 0, 1, 2, and 3, the output would be: Row Column +---+ | 2 | 3 101 111 ----+ +--- Rolled cell: F1 exactly one digit. 7. Test your Dice module using the TestDicel.cpp program provided. Once again, you will need TestHelper, hand TestHelper.cpp.cpp. Part D: The Game [35% = 28% output + 7% code] In Part D, you will make a simple game using the modules from Parts A, B, and C. The game will consist of a main function in its own file named Main.cpp. a function 1. Put #includes for the and libraries in Main.cpp as well as for all of your header files. Reminder: Whenever you #include standard libraries such as , you will also need the line: using namespace std; Reminder: Put #pragma once at the top of every header (. h) file. Reminder: Do not put #pragma once in any source (.cpp) file. Reminder: Never #include any source (.cpp) file into any other file. 2. Add a main function. It should start by initializing the Dice module using one of your functions. Then it should declare a 2D array of ints to be the game board and initialize it using another one of your functions. 3. Define a constant with the value 2 for the nun of players. Declare a 10 array for the that the players have and initialize its two elements to O. After all the initialization is done, print a message to welcome the players to the game. Note: We will refer to the two players as Player O and Player 1. 4. Add a main loop to your main function. This is a loop that will run continually until the program terminates. Each time through the loop, print "> " to prompt the user and then read a line of user input using getline. If the input is ever "q", the loop should end. Hint: The getline function takes two parameters, the input stream and the string to set. To read a line of console input into a variable named line, the syntax would be: getline (cin, line); 9. Determine how much money was in the cell using the boardGetAt function. Increase the current player's money by that amount. Remove the money from the board, using a function to set it to 0. Print a message showing how much the player's money increased, such as: Money: $4 + $2 = $6 Part E: Improved Game Board Display (10% output] In Part E, you will improve the display of the game board. By the end, it will look like the revised game board shown under The Game Board above. Perform the following steps: 1. Add an implementation for the boardPrint DataRow function. It should print the values for one row of the board in the same format as in Part B. Change your boardprint function to call the boardprint DataRow function. 2. Add the border to the game board. Add an implementation for the boardprintBorder Row function. You will also need to call it and update the boardprint Data Row function. Note: At this point, your game boarder will be smaller than the one in the example output. 3. Increase the spacing between the values on the game board. Add an implementation for the board PrintEmptyRow function. You will need to update boardprint and two other functions. 4. Print the row and column labels on the four sides of the game board. Add an implementation for the boardprintColumnNameRow function. Call the getRowName and getColumnName functions. Update the appropriate other functions. Formatting (-10% if not done] 1. Neatly indent your program using a consistent indentation scheme. 2. Put spaces around your arithmetic operators: x = x + 3; 3. Use symbolic constants, such as BOARD_SIZE, when appropriate. Note: We will fill in the contents of the main loop below. For your information: Most interactive programs have a main loop. In a graphical program, it is often called an event loop and checks for input events such as mouse movement and keystrokes. 5. After the main loop, print out how much money each player has. The message should include the player number and the money value with a dollar sign. Then print a closing message. The remainder of the steps refer to the contents of the main loop: 6. Declare a variable outside the main loop to keep track of the current player number and initialize it to 0. At the top of the loop, print "Player X's turn", where x is the current player number. At Page 6 of 8 http://www2.cs.uregina.ca/-anima/115/Terms/202110/Assignments/Assignment1/Assignment1.htm Page 7 of 8 http://www2.cs.uregina.ca/-anima/115/Terms/202110/Assignments/Assignment1/Assignment1.htm Page 2 of 8 202101 21 21 CS 1151 CB 115 1 2021 01 21 216 PM In Part E the display of the game board will be revised to look as follows: 2 $1 9. $2 $- $2 $2 I 1 $2 $2 $1 1 $ $2 93 $3 $3 $2 1 12 $2 $3 $3 $2 $ 1 E 92 32 $3 $3 $3 $2 $1 1 | E E 1 F $1 $2 $2$2$2 $2 $2 G 92 $2 $2 $3 $1 1 Perform the following steps: 1. As the first line in BoardSize.h and every other header (..) file for the rest of the course, put the following line: tracms unce This line tells the C++ compiler to only compile this file once even if it happens to be tincluded multiple times: 2. In Beerdsize.n, define BOARD SIZE and BCARD CELL COUNT as integer constants. DCARD SIZE should have a value of 7 and DCARD CELL COUNT should have a value of BCARD SIZE - BOARD SIZE. 3. In BcardSize.n, copy in the function prototypes shown above. You are now finished Boardsize.h. 4. Near the top of EcerdSize.cpy, add the following command: tinclude "Baard in." 5. Add an implementation for the get RowWame function that returns the name character for that row. For example, it is passed in as the row parameter, then the name character is 'A', SO 'A' should be retumed. 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 yetColumiNane function that returns the character name of that colurnn. Hint: Column names are chars starting with 'o', and 'O' + 3 -- '?'. 7. Test your Boardsize module using the TestBoardSizei.cpo program provided. You will also need the helpar.h and Tastelpay.spp files. Note: All the test programs for the game will use the same Testfelper.h and TeatHelper.opp files. Note: For additional information on compiling programs consisting of multiple files, please consult link. 1 2 3 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 dioe. For example: Column ROW | 2 | 3 +---+ +---+ + +---+ +---+ Here, row 2 + 3 - 5 and colurrin 1 + 0 -- were rolled, so the cell chosen is Fi. 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 Roardsite.h and the function implementations in a file named BoardSize.cep. 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) Part B: The Game Board [25% = 20% test program + 2% output + 3% code] In Part B, you will create functions related to the board Itselt. Put the function prototypes in a file named Board.h and the function implementations in a file narned Board.opp. By the end of Part B, you will have functions with the following prototypes: void boardinit (Board board) int boardgatat (const Board board int row, int column) void boardsetAt (Board board, int row, int column, haw.cs.ro.carinarim.202 100.citronssirenthin 2.cs.ro.com.arinamm. 202 100cm Assignment CS 1151 2027 01 21 2151 CS 115 41 2021 01 21 215 TestHelpex.h and TestHelper.opp int value); void boardprint (const Board board): In Part E, you will add helper functions with the following prototypes: void boardprintColumnName Row (); void board PrintBorderRow(); void boardprintEmpty Row (): void boardPrintDataRow (const Board board, int row) 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 D-ce. I and the function implementations in Dice.cop. By the end of Part C. you will have functions with the following prototypes: void diceInit() int diceRoll (): void dicePrint2and2 (int rl, int r2, int el, int c2): Perform the following steps: 1. In Board.cpp, use tinclude to include the costream> library, "boardsaze.", and "Poard.". 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 POARD_SIX- and BOARD_812. The typedef uses the BOARD_9.2E constant, so Buard. I should include "Boardsize.lt". 3. In Board, h, copy in the function prototypes shown above. 4. In Dceru.cyp, add an implementation for the boardini, 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: Theats function from the library returns the absolute value of a variable. So A.DE (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 boardGetzt function that retums the amount of money at the specified position. The lunction 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 hoarderint listed above will be used in Part E to print the board in the second format. Note: The in boardprint is a cornmon computer science convention for "arything". So boardprint means boardprintcolumnNameRow, boardprintBorderkow, boardPrintEmptyRow, and boardPrintDatakow. You can use the same syntax on Hercules (or any similar system) when entering commands. For example, 9++ -* *.cop will compile all the files in the current directory that have a .cpp extension. 8. Test your Board module using the Dest.Boerdl.cpo program provided. Again, you will need Perform the following steps: 1. In Dice.cpo, include the costream>, , 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

Recommended Textbook for

Auditing and Assurance Services A Systematic Approach

Authors: William Messier Jr, Steven Glover, Douglas Prawitt

10th edition

77732502, 978-0077732509

More Books

Students also viewed these Accounting questions

Question

Describe the team dynamics at Facebook.

Answered: 1 week ago