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!

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education