Program specification:
For this assignment you will write a program that simulates a rather simplistic Dice Throwing Game. This section specifies the required functionality of the program. Only a text interface is required for this program; however, more marks will be gained for a program that is easy/intuitive to use, with clear information/error messages to the user.
The aim of the Dice Throwing Game is to simulate a simple game for 2 players, where they take turn to each roll a dice twice, and score points according to the results of the dice rolls. The winner is the one who accumulates a pre-defined maximum score first. Your program will display a menu which allows the user of the program to select various options to simulate the various operations. Results of all the operations will be printed on the screen as plain text only (eg. “Andy rolled 5 + 3, and scored 8 points”).
The “dice rolls” are simulated by the program, using some random number generator. The program will update each player's current score accordingly. For this assignment, the program will only handle TWO players. It will keep track of the current score of the players until one, or both, reaches the pre-defined maximum score, agreed upon at the start of the game.
Program Logic:
The Dice Throwing Game begins with a welcome message followed by a menu with the following options :
Option (1) asks the 2 players to enter their names. A player’s name must not be blank (or consists of only spaces and nothing else), but may contain spaces between the characters. If this option is chosen again after the players have already been set up, 2 "new" players are set up (ie. with 2 new names, and both their starting scores set to 0). Note that the new players replace the previous players – there are only ever two players at any one time.
After the names are set up, the game asks for a maximum score. The default maximum score should be set to 200 points. Each player’s initial score is set to 0.
Option (2) simulates the “dice roll” operations for both players. When this option is chosen, the computer generates 4 random numbers between 1-6 (ie. simulating a 6-sided dice), representing 2 dice rolls for each player. It then updates both players' scores accordingly. The scoring rules for each "round" are as follows :
- if the 2 dice rolls have the same value (ie. 1&1, 2&2, …, 6x6), the player scores 2 times the sum of that value (eg. 1&1 scores 4 points, 2&2 scores 8 points, etc)
- if the 2 dice rolls have different values, the player simply scores the sum of that value (eg. 1&4 scores 5 points, 5&2 scores 7 points, etc)
- if both players reaches a score which is more than the pre-defined maximum, the game’s result is a Draw. note that both players can reach over that score at the same time, since for each round, 2 dice rolls are performed for each player, before a winner is decided
- a
if the 2 dice rolls have the same value (ie. 1&1, 2&2, …, 6x6), the player scores 2 times the sum of that value (eg. 1&1 scores 4 points, 2&2 scores 8 points, etc)
player is considered a winner if he accumulates a score which is moreif the 2 dice rolls have different values, the player simply scores the sum of that value (eg. 1&4 scores 5 points, 5&2 scores 7 points, etc)
than the pre-defined maximum, and the other player has not reachedif both players reaches a score which is more than the pre-defined maximum, the game’s result is a Draw. note that both players can reach over that score at the same time, since for each round, 2 dice rolls are performed for each player, before a winner is decided
that scorea player is considered a winner if he accumulates a score which is more than the pre-defined maximum, and the other player has not reached that score
Option (3) shows the players current scores, including who is leading the game.
Option (4) displays some brief instructions regarding how to play the game.
Option (5) exits the whole program. All player statistics should be cleared.
Additional Notes :
The menu must be displayed repeatedly after each operation, until the user chooses Option (5). Inputs other than 1-5 should be rejected, with appropriate error messages printed.
If the user chooses Option (2)/(3), before a game has been set up (Option (1)), an appropriate error message should be printed, and the operation aborted.
Your program must deal with invalid values entered by the user in a sensible manner.