write a program consisting of three Python classes (Die, Player, and Game), plus a main function that drives the program. The three classes are as follows
The Die Class
Your starting point for this class can be copied from the Rephactor textbook or from the example we did in class. The one modification that you must make is that the roll method should return the newly rolled value.
The Player Class
The Player class represents a single player. The instance data of a Player includes the player's name, two Die objects, and a mechanism for keeping track of which results have been rolled for this player. That mechanism is left up to you. One suggestion is to use a dictionary that maps the possible roll results (2 through 12) to a boolean value indicating whether that result has been rolled. But there are other ways you might keep track of this information.
The constructor of the Player class should accept a single argument representing the player's name.
The Player class should include the following methods:
__init__ - The initializer should accept the player's name as a parameter, then set up all instance data for a player. That is, it should store the name, create two Die objects, and set up the mechanism you choose to use to keep track of the rolled results.
__str__ - The string dunder method should return a string of the form 'Player Bob' with the appropriate player name.
get_name - This method should return the player's name (without the 'Player' prefix).
roll_dice - This method should roll both dice and return their sum.
update_status - This method should accept a value that has been rolled and update the status of this player. That is, it should update whatever mechanism you choose to use to keep track of the results that this player has rolled. This method does not return a value.
rolled_all - This method should return True if all possible values (2 to 12) have been rolled by this player, and False otherwise.
Note: the only method in the Player class that accepts an argument (other than self) is the initializer and the update_status method.
The Game Class
The Game class represents the game itself. The instance data of the Game includes only the two Player objects who are playing the game.
The constructor of the Game class should accept a the names of the two players.
The Game class should include the following methods:
__init__ - The initializer should create and store the two Player objects.
play_round - This method should play one complete round of the game. It should have both players roll their dice, print the value rolled for each player, then update the status of each player.
winner - This method will be called after each round is played to determine if there is a winner. It should return the word 'none' if no player has rolled all of the needed results. It should return 'tie' if both players finished in the same round. Otherwise, it should return the name of the player that won. Think about the logic of this method carefully and write clean, well-structured code.
Note that the Game class does not need a __str__ dunder method.
The main Function
The only function in this file is the main function that serves as the driver of the program. It accepts no parameters.
The main function should read the names of the two players from the user, then create a Game object. It should then use a loop to play rounds of the game until one (or both) of the players wins. After the loop it should print the result: print 'They tied!' if both players finished in the same round, or print the winner as shown in the sample run above.
Other than the main function, the only code in this module should be the following, at the end of the file:
Here is a sample run of the program as seen in the console window. User input is shown in blue:
What is the name of the first player? Bob
What is the name of the second player? Sue
Round 1
Player Bob rolled a 6
Player Sue rolled an 8
Round 2
Player Bob rolled a 10
Player Sue rolled a 7
Round 3
Player Bob rolled a 6
Player Sue rolled a 12
and so on...
Round 31
Player Bob rolled a 3
Player Sue rolled an 11
Round 32
Player Bob rolled an 8
Player Sue rolled a 10
The winner is Sue! Congratulations!