The goal of this lab is to write a program that allows the user to play a
Question:
The goal of this lab is to write a program that allows the user to play a version of Quispe, a dice-rolling game. The rules of the game are simple. In our version of the game, there are two players, the user and the computer. Each player rolls a pair of dice (2). The rolls are scored in the following manner:
First, die | Second Die | Score |
---|---|---|
4 | 5 | 45 |
2 | 3 | 23 |
3 | 3 | 300 |
6 | 6 | 600 |
1 | 2 | 1000 (Quispe!) |
2 | 1 | 1000 (Quispe!) |
When a 1 and 2 are rolled, in any order, that roll is called a Quispe and is worth 1000 points automatically.
Anytime the two dice match each other then the score is 100 times one of the dice (since they are the same, it doesn't matter which one is used).
- For example: If both dice roll a 5 then the score is calculated as 5 * 100 = 500. If both dice roll a 2 then the score is calculated as 2 * 100 = 200.
All other roll cases are simply scored by combining the two dice rolls together by multiplying the first number by 10 and adding the second:
- For example a 6 * 10 + 1 = 61
The user gets to re-roll one of the pair of dice if they choose. The user gets to choose which die to re-roll. Display all rolls and scores.
The user should be allowed to play as long as he or she wishes, and your program should keep a running tally of the total points that each has accumulated.
An example of the program output can be seen below or by looking at the test cases attached to this assignment. Please look at the example output first to get a better feel for what the goal of this program is.
PROGRAM DETAILS
When creating this game, you will need to write at least one other function outside of your main() function.
- A function named getScore should be used to calculate the score for a given roll. getScore should take in two numbers as parameters to the function (the two rolls from each die), and return an integer that contains the correct score based on the given inputs.
You will find that it will be much easier to reach the solution of this program if you break it down into smaller steps. For example:
First, build the getScore() function as specified above. Test this function with a couple of example values in main() to make sure it is functioning correctly. If your getScore matches the chart shown above you have a good start.
Build the logic that asks for an integer from the user to seed the random number generator.
Generate the dice values and scores for both the user and computer's first rolls and display these to the program output as shown in the sample execution
Build the logic that allows the user to reroll a die or keep their current score. (Hint: While loop for validating the user input)
Finally, build the prompt that allows the user to either play the game again or stop playing and print out the total scores (Hint: while loop)
There are 6 tests.
- Test 1 tests the correct scoring of Quispe and a basic roll (no Quispe and no doubles). It also tests keeping the original roll and stopping the loop. It does not check white space.
- Test 2 tests the correct scoring of doubles. It also tests the re-rolling (and re-scoring) option. It does not check white space. Test 2 is worth 20 points.
- Test 3 tests white space.
- Test 4-6 tests to make sure that your getScore() is functioning correctly.