Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a GUI class called Craps that implements the die game craps. This question asks you to write an event handler that deals with a
Write a GUI class called Craps that implements the die game craps. This question asks you to write an event handler that deals with a single round of the game. To understand how to write the handler, you need to remember how the game works. It begins with the player throwing a pair of standard, sixsided dice. If the player rolls a or in the first round, the player wins. If the player rolls a or in the first round, the player loses. For any other roll the player must roll again to determine whether heshe won. During subsequent rounds, the player wins if heshe rolls point, that is rolls the same total as heshe did during the first round. During subsequent rounds, the player loses if heshe rolls a In the template file you will find a GUI that has all the methods completed except for the event handler play. The following is a description of the methods that are already written. None of these methods should be modified as you complete this question:
init: The constructor creates the main window, sets the title, calls the newgame method, and calls the makewidgets method.
newgame: This method resets the first roll variable in the object. When the first roll is set to it means that the player has just begun a new game. Once the player has rolled for the first time the first roll is set to the total of the two dice, something that happens in the handler you will write.
makewidgets: This method creates the four labels, four entries, and button necessary for the GUI to function.You will write the play method which is the event handler attached to the button. When the GUI is first created by calling Crapsmainloop the GUI will appear as follows:The entries are used for displaying the rolls, total of the first roll, and result of the current roll. When the "Roll the dice!" button is pressed and the play method is called, the method should generate two random values between and which represent the current roll of the dice. The entries for the two dice should be cleared and then the rolls inserted into the appropriate entries. In the case that this is the first roll as pictured above then the total of the dice should be inserted into the entry for the first roll and the self.firstroll variable should be updated. If the first roll is a or an the user wins and this should be reported. Below is an example demonstrating that situation:If the first roll is a or the user loses, and this should be reported. Below is an example demonstrating that situation:If the user rolls anything other than a or during the first round, heshe needs to roll again to determine the results. This situation is show below:During rounds beyond the first which can be determined by checking that self.firstroll is nonzero when the play method starts the sum of the two dice should be compared against the first roll. If the total equals the player immediately loses. That situation is shown below:If the total of the dice is equal to the first roll, then the user wins. That situation is shown below:In the case that the sum of the dice don't equal the first roll, then the user needs to roll again. That situation is shown below:Whenever the player either wins or loses, the newgame method should be called so that if the player presses the "Roll the dice!" button again the play method will be prepared for a new game. Again, please don't modify the existing methods. You should only implement the play method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started