Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi. I am doing my python 3 homework about making pro games. The first and 2nd picture are the questions and instructions given to code

Hi. I am doing my python 3 homework about making pro games. The first and 2nd picture are the questions and instructions given to code and I have to code them by the order given and get the output just like the red texts written in the 2nd image. The 3rd image is the homework file which I have done so far that might need more advise. The 4th and 5th image are images of a different rpg_py.file given earlier for coding help. My homework file should open the operate rpg_py.file. I need help with the main function part also. I really need help with this help me!

from HW8 import * import random

#create a set of inventory items items = {"loaf of bread", "gold coin", "roll of twine", "candle", "amethyst crystal", "dagger"}

''' Checks for finding a health elixir. Health can be restored by a value between 0-5. ''' def check_for_health_elixir(hero): random_chance = random.randint(0,5) if random_chance == 5: health_amt = random.randint(2,5) print("You have found a health elixir.") print("Drinking it restores your health by " + str(health_amt) + ".") hero.restore_health(health_amt) print("Your current health is " + str(hero.health) + ". ")

''' Checks for finding inventory. ''' def check_for_inventory(hero): random_chance = random.randint(0,4) if random_chance == 4: item = random.sample(items, 1)[0] print("You have found a " + item + ".") hero.add_inventory(item) print("Your current inventory is " + str(hero.get_inventory()) + ". ")

