Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. . Part D: The Game (35% = 28% Output + 7% code] In Part D, you will make a simple game using the modules

image text in transcribed
image text in transcribed
image text in transcribed
. . 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. 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 ma in 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 number of players. Declare a 10 array for the money that the players have and initialize its two elements to 0. 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. 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 get line 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); Note: We will fill in the contents of the main loop below. . 4 . . . 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 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, Ind 3, the output would be: Row Column +---+ +--- 101 11 2.1 --- + Rolled cell: 1 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 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. 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 ma in 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 number of players. Declare a 10 array for the money that the players have and initialize its two elements to 0. 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. 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 get line 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); Note: We will fill in the contents of the main loop below. . 4 . . . 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 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, Ind 3, the output would be: Row Column +---+ +--- 101 11 2.1 --- + Rolled cell: 1 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

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

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

Recognize the four core purposes service environments fulfill.

Answered: 1 week ago