Answered step by step
Verified Expert Solution
Link Copied!

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, six-sided dice. If the player rolls a 7 or 11 in the first round, the player wins. If the player rolls a 2,3, or 12 in the first round, the player loses. For any other roll the player must roll again to determine whether he/she won. During subsequent rounds, the player wins if he/she rolls point, that is, rolls the same total as he/she did during the first round. During subsequent rounds, the player loses if he/she rolls a 7. 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:
1.__init__: The constructor creates the main window, sets the title, calls the new_game() method, and calls the make_widgets() method.
2. new_game: This method resets the first roll variable in the object. When the first roll is set to 0 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.
3. make_widgets: 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 Craps().mainloop() 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 1 and 6 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 7 or an 11, the user wins and this should be reported. Below is an example demonstrating that situation:If the first roll is a 2,3, or 12, the user loses, and this should be reported. Below is an example demonstrating that situation:If the user rolls anything other than a 2,3,7,11, or 12 during the first round, he/she 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 non-zero when the play() method starts), the sum of the two dice should be compared against the first roll. If the total equals 7, 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 new_game() 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions