Create a dice game that awards the user points for pair, three-of-a-kind, or a series. Use...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Create a dice game that awards the user points for pair, three-of-a-kind, or a series. Use the following class diagram for your program. Die sides: int value: int _init_ (self, sides-6) roll(self): int _str_(self): str (self, other): bool eq_(self, other): bool _sub_(self, other): int Player dice: Die list points: int _init_ (self) get points(self): int roll dice(self) has_pair(self): bool has three of a kind (self): bool has_series(self): bool _str_(self): str Die class (die py) - has two attributes: the number of sides of the die and the value of the rolled die. 1. __init__(self, side 6-assigns the number of sides from the value passed in. Set value to 0 or to the returned value of roll(). 2. roll (self)-generate a random number between 1 and the number of sides and assign it to the Die's value. Return the value. 3. ____ (self) return the Die's value as a string. 4. __1_(self, other) -return true if the value of self is less than the value of other. 5.(self, other) -return true if both the values of self and other are equal. 6.__sub (self, other) - return the difference between the value of self and the value of other. Player class (player.py) - has two attributes: a list of 3 Die objects and the player's points. 1. ___inis (self-constructs and sorts the list of three Die objects and initializes the player's points to 0. 2. get points (seif) -returns the player's points. 3. roll dice (self) - calls roll on each of the Die objects in the dice list and sorts the list. 4. has paiz (self) -returns true if two dice in the list have the same value (uses ==). Increments points by 1. 5. has three of a kind (self) - returns true if all three dice in the list have the same value (uses ==). Increments points by 3. 6. has series(self)-returns true if the values of each of the dice in the list are in a sequence (ex. 1.2.3 or 2,34 or 3.4.5 or 45.6) (uses -). Increments points by 2. 7. __str_(self)-returns a string in the format: "D1=2, D2=4, D3=6", Main file (main.py) - has one function named take_turn that passes in a Player object. The take_turn function should: roll the player's dice, display the dice, check for and display any win types (pair, series, three-of-a-kind), and display the updated score. The main function should construct a player object, and then repeatedly call take_turn until the user chooses to end the game. Display the final points at the end of the game. Use the check_input module's get_yes no function to prompt the user to continue or end the game. Use docstrings to document each class, method, and function. Example Output (user input in italics): -Yahtzee- D1-1 D2-4 D3-5 Aww. Too Bad. Score 0 Play again? (Y/N): g Invalid input - should be a 'Yes' or 'No'. Play again? (Y/N): y D1-3 D2=3 D3=5 You got a pair! Score = 1 Play again? (Y/N): y Notes: D1-3 D2-4 D3=5 You got a series of 3! Score = 3 Play again? (Y/N): y D1-1 D2-1 D3=1 You got 3 of a kind! Score = 6 Play again? (Y/N): n Game Over. Final Score 6 1. You should have 4 different files: die.py, player.py, check_input.py, and main.py. 2. Check all user input using the get_yes_no function in the check input module. 3. Do not create any extra methods or add any extra parameters. 4. Please do not create any global variables or use the attributes globally. Only access the attributes using the class's methods. 5. Do not call any of the methods using the double underscores (ex. use == not__eg__). 6. Use docstrings to document the class, each of its methods, and the functions in the main file. See the lecture notes and the Coding Standards reference document for examples. 7. Place your names, date, and a brief description of the program in a comment block at the top of your main file. Place brief comments throughout your code. 8. Thoroughly test your program before submitting: a. Make sure that the user input is validated. b. Make sure that the dice values are sorted. c. Make sure that each of the win types are detected correctly. d. Make sure that the user is not awarded for both a pair and a three-of-a-kind simultaneously. e. Make sure that each of the win types awards the correct number of points. f. Make sure that the game continues and ends correctly. g. Make sure that the final score is displayed at the end. Create a dice game that awards the user points for pair, three-of-a-kind, or a series. Use the following class diagram for your program. Die sides: int value: int _init_ (self, sides-6) roll(self): int _str_(self): str (self, other): bool eq_(self, other): bool _sub_(self, other): int Player dice: Die list points: int _init_ (self) get points(self): int roll dice(self) has_pair(self): bool has three of a kind (self): bool has_series(self): bool _str_(self): str Die class (die py) - has two attributes: the number of sides of the die and the value of the rolled die. 1. __init__(self, side 6-assigns the number of sides from the value passed in. Set value to 0 or to the returned value of roll(). 2. roll (self)-generate a random number between 1 and the number of sides and assign it to the Die's value. Return the value. 3. ____ (self) return the Die's value as a string. 4. __1_(self, other) -return true if the value of self is less than the value of other. 5.(self, other) -return true if both the values of self and other are equal. 6.__sub (self, other) - return the difference between the value of self and the value of other. Player class (player.py) - has two attributes: a list of 3 Die objects and the player's points. 1. ___inis (self-constructs and sorts the list of three Die objects and initializes the player's points to 0. 2. get points (seif) -returns the player's points. 3. roll dice (self) - calls roll on each of the Die objects in the dice list and sorts the list. 4. has paiz (self) -returns true if two dice in the list have the same value (uses ==). Increments points by 1. 5. has three of a kind (self) - returns true if all three dice in the list have the same value (uses ==). Increments points by 3. 6. has series(self)-returns true if the values of each of the dice in the list are in a sequence (ex. 1.2.3 or 2,34 or 3.4.5 or 45.6) (uses -). Increments points by 2. 7. __str_(self)-returns a string in the format: "D1=2, D2=4, D3=6", Main file (main.py) - has one function named take_turn that passes in a Player object. The take_turn function should: roll the player's dice, display the dice, check for and display any win types (pair, series, three-of-a-kind), and display the updated score. The main function should construct a player object, and then repeatedly call take_turn until the user chooses to end the game. Display the final points at the end of the game. Use the check_input module's get_yes no function to prompt the user to continue or end the game. Use docstrings to document each class, method, and function. Example Output (user input in italics): -Yahtzee- D1-1 D2-4 D3-5 Aww. Too Bad. Score 0 Play again? (Y/N): g Invalid input - should be a 'Yes' or 'No'. Play again? (Y/N): y D1-3 D2=3 D3=5 You got a pair! Score = 1 Play again? (Y/N): y Notes: D1-3 D2-4 D3=5 You got a series of 3! Score = 3 Play again? (Y/N): y D1-1 D2-1 D3=1 You got 3 of a kind! Score = 6 Play again? (Y/N): n Game Over. Final Score 6 1. You should have 4 different files: die.py, player.py, check_input.py, and main.py. 2. Check all user input using the get_yes_no function in the check input module. 3. Do not create any extra methods or add any extra parameters. 4. Please do not create any global variables or use the attributes globally. Only access the attributes using the class's methods. 5. Do not call any of the methods using the double underscores (ex. use == not__eg__). 6. Use docstrings to document the class, each of its methods, and the functions in the main file. See the lecture notes and the Coding Standards reference document for examples. 7. Place your names, date, and a brief description of the program in a comment block at the top of your main file. Place brief comments throughout your code. 8. Thoroughly test your program before submitting: a. Make sure that the user input is validated. b. Make sure that the dice values are sorted. c. Make sure that each of the win types are detected correctly. d. Make sure that the user is not awarded for both a pair and a three-of-a-kind simultaneously. e. Make sure that each of the win types awards the correct number of points. f. Make sure that the game continues and ends correctly. g. Make sure that the final score is displayed at the end.
Expert Answer:
Answer rating: 100% (QA)
diepy This file defines a Die class that represents a single die It has methods to roll the die compare two dice and subtract one die from another It also has a str method that returns the current val... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Frowren Domestic manufactures and sells a single product. In preparing its master budget for the current quarter, the company's controller has assembled the following information: Frowren Domestic...
-
Sage's Ice Cream Shop incurs the following costs associated with selling its specialty waffle cones in one month: Direct materials cost for ice cream and cones $1,996 Wages for the staff to scoop and...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
On December 31, Alvare Company estimates its bad debts to be .5% of its annual credit sales of $875,000. They use the allowance method. Prepare the Journal entries for December 31 recording the Bad...
-
Calculate the mean lifetime of excited atoms if it is known that the intensity of the spectral line appearing due to transition to the ground state diminishes by a factor = 25 over a distance l = 2.5...
-
The year - end balance sheet of Social Systems, Inc. includes the following stockholders equity section ( with certain details omitted ) : Stockholders equity: 9 % cumulative preferred stock, Rs . 1...
-
Consider the flow in cylindrical coordinates with no dependence on \(\theta\). How is the streamfunction defined? What is the non-vanishing component of vorticity. Show that the \(E^{2}\) operator...
-
Assume the following financial data for Rembrandt Paint Co. and Picasso Art Supplies: a. If all the shares of Rembrandt Paint Co. are exchanged for those of Picasso Art Supplies on a share-for-share...
-
Adger Corporation is a service company that measures its output based on the number of customers served. The company provided the following fixed and variable cost estimates that it uses for...
-
Of all the price analysis methodologies that exist, which are the foundational methods. Longing & Shorting. Trading & Investing. Volume & sentiment. On-chain & Macroeconomic. Mean reversion &...
-
Use computational and algebraic tools to quantify the total costs for each plan using last year's medical expenses as an estimate. Option 1: The Deluxe Plan (You pay . . .) Option 2: The Basic Plan...
-
Indicate whether the following statements are syntactically correct or incorrect. If incorrect, indicate what is wrong with the statement: A. Scanner inputFile=new Scanner (new file (Sample.dat));...
-
Write a recursive method to reverse a given string. The method accepts a string as a parameter and returns the reverse of the string. For example, if the argument is Java, then the method returns...
-
Given the following variables, give the result of each of the following operations (show all 8 bits): int num1 = 0b00110101, num2 = 0b11001010, ans; *A. B. *C. D. ans = num1 & num2; ans = num1 |...
-
Indicate whether the following statements are syntactically correct or incorrect. If incorrect, indicate what is wrong with the statement: A. int [] array[]; *B. double data [] = new data []; *C. int...
-
The Triangle class is derived from the RegPolygon class. Using the UML diagrams shown below, complete the following: A. List any overloaded methods in the RegPolygon and Triangle classes. B. List any...
-
1) Which of the following numbers represents the correlation forthe above scatter plot? Select one: -0.49 -0.95 -0.98 0.57 0.34 0.89 2) Which of the following numbers represents the correlation...
-
Read the Forecasting Supply Chain Demand Starbucks Corporation case in your text Operations and Supply Chain Management on pages 484-485, then address the four questions associated with the...
-
a. Write a program that allows you to create a file of customers for a company. The first part of the program should create an empty file suitable for writing a three-digit ID number, six-character...
-
The method public static boolean testValue(int response) returns _____________. a. No value b. An int value c. A boolean value d. You cannot determine what is returned.
-
Which of the following is a requirement when you use a binary search method with an array? a. The array must be numeric. b. The array must have been sorted in ascending order. c. The array must have...
-
Catherine Rampell is an economics writer for the Washington Post. In an article in 2023, she observes that the average U.S. tariff rate on mens underwear is 11.5 percent. The average rate on womens...
-
An opinion column in the Wall Street Journal argued that Americans enjoy comparative advantages in [service] sectors such as construction and engineering, but global trade in services is weighed down...
-
An article in the Wall Street Journal explained that despite rising national security tensions between the United States and China in 2023, trade between the two nations was rising. China is a...
Study smarter with the SolutionInn App