def main(): enemy = Goblin() hero = Hero() while enemy.alive() and hero.alive(): hero.print_status() enemy.print_status() print() print("What do you want to do?") print("1. fight enemy") print("2. do nothing") print("3. flee") print("> ", ) response = input() if response == "1": # Hero attacks enemy hero.attack(enemy) elif response == "2": pass elif response == "3": print("Goodbye.") break else: print("Invalid input %r" % input) if enemy.alive(): # enemy attacks hero enemy.attack(hero)
def main(): hero = Hero('Matt', 10, 5) goblin = Goblin('Goblin', 6, 2) while goblin.alive() and hero.alive(): print() print("What do you want to do?") print("1. fight %s" % (goblin.name)) print("2. do nothing") print("3. flee") print("> ", ) user_input = input() if user_input == "1": # Hero attacks enemy hero.attack(goblin) print("You do %d damage to the %s." % (hero.power, goblin.name)) if goblin.health <= 0: print("The %s is dead." % (goblin.name)) elif user_input == "2": goblin.attack(hero) hero.print_status() elif user_input == "3": print("Goodbye.") else: print("Invalid input %r" % user_input) if hero.health <= 0: print("You are dead.")
def main(): hero = Hero() goblin = Goblin() while hero.alive() and goblin.alive(): hero.print_status() goblin.print_status() print() print("What do you want to do?") print("1. fight goblin") print("2. do nothing") print("3. flee") print("> ", ) user_input = input() if user_input == "1": # Hero attacks goblin hero.attack(goblin) elif user_input == "2": pass elif user_input == "3": print("Goodbye.") break else: print("Invalid input %r. Enter 1, 2 or 3." % user_input) if goblin.health > 0: # Goblin attacks hero goblin.attack(hero)
def main(): hero = Hero(10, 5) goblin = Goblin(6, 2) # hero_health = 10 # hero_power = 5 # goblin_health = 6 # goblin_power = 2 while goblin.alive() and hero.alive(): #print("You have %d health and %d power." % (hero.health, hero.power)) hero.print_status() #print("The goblin has %d health and %d power." % (goblin.health, goblin.power)) goblin.print_status() print() print("What do you want to do?") print("1. fight goblin") print("2. do nothing") print("3. flee") print("> ", ) user_input = input() if user_input == "1": # Hero attacks goblin # goblin_health -= hero_power # print("You do %d damage to the goblin." % hero_power) hero.attack(goblin) if not goblin.alive(): print("The goblin is dead.") elif user_input == "2": pass elif user_input == "3": print("Goodbye.") break else: print("Invalid input %r" % user_input) if goblin.alive(): # Goblin attacks hero # hero_health -= goblin_power # print("The goblin does %d damage to you." % goblin_power) goblin.attack(hero) if not hero.alive(): print("You are dead.")
def main(): my_hero = Hero() goblin = Goblin() zombie = Zombie() medic = Medic() shadow = Shadow() while (goblin.alive() or zombie.alive()) and my_hero.alive(): my_hero.print_status() print() print("What do you want to do?") print("1. fight goblin") print("2. fight zombie") print("3. fight medic") print("4. fight shadow") print("5. do nothing") print("6. flee") print("> ",) user_input = input() if user_input == "1": goblin.print_status() # my_hero attacks goblin my_hero.attack(goblin) if goblin.health > 0: # Goblin attacks my_hero goblin.attack(my_hero) elif user_input == "2": zombie.print_status() my_hero.attack(zombie) zombie.attack(my_hero) zombie.alive() elif user_input == "3": medic.print_status() my_hero.attack(medic) medic.attack(my_hero) medic.alive() elif user_input == "4": shadow.print_status() shadow.attack(my_hero) my_hero.attack(shadow) shadow.alive() elif user_input == "5": pass elif user_input == "6": print("Goodbye.") break else: print("Invalid input %r" % user_input)