Template Dice. Using the Templated Method Design Pattern,
modify the
templated
games example as follows. Add a game of Dice where
two players try to get the higher score by rolling five dice up to
three times. A single dice roll should be a random number from 1-6.
Thus, the minimum score is 5 and the maximum is 30. The first player
is the computer. The computer randomly selects whether to roll again
or pass and keep the score. The second player is human. The program
should print the round number, the outcome of the round (for both
human and computer) and ask whether the human wants to roll again or
pass. The game ends either after three moves (rounds) or when both
players decide to pass and keep the score. In the end, the program
should print the scores and declare the winner (human or
computer). Computer wins if the score is tied. Here is an example
dialog:
Round 1: Computer rolled: 1 2 3 5 6, computer's score = 17
You rolled: 1 2 5 3 1, your score = 12
Roll again? [y/n] y
Round 2: Computer rolled: 2 3 1 5 1, computer's score = 12
You rolled: 6 6 3 1 5, your score = 21
Roll again? [y/n] n
Round 3: Computer rolled: 5 5 5 6 3, computer's score = 24
You rolled: passed, your score = 21
You lose!
In the template method example, you should not modify the base class
template method, you should only write primitive operations for the
new derived class Dice