def battle(player: Player, boss: Boss) -> bool: player_turn = True while player.hit_points > 0 and boss.hit_points > 0: # print("-- Boss turn --") if not player_turn else print("-- Player turn --") # print(f"- Player has {player.hit_points} hit points, {player.armor} armor, " # f"{player.mana} mana") # print(f"- Boss has {boss.hit_points} hit points") apply_active_spells(player, boss) if player_turn: active_spells = [spell["name"] for spell in player.active_spells] + \ [spell["name"] for spell in boss.active_spells] spell = player.cast_spell(active_spells) if player.mana < spell["cost"]: print(f"Cannot cast spell, no mana left!") return False else: player.mana -= spell["cost"] player.mana_spent += spell["cost"] if spell["damage"]: if spell["turns"]: #print(f"Player casts {spell['name']}.") boss.apply_spell(spell) else: if spell["heals"]: player.hit_points += spell["heals"] #print(f"Player casts {spell['name']}, " # f"dealing {spell['damage']} damage.") boss.hit_points -= spell["damage"] else: #print(f"Player casts {spell['name']}.") player.apply_spell(spell) player_turn = False else: damage_dealt = boss.damage - player.armor if damage_dealt <= 0: damage_dealt = 1 player.hit_points -= damage_dealt #print(f"Boss attacks for {damage_dealt} damage!") player_turn = True player.boss_hp = boss.hit_points if player.hit_points <= 0: return False else: return True