#!/usr/bin/python # -*- coding: utf-8 -*- if __name__ == '__main__' and __package__ is None: from os import sys, path sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) from game.spells import magic_missile, drain, shield, poison, recharge from game.characters import Boss, Wizard from game.strategies import SelectSpellByPredefinedOrder from game.game_state import combat def hit_armor_mana(wizard): return (wizard.hit_points, wizard.armor, wizard.mana) mock_order = [poison(), recharge(), magic_missile(), magic_missile(), poison(), shield(), magic_missile(), magic_missile()] wizard = Wizard(hit_points=50, mana=500, spell_selection_strategy=SelectSpellByPredefinedOrder(mock_order)) boss = Boss(hit_points=51, damage=9) combat(wizard, boss) assert not boss.is_alive() assert wizard.is_alive() # SOLUTION [((50, 0, 500), 51, frozenset([])), ('Poison', 173), ((41, 0, 327), 48, frozenset([('Poison', 5)])), ('Recharge', 402), ((32, 0, 199), 42, frozenset([('Poison', 3), ('Recharge', 4)])), ('Magic Missile', 455), ((23, 0, 348), 32, frozenset([('Poison', 1), ('Recharge', 2)])), ('Magic Missile', 508), ((14, 0, 497), 25, frozenset([])), ('Poison', 681), ((5, 0, 324), 22, frozenset([('Poison', 5)])), ('Shield', 794), ((3, 7, 211), 16, frozenset([('Poison', 3), ('Shield', 5)])),
if __name__ == '__main__' and __package__ is None: from os import sys, path sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) from game.spells import Effect, TimedEffect from game.spells import magic_missile, drain, shield, poison, recharge from game.characters import Boss, Wizard from game.strategies import SelectSpellByPredefinedOrder from game.game_state import GameState def hit_armor_mana(wizard): return (wizard.hit_points, wizard.armor, wizard.mana) # Now, suppose the same initial conditions, except that the boss has 14 hit points instead: mock_order = [recharge(), shield(), drain(), poison(), magic_missile()] wizard = Wizard(hit_points=10, mana=250, spell_selection_strategy=SelectSpellByPredefinedOrder(mock_order)) boss = Boss(hit_points=14, damage=8) game_state = GameState(wizard, boss) # -- Player turn -- # - Player has 10 hit points, 0 armor, 250 mana assert hit_armor_mana(wizard) == (10, 0, 250) # - Boss has 14 hit points assert boss.hit_points == 14 # Player casts Recharge. s = wizard.launch_spell(game_state) assert s.name == 'Recharge' # -- Boss turn -- # - Player has 10 hit points, 0 armor, 21 mana