def setUp(self): self.damage = 0 self.buff = 0 self.stat = pyzork.StatEnum.attack self.p = pyzork.Player(max_health=10) pyzork.utils.update_output(lambda text: None)
def test(self): class InsultSpell(pyzork.Ability): """Insult""" pass class Fireball(pyzork.Ability): pass class LightningNova(pyzork.Ability): """Lightning Nova""" pass class WarRoar(pyzork.Ability): """War Roar""" pass player = pyzork.Player( abilities=[InsultSpell(), Fireball(), LightningNova(), WarRoar()]) battle = pyzork.Battle(player=player, enemies=[goblin, wizard, goblin2]) strings = [("cast insult on the wizard", (wizard, InsultSpell)), ("use fireball on the goblin", (goblin2, Fireball)), ("cast War Roar on the myself", (player, WarRoar))] for string, enemy in strings: reply = pyzork.actions.use_ability_parser(string, battle) self.assertIsNot(reply, None, msg=string) self.assertIs(reply[0], enemy[0], msg=string) self.assertIsInstance(reply[1], enemy[1], msg=string)
def test_full(self): player = pyzork.Player(max_health=50, attack=5, defense=1) BattleField = pyzork.Location.from_dict(name="BattleField", enemies=[Goblin, BigGoblin]) bf = BattleField() battle = pyzork.Battle(player=player, enemies=bf.enemies, location=bf) strings = [ "attack the goblin", "attack the big goblin", "attack the goblin", "attack the big goblin", "attack the big goblin", ] self.index = 0 def new_input(): i = strings[self.index] self.index += 1 return i pyzork.utils.update_input(new_input) pyzork.utils.update_output(lambda x: None) battle.battle_loop() self.assertFalse(bf.enemies) self.assertFalse(battle.alive) self.assertEqual(len(battle.dead), 2)
def setUp(self): self.player = pyzork.Player(max_energy=6, max_health=10, damage=6, defense=6) self.stat = pyzork.StatEnum.null self.duration = 0 self.buff = 0 self.damage = 0 pyzork.utils.update_output(lambda text: None)
def test(self): inv = pyzork.Inventory(items=[Sword(), Cuirass(), SwordAndShield()]) p = pyzork.Player(inventory=inv) strings = [ ("equip my sword and shield", SwordAndShield), ("take the sword", Sword), ("put on the cuirass", Cuirass), ] for string, item in strings: reply = pyzork.actions.equip_item_parser(string, p) self.assertIsInstance(reply, item, msg=string)
def test(self): player = pyzork.Player() battle = pyzork.Battle(player=player, enemies=[goblin, wizard, goblin2]) strings = [("attack the goblin", goblin2), ("punch the wizard with my hands", wizard), ("strike the fat goblin", goblin), ("target the enemy wizard", wizard), ("hit myself", player), ("strike me", player)] for string, target in strings: reply = pyzork.actions.attack_parser(string, battle) self.assertIs(reply, target, msg=string)
def test_flexible_reward(self): def basic_reward(levels): levels.entity.base_attack *= 1.2 basic = pyzork.ExperienceLevels(requirement=100, modifier=1.2, max_level=10, reward=basic_reward) p = pyzork.Player(experience=basic, attack=4) for _ in range(basic.max_level): attack = p.attack * 1.2 basic += basic.remaining # self.assertEqual(p.health, health) self.assertEqual(p.attack, attack)
def test_priorities(self): def custom_priorities(battle): turns = [] for enemy in battle.alive: turns.append(battle.player) turns.append(enemy) return turns player = pyzork.Player(max_health=50, attack=5, defense=1) BattleField = pyzork.Location.from_dict(name="BattleField", enemies=[Goblin, BigGoblin]) bf = BattleField() battle = pyzork.Battle(player=player, enemies=bf.enemies, location=bf, priorities=custom_priorities) self.assertEqual(len(battle.priorities(battle)), 4)
def test(self): class Sword(pyzork.Weapon): pass self.player = pyzork.Player(money=500) sword = pyzork.ShopItem(item=Sword, price=25, amount=1) money = self.player.money sword.buy(self.player) self.assertEqual(self.player.money, money - sword.price) self.assertEqual(len(self.player.inventory.equipment), 1) sword.buy(self.player) self.assertEqual(self.player.money, money - sword.price) self.assertEqual(len(self.player.inventory.equipment), 1) sword.sell(self.player, 1) self.assertEqual(self.player.money, money) self.assertEqual(len(self.player.inventory.equipment), 0)
def test(self): inv = pyzork.Inventory( items=[HealingOnguent(), HealthPotion(), MagicPowder(), Spear()]) player = pyzork.Player(inventory=inv) battle = pyzork.Battle(player=player, enemies=[goblin, wizard, goblin2]) strings = [ ("use the potion on me", (player, HealthPotion)), ("use the onguent on me", (player, HealingOnguent)), ("throw the spear at the wizard", (wizard, Spear)), ("eat the magic powder", (player, MagicPowder)), #NO TARGET ("throw the potion at the fat goblin", (goblin, HealthPotion)), ] for string, enemy in strings: reply = pyzork.actions.use_item_parser(string, battle) self.assertIsNot(reply, None, msg=string) self.assertIs(reply[0], enemy[0], msg=string) self.assertIsInstance(reply[1], enemy[1], msg=string)
def setUp(self): self.player = pyzork.Player(max_health=100, health=0) self.charges = 0 self.heal = 0 pyzork.utils.update_output(lambda text: None)
def test(self): class Sword(pyzork.Weapon): pass class Shield(pyzork.Weapon): pass class BigArmor(pyzork.Armor): pass class HealthPotion(pyzork.Consumable): def __init__(self): super().__init__(charges=1) class HealingOnguent(pyzork.Consumable): def __init__(self): super().__init__(charges=1) class ImportantKey(pyzork.QuestItem): pass class Spear(pyzork.Weapon): pass class SpearThingy(pyzork.Consumable): def __init__(self): super().__init__(charges=1) class OldSpear(pyzork.QuestItem): pass inventory = pyzork.Inventory(items=[ Sword(), Shield(), HealthPotion(), BigArmor(), HealingOnguent(), ImportantKey() ]) player = pyzork.Player() inventory.add_item(OldSpear()) inventory.add_item(SpearThingy()) inventory.add_item(Spear()) item = inventory.get_consumable(name="HealingOnguent") inventory.use_item(item, player) item = inventory.get_consumable(name="HealingOnguent") self.assertIs(item, None) item = inventory.get_equipment(name="Spear") inventory.equip_item(item) self.assertIs(inventory.weapon, item) item = inventory.get_equipment(name="Spear") self.assertIs(item, None) item = inventory.get_quest(name="OldSpear") inventory.remove_item(item) item = inventory.get_quest(name="OldSpear") self.assertIs(item, None) inventory.print() item = inventory.get_item(name="BigArmor") self.assertIsNot(item, None)
else: self.health -= value def restore_health(self, value): self.health += value self.shield += int(value * 0.1) def restore_shield(self, value): self.shield += value def end_turn(self): """End this entity's turn, decrementing all the modifier's durations and removing the expired ones.""" for name in list(self.modifiers.keys()): modifier = self.modifiers[name] modifier.end_turn(self) if modifier.is_expired(): del self.modifiers[name] self.shield += self.max_shield * 0.1 class BigGoblin(EnemyWithShield): def __init__(self): super().__init__( max_health=10, max_shield=10, attack=3 ) e = BigGoblin() p = pyzork.Player(max_health=25, attack=4)
def setUp(self): self.player = pyzork.Player(max_energy=6, max_health=5) pyzork.utils.update_output(lambda text: None)