''' Determines how much damage is inflicted by running from an enemy (a value from 0 to half the enemy's damage power). ''' def run(hero, enemy): damage = random.randint(0, enemy.damage//2) print("The " + enemy.name + " inflicted a damage of " + str(damage) + " as you ran away.") health = hero.take_damage(damage) print("Your current health is " + str(health) + ". ")

''' Determines how much damage is incurred by fighting an enemy. If hero wins, 0 damage is taken. If enemy wins, then the enemy's full damage power is taken. ''' def fight(hero, enemy): winner = random.randint(0,1) if winner == 0: print("You have defeated the " + enemy.name + ".") else: print("You have lost the fight. The " + enemy.name + " has inflicted a damage of " + str(enemy.damage) + ".") health = hero.take_damage(enemy.damage) print("Your current health is " + str(hero.health) + ". ")

def main():

#create 1 hero and 4 enemies hero = Hero('Elsa', 40) goblin = Enemy('Goblin', 10, 5) dragon = Enemy('Dragon', 30, 10) ogre = Enemy('Ogre', 20, 8) wizard = Enemy('Wizard', 20, 10)

#put the enemies in a set enemies = {goblin, dragon, ogre, wizard}

print("You are the hero " + hero.name + ". Your current health is " + str(hero.health) + ". ") game_over = False while not game_over:

#check for health elixir check_for_health_elixir(hero)

#check for inventory check_for_inventory(hero)

#encounter an enemy - randomly select one from the set of enemies enemy = random.sample(enemies, 1)[0] print("You have encountered a " + enemy.name + ".") action = input("Do you want to run or fight?").strip()

while action != "run" and action != "fight": action = input("Do you want to run or fight?").strip()

#respond to the user's action (run or fight) if action == "run": run(hero, enemy)

elif action == "fight": fight(hero, enemy)

#check hero's health if hero.health

if __name__ == '__main__': main()

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Your program must contain a main function, which in turn calls other functions. Turn in one program file that does all of the following things: 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 character's 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 character's health by that amount, then returns the Character's resulting health value Also implement the strO 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) 1. 2. 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 health0 that takes in a restore amount and increases the character's 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 hero's inventory list. Create method get inventory that returns the inventory list 3. 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. 4. Once your classes are created, create a main0 that tests your classes by simulating some encounters between Characters In main0 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 a. Print "Start:" and then print the three characters. Start: 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 l: b. 2 Han (health-30) Werewolf (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. c. 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. d Print "Restore Health" and then print the hero. Restore Health: Han (health-20) The hero finds a gold coin. Add "gold coin" to the hero's inventory. The hero finds a candle. Add "candle" to the hero's inventory. e. Print "Inventory:" and then print the hero's inventory by using the get inventory method. Inventory: I'gold coin, 'candle'1 All together, your printouts should look exactly like this: Start: 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) Inventory: I'gold coin', 'candle' 1 5. Use the provided play xpS.py file to test your code and play the role player game (RPG). a. In your homework file, wrap your call to main0 in an if-statement, as we discussed in class: if name main main() b. At the top of the play xRgy file, change "HW8" in the import statement to your homework file name def fight(hero, enemy): winmer - random.rondint(0,1) if winner0: print("You have defeated the " enemy.name"." else: print("You have lost the fight. The " + enemy.name +" has inflicted a damage of" + str(enemy. damage) +"." health hero.take_damageCenemy.damage) printC"Your current health is " str(hero.health)".In") def mainO #create 1 hero and 4 enemies hero Hero('Elsa, 40) goblin EnemyC' Goblin', 10, 5) dragon = Enemy("Dragon", 30, 10) ogre Enemy('Ogre', 20, 8) wizard EnemyC'Wizard', 20, 10) #put the enemies in a set enemies goblin, dragon, ogre, wizard) print("You are the hero "+hero.name+. Your current health is " + str(hero.health).n") game_over False while not game_over: #check for health elixir check for_health_elixirChero) #check for inventory check for_inventory(hero) #encounter an enemy- randomly select one from the set of enemies enemy random. sampleCenemies, 1)00] printC"You have encountered a enemy.name "." action input("Do you want to run or fight?").strip) while action!"run" and action-"fight": action input("Do you want to run or fight?").strip) #respond to the user's action (run or fight) if action"run": runChero, enemy) elif action"fight": fight(hero, enemy) #check hero's health if hero.health0: print( You are dead! Game over.") ame-over = True if -.-namemain mainO Your program must contain a main function, which in turn calls other functions. Turn in one program file that does all of the following things: 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 character's 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 character's health by that amount, then returns the Character's resulting health value Also implement the strO 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) 1. 2. 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 health0 that takes in a restore amount and increases the character's 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 hero's inventory list. Create method get inventory that returns the inventory list 3. 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. 4. Once your classes are created, create a main0 that tests your classes by simulating some encounters between Characters In main0 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 a. Print "Start:" and then print the three characters. Start: 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 l: b. 2 Han (health-30) Werewolf (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. c. 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. d Print "Restore Health" and then print the hero. Restore Health: Han (health-20) The hero finds a gold coin. Add "gold coin" to the hero's inventory. The hero finds a candle. Add "candle" to the hero's inventory. e. Print "Inventory:" and then print the hero's inventory by using the get inventory method. Inventory: I'gold coin, 'candle'1 All together, your printouts should look exactly like this: Start: 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) Inventory: I'gold coin', 'candle' 1 5. Use the provided play xpS.py file to test your code and play the role player game (RPG). a. In your homework file, wrap your call to main0 in an if-statement, as we discussed in class: if name main main() b. At the top of the play xRgy file, change "HW8" in the import statement to your homework file name def fight(hero, enemy): winmer - random.rondint(0,1) if winner0: print("You have defeated the " enemy.name"." else: print("You have lost the fight. The " + enemy.name +" has inflicted a damage of" + str(enemy. damage) +"." health hero.take_damageCenemy.damage) printC"Your current health is " str(hero.health)".In") def mainO #create 1 hero and 4 enemies hero Hero('Elsa, 40) goblin EnemyC' Goblin', 10, 5) dragon = Enemy("Dragon", 30, 10) ogre Enemy('Ogre', 20, 8) wizard EnemyC'Wizard', 20, 10) #put the enemies in a set enemies goblin, dragon, ogre, wizard) print("You are the hero "+hero.name+. Your current health is " + str(hero.health).n") game_over False while not game_over: #check for health elixir check for_health_elixirChero) #check for inventory check for_inventory(hero) #encounter an enemy- randomly select one from the set of enemies enemy random. sampleCenemies, 1)00] printC"You have encountered a enemy.name "." action input("Do you want to run or fight?").strip) while action!"run" and action-"fight": action input("Do you want to run or fight?").strip) #respond to the user's action (run or fight) if action"run": runChero, enemy) elif action"fight": fight(hero, enemy) #check hero's health if hero.health0: print( You are dead! Game over.") ame-over = True if -.-namemain mainO

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago