For this project, I have devised a unique dice game to give you lots of practice in writing conditional statements, as well as utilizing other skills we have learned throughout this semester so far. The set-up is very simple:
- You are playing against the computer
- The object is to see if you can end up with a higher score than the computer
- Scores may be negative
- Over and over, you will roll the dice, followed by the computer. This will happen until you decide to stop the game.
- At the end -- that is, after you choose to stop -- the program will announce both players' (yours and the computer's) final scores and the winner.
Points are allocated according to a very intricate set of rules, based upon the values of each individual die and the sum of both. Whenever a player rolls the dice:
- When the value of second die is greater than the value of the first die, the player will increase their own score by the difference (and lower their opponent's score by the same) if the difference is odd.
- If the difference is even, however, they will lower their own score by the difference and increase their opponent's by the same.
- On the other hand, if the value of the first die is greater than the value of the second die, they will lower their own score by the difference (and increase their opponent's score by the same) if the difference is odd.
- If the difference is even, however, they will increase their own score by the difference and lower their opponent's by the same.
- If the two dice are equal, then the player will increase their score by the sum of the positive factors of the total -- up to but not including the total.
The whole program will consist of three Python files:
- dice.py: Defines the Die class. A Die object has a max value (always 6), a current face value, and several behaviors - the most important one being roll(), which "rolls" the die and returns a random value between 1 and 6
- die_cli.py: Quite literally, the Command Line Interface for the program -- with the code driving user interaction and directing the other parts of the program. Notice that none of the internal logic of rolling dice or updating scores is taking place in this class!
- dice_player.py: Defines the DicePlayer class, which represents the player (and their computer opponent). It takes care of "rolling" the dice, keeping track of score, and updating both player's and opponent's scores based upon the roll.
The only file you will have to write code for is dice_player.py, in three of its methods:
- present_scores: Write code to assign to the variable current_leader the String representing whichever player is ahead -- or "Actually, it's a tie!" (when the two scores are the same)
- final_scores: Same as the previous, for the variable winner.
- do_roll: This is a complex method that will need to accomplish a number of things:
- Announce that the player is rolling. (Already taken care of.)
- Roll and get the values of each die - first and second - along with their difference (and sum, if needed.)
- Announce what the player has rolled: the value of each die (in order) and the sum of the two.
- Based on the values: Make a decision about how to update each player's score, make the updates, and announce the nature of the updates. (See the sample output below.)