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!
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!

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









