def lets_play(): command_list = [{ 'w': 'up', 's': 'down', 'a': 'left', 'd': 'right' }, 'f', 'spawn', 'status', 'u', 'p'] print('\nLets play a game!\n ') name = input('Write a name for your hero: ') title = input('How is your hero known as: ') h = Hero(name=name, title=title, health=100, mana=100, mana_regeneration_rate=2) name = input('Give a name to your weapon: ') w = Weapon(name=name, damage=20) h.equip(w) print('\n{} will fight with {} to save The Princess!\n'.format( h.known_as(), w.name)) input('Press enter to start the game!') map = Dungeon("level1.txt") map.spawn(h) map.print_map() input_data = input( "\nType w/s/a/d to move your hero up/down/left/right\ , f for fight, spawn for spawn, status to show hero's status, u for update spell/weapon or e for exitd: " ) while (input_data != 'e'): if input_data in command_list[0].keys(): map.move_hero(command_list[0][input_data]) map.print_map() elif input_data == command_list[1]: map.hero_attack() map.print_map() elif input_data == command_list[2]: map.spawn(h) map.print_map() elif input_data == command_list[3]: print('\n', h, h.weapon, h.spell) elif input_data == command_list[4]: which = input('Type spell/weapon: ') print( 'Are you sure. You have {} and the update is 20. Type y or n:' .format(map.hero.money)) result = input() if result == 'y': map.hero.update(which) else: print('Update not successful') elif input_data == 'm': print("\nType w/s/a/d to move your hero up/down/left/right\ , f for fight, spawn for spawn, status to show hero's status, u for update spell/weapon or e for exit" ) else: print('Comming soon!') print('Type m to see the curret command menu.') print('\n') input_data = input('Command: ')
class Test_Dungeon(unittest.TestCase): def setUp(self): self.map = Dungeon("level1.txt") self.h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) def test_init(self): self.assertEqual(self.map.get_map(), [['S', '.', '#', '#', '.', '.', 'S', '.', '.', 'T'], ['#', 'T', '#', '#', '.', '.', '#', '#', '#', '.'], [ '#', '.', '#', '#', '#', 'E', '#', '#', '#', 'E'], ['#', '.', 'E', '.', '.', '.', '#', '#', '#', '.'], ['#', '#', '#', 'T', '#', '#', '#', '#', '#', 'G']]) self.assertEqual(self.map.get_enemies(), [[2, 5], [2, 9], [3, 2]]) def test_spawn(self): self.map.spawn(self.h) self.assertEqual(self.h.mana, self.h.starting_mana) self.assertEqual(self.h.health, self.h.starting_health) self.assertEqual(self.map.get_hero_x(), 0) self.assertEqual(self.map.get_hero_y(), 0) self.assertTrue(self.map.spawn(self.h)) def test_move(self): self.map.spawn(self.h) self.h.take_damage(90) self.assertFalse(self.map.move_hero(self.h, 'up')) self.assertTrue(self.map.move_hero(self.h, 'right')) with self.assertRaises(Wrong_direction): self.assertTrue(self.map.move_hero(self.h, 'hihihi')) self.assertEqual(1, self.map.get_hero_x()) self.assertEqual(0, self.map.get_hero_y()) self.assertFalse(self.map.move_hero(self.h, 'right')) self.assertEqual(1, self.map.get_hero_x()) self.assertEqual(0, self.map.get_hero_y()) # self.map.move_hero(self.h, 'down') def test_spell_or_weapon(self): self.h.equip(Weapon(name="The Axe of Destiny", damage=20)) self.h.learn( Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)) self.assertTrue(isinstance(self.map.spell_or_weapon(self.h), Spell)) self.h.equip(Weapon(name="The Axe of Destiny", damage=120)) self.assertTrue(isinstance(self.map.spell_or_weapon(self.h), Weapon)) def test_hero_attack(self): self.h.equip(Weapon(name="The Axe of Destiny", damage=20)) self.h.learn( Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)) self.map.spawn(self.h) self.map.print_map() self.map.move_hero(self.h, 'right') self.map.print_map() self.map.move_hero(self.h, 'down') self.map.print_map() self.map.move_hero(self.h, 'down') self.map.print_map() self.map.move_hero(self.h, 'down') self.map.print_map() # self.assertEqual(self.map.move_hero(self.h, 'right'), True) self.map.hero_attack(self.h) self.map.print_map() for x in range(5): self.map.move_hero(self.h, 'right') self.map.print_map() self.map.move_hero(self.h, 'up') self.map.print_map() self.map.spawn(self.h) self.map.print_map() self.map.move_hero(self.h, 'left') self.map.move_hero(self.h, 'down') self.map.move_hero(self.h, 'down') self.map.print_map()