This question refers to the subroutine PlayDiceGame.
The dice game in the Skeleton Program is very simple – the player and the other character both roll a die and whoever gets the highest number wins.
The PlayDiceGame subroutine is to be changed to a more complex dice game. All other parts of the subroutine are to remain the same – no changes should be made to checking that it is possible to play the dice game or to what happens when the player wins, loses or draws the game.
In the new game the player rolls their die three times. The largest of the numbers they roll is multiplied by 100 and the second largest of the numbers they roll is multiplied by 10. The results of these two multiplications are added together along with the smallest of the numbers they rolled to give the player’s total score.
The other character’s die is also rolled three times. The second number they roll is multiplied by 10 and the third number they roll is multiplied by 100. The results of these two multiplications are added together along with the first number they rolled to give their total score.
As with the original dice game, whoever has the highest total score wins the game and if the scores are the same the result is a draw.
The program should display the result of each die roll for each player and the total scores obtained by both players.
New dice game examples
• The player rolls a 4, then a 2 and then a 3. Their total score is 4×100 + 3×10 + 2 = 432. The other character rolls a 5, then a 2, then a 3. Their total score is 3×100 + 2×10 + 5 = 325. The player’s score is higher so they win the game.
• The player rolls a 2, then a 3 and then a 4. Their total score is 4×100 + 3×10 + 2 = 432. The other character rolls a 6, then a 1, then a 4. Their total score is 4×100 + 1×10 + 6 = 416. The player’s score is higher so they win the game.
What you need to do
Task 1 Modify the subroutine PlayDiceGame.
Task 2 Test that the changes you have made work by playing the new dice game with the guard twice:
run the Skeleton Program
load the file flag2.gme
enter the command playdice guard
choose a minimum value of 1 and a maximum value of 6 for the player’s die each time the die is rolled
if the player wins the game take any item from the guard; if the guard wins the game and the randomly selected item to take from the player is the player’s die then you will need to re-run the Skeleton Program and load the file flag2.gme again before completing the next part of the test
enter the command playdice guard
choose a minimum value of 1 and a maximum value of 6 for the player’s die each time the die is rolled.