Define the playround method with only the self parameter


Assignment: Dice Poker

Our goal is to write a game program that allows a user to play video poker using dice. The program will display a hand consisting of five dice. The basic set of rules is as follows:

? The player starts with $100.
? Each round costs $10 to play. This amount is subtracted from the user's money at the start of the round.
? The player initially rolls a completely random hand.
? The player gets two chances to enhance the hand by rerolling some or all of the dice.
? At the end of the hand, the player's money is updated according to the following payout schedule:

? Two Pairs = $5
? Three of a Kind = $8
? Full House (A Pair and a Three of a Kind) = $12
? Four of a Kind = $15
? Straight (1-5 or 2-6) $20
? Five of a Kind = $30

1. Now we are ready to turn our attention to the task of actually implementing the poker game. We know that the PokerApp will need to keep track of the dice and the amount of money. Let's initialize these values in the constructor.

1. Define a new class named PokerApp in the same file as the Dice class.

2. Inside the PokerApp define an init method that only has one parameter, self.

3. Inside the init method, create an instance of the Dice class, Dice(), and store the instance in an instance variable called dice. Remember to precede the instance variable with self and a dot.

4. Inside the init method, create an instance variable named money and initialize it to 100. Remember self-dot.

5. To test the PokerApp class and its contructor use the following driver code:

1. game = PokerApp()

2. print game.money

3. Printing the dice instance variable is a little more tricky. Try it by adding the following code to the driver code above:

1. print game.dice

2. This doesn't work because the dice instance variable is an object. To print the value inside the object you must use dot notation and call the instance variable on that object. Change the last line of code to:

1. print game.dice.dice

2. Now we want to loop the program allowing the user to continue playing hands until he or she is either out of money or chooses to quit. Sincee it costs $10 to play a hand, we can continue as long as the amount of money is at least $10.

1. Define a method called wantToPlay that has a parameter self.

1. Inside the method, use raw_input to ask the user "Do you wish to try your luck?" and store the result in a local variable named ans.

2. Now we need to see if the user responded with "yes" or "y". If the first letter of ans is uppercase or lowercase "y" then return True, otherwise return "False." Hint: The first letter of a string is index zero.

2. Define another method called run with a parameter, self.

1. Inside the method, ouput the following: You currently have $100.

2. Inside the method, create a loop that executes as long as the money balance is at least $10 and a call to the wantToPlay method is true. Don't forget the self-dot.

3. Inside the loop make a call to a method named playRound and send no arguments.

3. Most of the work of the program has now been pushed into the playRound method. Each round will consist of a series of rolls. Based on these rolls, the program will have to adjust the player's score.

1. Define the playRound method with only the self parameter.

2. Inside the playRound method, subtract 10 from the money.

3. Make a call to another instance method called doRolls that takes no arguements. This method will be in charge rolling the dice and rerolling if the user chooses. We will write this method in the next section.

4. When control returns from the doRolls method we will have the final hand to be played so we need to score the hand by calling the score method in the dice class. To do this we must use call the method using the dice instance variable (don't forget the self-dot). The score method will return two values: the type of hand and the payout. So here's how it will look:

1. result, score = self.dice.score()

5. Print the values returned by the score method according to this sample output: Full House. You win $12.

6. Add the payout to the player's money.

7. Print the new amount player money according the following sample output: You currently have $102.

4. Finally, we are down to the nitty-gritty details of implementing the dice rolling process.

Initially, all of the dice will be rolled. Then we need a loop that continues rolling user-selected dice until either athe user chooses to quit rolling or the limit of three rolls is reached.

1. Roll all the dice using the roll method in the Dice class.

2. Create a local variable to keep track of the roll number. Initialize this variable to 1 since we are on the first roll.

3. Print the roll of the dice using the following sample: Dice: [2, 3, 2, 1, 5, 5]

4. Get input from the user asking for which dice to reroll and store in a local variable named toRoll: toRoll = input("Enter list of which to change ([] to stop) ")

5. Create a loop that will execute as long as the roll count is less than three and the user didn't type in an empty list to stop.

1. Inside the body of the loop, call the roll method of the dice class rolling the dice the user selected.

2. Increment the roll count by 1.

3. Output the new hand of rolled dice. Use the same code as earlier.

4. Create a conditional statement that asks the user if they want to roll again but only if the roll count is still less than three.

5. Your PokerApp class should now be complete. To run the game you should only need to create a PokerApp object and then call its run method. These commands should not be part of the class and therefore should not be indented.

1. game = PokerApp()
2. game.run().

Request for Solution File

Ask an Expert for Answer!!
Python Programming: Define the playround method with only the self parameter
Reference No:- TGS02300464

Expected delivery within 24 Hours