class TestDungeons(unittest.TestCase): def setUp(self): self.dungeon = Dungeon("level1.txt") self.hero = Hero("Arthur", "knight", 100, 100, 2) self.my_map = "S.##.....T\n#T##..###.\n#.###E###E\n#.E...###.\n###T#####G\n" self.my_matrix = [['S', '.', '#', '#', '.', '.', '.', '.', '.', 'T'], ['#', 'T', '#', '#', '.', '.', '#', '#', '#', '.'], ['#', '.', '#', '#', '#', 'E', '#', '#', '#', 'E'], ['#', '.', 'E', '.', '.', '.', '#', '#', '#', '.'], ['#', '#', '#', 'T', '#', '#', '#', '#', '#', 'G']] def test_init(self): self.assertTrue(isinstance(self.dungeon, Dungeon)) self.assertEqual(self.dungeon.my_map, self.my_map) self.assertEqual(self.my_matrix, self.dungeon.matrix) def test_matrix_to_map(self): self.assertEqual(self.dungeon.matrix_to_map(), self.my_map) def test_map_to_matrix(self): self.assertEqual(self.dungeon.map_to_matrix(), self.my_matrix) def test_get_hero_position(self): self.dungeon.spawn(self.hero) self.assertEqual(self.dungeon.get_hero_position(), (0, 0)) self.dungeon.spawn(self.hero) self.dungeon.spawn(self.hero) self.assertEqual(self.dungeon.get_hero_position(), (0, 4)) def test_move_hero(self): self.dungeon.spawn(self.hero) self.assertFalse(self.dungeon.move_hero('left'))
def main(): h = Hero("Bron", "Dragonslayer", 100, 100, 2) w = Weapon("The Axe of Destiny", 20) h.equip(w) s = Spell("Fireball", 20, 50, 2) h.learn(s) map = Dungeon("map.txt") map.open_map() map.spawn(h) map.move_hero("right") map.move_hero("down") map.move_hero("down") map.move_hero("down") map.print_map() fight = Fight(map, h) fight.hero_attack(by="spell") map.respawn() map.get_map()
class DungeonsAndPythonsTests(unittest.TestCase): def setUp(self): self.hero = Hero("Bron", "Dragon", 100, 100, 2) self.dungeon = Dungeon("map2.txt") self.weapon = Weapon(name="The Axe of Destiny", damage=20) self.spell = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2) self.mana_potion = self.hero.mana self.health_potion = self.hero.health def test_known_as(self): self.assertEqual(self.hero.known_as(), "Bron the Dragon") def test_is_alive(self): self.assertTrue(self.hero.is_alive()) def test_spawn_hero(self): self.dungeon.spawn() def test_get_position(self): self.dungeon.spawn() self.assertEqual(self.dungeon.get_position(), (0, 0)) def test_move_right(self): self.dungeon.spawn() self.dungeon.move_hero("right") # self.dungeon.print_map() self.assertFalse(self.dungeon.move_hero("right")) def test_move_up(self): self.dungeon.spawn() self.dungeon.move_hero("up") self.assertFalse(self.dungeon.move_hero("up")) def test_move_left(self): self.dungeon.spawn() self.dungeon.move_hero("left") self.assertFalse(self.dungeon.move_hero("left")) def test_move_down(self): self.dungeon.spawn() self.dungeon.move_hero("down") self.assertFalse(self.dungeon.move_hero("down"))