from character import Character from monster import Monster from weapon import Weapon from armor import Armor import random def attack_someone(attacker, defender): throw_result = random.randint(1, 6) attack = attacker.attack + attacker.weapon.bonus defense = defender.defense + defender.armor.bonus damage = attack + throw_result - defense if damage > 0: defender.hp = defender.hp - damage character = Character("You", 3, 10, 2, Weapon("Sword"), Armor("Helmet", 2)) monster = Monster("Goblin", 6, 1, 1, Weapon("Axe"), Armor("Shield", 1)) monster2 = Monster("Troll", 20, 3, 2, Weapon("Axe"), Armor("Shield", 1)) monsters = [monster, monster2] for current_monster in monsters: print("You are fighting against", current_monster.name) attack_someone(current_monster, character) while character.is_alive() and monster.is_alive(): attack_someone(character, monster) if monster.is_alive(): attack_someone(monster, character) if character.hp <= 0: print("You won!") else: print("You lost!")