class TestFight(unittest.TestCase): def setUp(self): self.hero = Hero(health=100, mana=50, name="Yamamoto", title="Samurai", mana_regeneration_rate=2) self.enemy = Enemy(health=100, mana=100, damage=20) self.weapon = Weapon.generate(self.hero) self.spell = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2) self.hero.learn(self.spell) self.hero.equip(self.weapon) def test_simple_fight_in_one_cell(self): fight = Fight(self.hero, self.enemy) self.assertIs(fight.start_fight(), self.hero) def test_sipmle_fight_starts_with_weapon(self): fight = Fight(self.hero, self.enemy, "spell") self.assertIs(fight.start_fight(), self.hero) print(self.hero.__dict__)
class DungeonTests(unittest.TestCase): def setUp(self): self.dummy = Dungeon() self.hero = Hero(name='Fuggboi', title='Wise') def test_spawn_method(self): self.dummy.open_map(fileDir=plainMapDir) self.dummy.spawn(hero=self.hero) # self.dummy.print_map() self.assertEqual( self.hero.get_coords(), (1, 1)) def test_move_method(self): with self.subTest('Test moving up.'): self.dummy.open_map(fileDir=plainMapDir) self.dummy.spawn(hero=self.hero) self.dummy.move_hero(direction='up') self.assertEqual( self.hero.get_coords(), (1, 0) ) with self.subTest('Test moving down.'): self.dummy.open_map(fileDir=plainMapDir) self.dummy.spawn(hero=self.hero) self.dummy.move_hero(direction='down') self.assertEqual( self.hero.get_coords(), (1, 2) ) with self.subTest('Test moving right.'): self.dummy.open_map(fileDir=plainMapDir) self.dummy.spawn(hero=self.hero) self.dummy.move_hero(direction='right') self.assertEqual( self.hero.get_coords(), (2, 1) ) with self.subTest('Test moving left.'): self.dummy.open_map(fileDir=plainMapDir) self.dummy.spawn(hero=self.hero) self.dummy.move_hero(direction='left') self.assertEqual( self.hero.get_coords(), (0, 1) ) with self.subTest('Test moving into treasure chest.'): self.dummy.open_map(fileDir=treasureMapDir) self.dummy.spawn(hero=self.hero) with self.subTest('Test moving into enemy.'): self.dummy.open_map(fileDir=enemyMapDir) self.dummy.spawn(hero=self.hero) self.dummy.move_hero(direction='right') with self.subTest('Test shoot_blindly method.'): self.hero.heal_to_full() self.dummy.open_map(fileDir=enemyMapDir) s1 = Spell(name="Magic spit", damage=30, manaCost=25, castRange=2) self.hero.learn(s1) self.dummy.spawn(hero=self.hero) self.dummy.shoot_blindly() self.dummy.print_map() with self.subTest('Test moving into gateway.'): self.dummy.open_map(fileDir=validMapDir) self.dummy.spawn(hero=self.hero) self.assertEqual(self.dummy.move_hero(direction='right'), True) with self.subTest('Test moving into gateway work when dirs have larger indexes.'): temp = 'dungeon_maps/level_99/' self.dummy.open_map(fileDir=temp) self.dummy.spawn(hero=self.hero) self.assertEqual( type(self.dummy.move_hero(direction='right')), str)
'''this is going to be a manual test''' from src.hero import Hero from src.enemy import Enemy from src.spell import Spell from src.weapon import Weapon from src.fight import Fight from src.fight_status_bar import FightStatusBar h = Hero(name="Genadi", title="Gopnik") s = Spell(name="Kwass Molotov", damage=5, manaCost=10, castRange=7) s1 = Spell(name="Magic spit", damage=10, manaCost=25, castRange=2) w = Weapon(name="Beer Bottle", damage=25) w1 = Weapon(name="Bat", damage=22) h.equip(w) h.learn(s) h.coordinates = (0, 7) e = Enemy() e.learn(s1) e.equip(w1) e.coordinates = (0, 0) """ f = Fight(h, e,) f.initialize_fight() """