The class will be named Player and will represent all the information about the player playing the game. In the constructor, the client passes a name, health, and strength for the player. Both the health and the strength should be between 1 and 100 (raise a ValueError if they are not). Include the following methods: attack: Generates a random number between 1 and the player's strength and returns that number. take_damage: has a parameter named damage_amount. This is how much the enemy is attacking the player for (this number should be between 1 and 100). Generate a random number between 1 and the damage amount, and that is how much the player blocks the attack for. Subtract the remaining attack from the player's health. This function should return True if the player has died from the attack (health gone below 0) and False otherwise. heal: Adds 10 to the player's health. If the players health goes above their start health, reset the player's health to their starting health. Hint: To do this, you want two attributes. One named _current_health and one named _starting_health. _current_health will change as the game is played (and possibly go to 0) and _starting_health should never change. __str__: Print out all relevant information about the Player (name and current health in particular). Add properties and setters for the current_health and strength attributes. Make sure the client does not violate the invariant with either of these! In your program's main file, create a Player object and test it out a little. Feel free to make any changes that seem interesting to you in the Player class!

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter6: Looping
Section: Chapter Questions
Problem 4GZ
icon
Related questions
Question

You will create a class for use in a video game in Python. The class will be named Player and will represent all the information about the player playing the game. In the constructor, the client passes a name, health, and strength for the player. Both the health and the strength should be between 1 and 100 (raise a ValueError if they are not). Include the following methods: attack: Generates a random number between 1 and the player's strength and returns that number. take_damage: has a parameter named damage_amount. This is how much the enemy is attacking the player for (this number should be between 1 and 100). Generate a random number between 1 and the damage amount, and that is how much the player blocks the attack for. Subtract the remaining attack from the player's health. This function should return True if the player has died from the attack (health gone below 0) and False otherwise. heal: Adds 10 to the player's health. If the players health goes above their start health, reset the player's health to their starting health. Hint: To do this, you want two attributes. One named _current_health and one named _starting_health. _current_health will change as the game is played (and possibly go to 0) and _starting_health should never change. __str__: Print out all relevant information about the Player (name and current health in particular). Add properties and setters for the current_health and strength attributes. Make sure the client does not violate the invariant with either of these! In your program's main file, create a Player object and test it out a little. Feel free to make any changes that seem interesting to you in the Player class!

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage