Question: This is for Python You are going to create the classes for a simple, text-based role player game (RPG). In this game, there are good

This is for Python

You are going to create the classes for a simple, text-based role player game (RPG). In this game, there are good characters (heroes) and bad characters (enemies).

All characters, whether good or bad, have a health value. Once a characters health value drops to (or below) zero, the character dies.

Characters will encounter each other in the game and can inflict damage upon each other, reducing the health value of characters that get attacked.

Create a Character class. A character should be initialized with a name and an initial health value.

Characters should have a method called take_damage() that takes in a damage amount and reduces the characters health by that amount, then returns the Characters resulting health value.

Also implement the str() method for Character so that printing a Character prints their name and their current health value in exactly this format for an example Character with the name Trinity and a health value of 75:

Trinity (health=75)

Create a subclass of Character called Hero. A Hero should be initialized with a name and an initial health value.

Heroes are able to regain health points by finding healing elixirs. Heroes should have a method called restore_health() that takes in a restore amount and increases the characters health by that amount.

Heroes can also have an inventory of items. Create a private variable for inventory and initialize it to an empty list in the initializer.

Create methods add_inventory and remove_inventory which take in a single item as an argument and add or remove that item from the heros inventory list.

Create method get_inventory that returns the inventory list.

Create a subclass of Character called Enemy. An enemy should be initialized with a name, an initial health value, and a damage amount. The damage amount is how much damage this enemy will take from the hero if this enemy wins a battle with the hero.

Enemies do not have any additional methods.

Once your classes are created, create a main() that tests your classes by simulating some encounters between Characters.

In main():

Create a Hero named Han with health of 40.

Create an Enemy named Zombie with health of 20 and damage of 15.

Create an Enemy named Warewolf with health of 15 and damage of 10.

Print Start: and then print the three characters.

Han (health=40)

Zombie (health=20)

Warewolf (health=15)

An encounter occurs between the hero and the warewolf. The hero damages the warewolf by 10. The warewolf damages the hero by its full damage strength. Write the lines of code to reflect this (hint: 2 lines of code).

Print Battle 1: and then print the hero and the warewolf.

Battle 1:

Han (health=30)

Warewolf (health=5)

An encounter occurs between the hero and the zombie. The hero damages the zombie by 20. The zombie damages the hero by its full damage strength.

Write the lines of code to reflect this.

Print Battle 2: and then print the hero and the zombie.

Battle 2:

Han (health=15)

Zombie (health=0)

The hero finds a health elixir to restore his health by 5 points. Write the code to reflect this.

Print Restore Health and then print the hero.

Restore Health:

Han (health=20)

The hero finds a gold coin. Add gold coin to the heros inventory. The hero finds a candle. Add candle to the heros inventory.

Print Inventory: and then print the heros inventory by using the get_inventory method.

['gold coin', candle']

All together, your printouts should look exactly like this:

Han (health=40)

Zombie (health=20)

Warewolf (health=15)

Battle 1:

Han (health=30)

Warewolf (health=5)

Battle 2:

Han (health=15)

Zombie (health=0)

Restore Health:

Han (health=20)

['gold coin', candle']

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!