本文整理汇总了Python中dungeon.Dungeon.move_hero方法的典型用法代码示例。如果您正苦于以下问题:Python Dungeon.move_hero方法的具体用法?Python Dungeon.move_hero怎么用?Python Dungeon.move_hero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dungeon.Dungeon
的用法示例。
在下文中一共展示了Dungeon.move_hero方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move_hero [as 别名]
def main():
my_dungeon = Dungeon("area.txt")
my_dungeon.spawn(my_dungeon.hero)
my_dungeon.hero.learn(Spell("strong", 30, 70, 6))
while my_dungeon.hero.is_alive():
print(my_dungeon.print_map())
command = input("Enter Direction: ")
my_dungeon.move_hero(command)
示例2: test_moving_around_the_map
# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move_hero [as 别名]
def test_moving_around_the_map(self):
dungeon = Dungeon("level2.txt")
dungeon.spawn(self.hero)
dungeon.move_hero("right")
dungeon.move_hero("down")
self.assertFalse(dungeon.move_hero("right"))
dungeon.move_hero("down")
self.assertFalse(dungeon.move_hero("left"))
# dungeon.print_map()
self.assertTrue(dungeon.move_hero("down"))
示例3: DungeonTest
# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move_hero [as 别名]
class DungeonTest(unittest.TestCase):
def setUp(self):
self.new_map = [
['S', '.', '#', '#', '.', '.', '.', '.', '.', 'T'],
['#', 'T', '#', '#', '.', '.', '#', '#', '#', '.'],
['#', '.', '#', '#', '#', 'E', '#', '#', '#', 'E'],
['#', '.', 'E', '.', '.', '.', '#', '#', '#', '.'],
['#', '#', '#', 'T', '#', '#', '#', '#', '#', 'G']
]
self.dungeon = Dungeon(self.new_map)
self.hero = Hero("Floki", "Builder", 100, 100, 2)
def test_create_new_instance(self):
self.assertTrue(isinstance(self.dungeon, Dungeon))
def test_valid_members(self):
self.assertEqual(self.dungeon.map, self.new_map)
self.assertEqual(self.dungeon.spawning_points, [(0, 0)])
self.assertEqual(self.dungeon.hero, None)
self.assertEqual(self.dungeon.hero_x, None)
self.assertEqual(self.dungeon.hero_y, None)
def test_spawn(self):
self.assertTrue(self.dungeon.spawn(self.hero))
self.assertEqual(self.dungeon.hero.health, 100)
self.assertEqual(self.dungeon.hero.mana, 100)
self.assertEqual(self.dungeon.hero_x, 0)
self.assertEqual(self.dungeon.hero_y, 0)
def test_move(self):
self.dungeon.spawn(self.hero)
self.assertFalse(self.dungeon.move_hero("u"))
self.assertIsNone(self.dungeon.move_hero("r"))
self.assertIsNone(self.dungeon.move_hero("d"))
self.assertEqual(self.dungeon.hero_x, 1)
self.assertEqual(self.dungeon.hero_y, 1)
self.assertIsNone(self.dungeon.move_hero("d"))
self.assertEqual(self.dungeon.hero_x, 2)
self.assertEqual(self.dungeon.hero_y, 1)
示例4: test_the_game
# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move_hero [as 别名]
def test_the_game(self):
h = Hero(name="Bron", title="Dragonslayer",
health=100, mana=100, mana_regeneration_rate=2)
w = Weapon(name="The Axe of Destiny", damage=20)
h.equip(w)
s = Spell(name="Lightning bolt", damage=30, mana_cost=50, cast_range=2)
h.learn(s)
dungeon = Dungeon("level1.txt")
dungeon.spawn(h)
dungeon.move_hero("right")
dungeon.move_hero("down")
dungeon.try_range_attack()
dungeon.move_hero("down")
dungeon.move_hero("down")
dungeon.try_range_attack()
# dungeon.move_hero("right")
# dungeon.move_hero("right")
dungeon.print_map()
示例5: dungeon_test
# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move_hero [as 别名]
class dungeon_test(unittest.TestCase):
def setUp(self):
self.dungeon_map = [
['.', 'S', '#', '#', '.', '.', '.', '.', '.', 'T'],
['#', 'T', '#', '#', '.', '.', '#', '#', '#', '.'],
['#', '.', '#', '#', '#', 'E', '#', '#', '#', 'E'],
['#', '.', 'E', '.', '.', '.', '#', '#', '#', '.'],
['#', '#', '#', 'T', '#', '#', '#', '#', '#', 'G']]
f = open('test_level.txt', 'w')
for line in self.dungeon_map:
f.write(''.join(line) + '\n')
f.close()
self.dungeon = Dungeon("test_level.txt")
def tearDown(self):
os.remove("test_level.txt")
def test_init(self):
self.assertEqual(self.dungeon.dungeon_map, self.dungeon_map)
def test_find_item_coordinates(self):
self.assertEqual(self.dungeon._find_item_coordinates('S'), (0, 1))
self.assertEqual(self.dungeon._find_item_coordinates('G'), (4, 9))
def test_spawn(self):
hero = Unit(100, 100, 5)
self.dungeon.spawn(hero)
self.assertEqual(self.dungeon.dungeon_map[0][1], 'H')
def test_prin_map(self):
map_string = """.S##.....T
#T##..###.
#.###E###E
#.E...###.
###T#####G"""
self.assertEqual(self.dungeon.print_map(), map_string)
def test_move_hero(self):
hero = Unit(100, 100, 5)
self.dungeon.spawn(hero)
self.assertFalse(self.dungeon.move_hero('up'))
self.assertTrue(self.dungeon.move_hero('left'))
# self.assertTrue(self.dungeon.move_hero('rigth'))
self.assertTrue(self.dungeon.move_hero('rigth'))
self.assertTrue(self.dungeon.move_hero('down'))
self.assertTrue(self.dungeon.move_hero('down'))
self.assertEqual(self.dungeon.hero_possition, (2, 1))
self.assertEqual(self.dungeon.dungeon_map[1][1], '.')
self.dungeon_map[0][1] = '.'
self.dungeon_map[1][1] = '.'
self.dungeon_map[2][1] = 'H'
self.assertEqual(self.dungeon.dungeon_map, self.dungeon_map)
def test_found_treasure(self):
hero = Unit(100, 100, 5)
hero.health = 1
hero.mana = 1
self.dungeon.spawn(hero)
self.dungeon._found_treasure('mana')
self.assertGreater(hero.mana, 1)
self.dungeon._found_treasure('health')
self.assertGreater(hero.health, 1)
self.dungeon._found_treasure('weapon')
self.assertNotEqual(hero.weapon, None)
self.dungeon._found_treasure('spell')
self.assertNotEqual(hero.spell, None)
def test_create_enemy(self):
enemy = self.dungeon._create_enemy(100, 100, 100)
self.assertEqual(enemy.health, 100)
self.assertEqual(enemy.mana, 100)
self.assertEqual(enemy.damage, 100)
def test_find_enemy(self):
self.dungeon.hero_possition = (3, 3)
self.dungeon.dungeon_map[3][3] = 'H'
def test_hero_attack(self):
hero = Unit(100, 100, 5)
hero.learn(Spell('a', 10, 10, 2))
self.dungeon.spawn(hero)
self.dungeon.move_hero('down')
self.dungeon.move_hero('down')
self.assertEqual('Nothing in casting range 2',
self.dungeon.hero_attack(by="spell"))
self.dungeon.move_hero('down')
self.assertIsInstance(self.dungeon.hero_attack(by='spell'), Fight)
示例6: Hero
# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move_hero [as 别名]
from hero import Hero
from dungeon import Dungeon
from weapons_and_spells import Weapon, Spell
h = Hero(name="Bron", title="Dragonslayer",
health=100, mana=100, mana_regeneration_rate=2)
w = Weapon(name="The Axe of Destiny", damage=20)
h.equip(w)
s = Spell(name="Lightning bolt", damage=30, mana_cost=50, cast_range=2)
h.learn(s)
dungeon = Dungeon("level1.txt")
dungeon.spawn(h)
dungeon.print_map()
dungeon.move_hero("right")
dungeon.move_hero("down")
dungeon.print_map()
dungeon.try_range_attack()
dungeon.move_hero("down")
dungeon.move_hero("down")
dungeon.try_range_attack()
dungeon.print_map()
dungeon.move_hero("right")
dungeon.move_hero("right")
dungeon.move_hero("right")
dungeon.move_hero("right")
dungeon.move_hero("up")
dungeon.print_map()
dungeon.move_hero("down")
示例7: HeroTests
# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move_hero [as 别名]
class HeroTests(unittest.TestCase):
def setUp(self):
self.hero = Hero("Ahri", "Kingslayer", 100, 100, 2)
self.enemy = Enemy(100, 100, 20)
self.dungeon = Dungeon("level1.txt")
self.weapon = Weapon("The Axe of Destiny", damage=20)
self.spell = Spell(
name="Fireball", damage=30, mana_cost=50, cast_range=1)
def test_known_as(self):
self.assertEqual(self.hero.known_as(), "Ahri the Kingslayer")
def test_take_damage(self):
self.hero.take_damage(150)
self.assertEqual(self.hero.get_health(), 0)
def test_take_healing(self):
self.hero.take_damage(50)
self.assertTrue(self.hero.take_healing(55))
self.assertEqual(self.hero.get_health(), 100)
def test_take_mana_with_potion(self):
pass
# Test enemy who can not regenerate mana
def test_mana_regeneration_while_moving(self):
pass
def test_can_cast(self):
self.hero.learn(self.spell)
self.assertTrue(self.hero.can_cast())
def test_can_cast_with_no_spells_learned(self):
self.assertFalse(self.hero.can_cast())
def test_attack_not_being_specified(self):
with self.assertRaises(ValueError):
self.hero.attack(by="gun")
def test_attack_without_weapon_or_spell(self):
self.assertEqual(self.hero.attack(by="weapon"), 0)
self.assertEqual(self.hero.attack(by="magic"), 0)
# Test for enemy (base damage= = 20)
self.assertEqual(self.enemy.attack(by="weapon"), 20)
self.assertEqual(self.enemy.attack(by="magic"), 20)
def test_attack(self):
self.hero.equip(self.weapon)
self.assertEqual(self.hero.attack(by="weapon"), 20)
self.hero.learn(self.spell)
self.assertEqual(self.hero.attack(by="magic"), 30)
def test_dungeon_map(self):
self.assertEqual(self.dungeon.map, [['S', '.', '#', '#', '.', '.', '.', '.', '.', 'T'], ['#', 'T', '#', '#', '.', '.', '#', '#', '#', '.'], ['#', '.', '#', '#', '#', 'E', '#', '#', '#', 'E'], ['#', '.', 'E', '.', '.', '.', '#', '#', '#', '.'], ['#', '#', '#', 'T', '#', '#', '#', '#', '#', 'G']])
# self.dungeon.print_map()
def test_spawn_hero(self):
self.dungeon.spawn(self.hero)
self.dungeon.spawn(self.hero)
self.dungeon.spawn(self.hero)
# self.dungeon.print_map()
def test_get_position(self):
self.dungeon.spawn(self.hero)
self.assertEqual(self.dungeon.get_position(), (0, 0))
def test_move_right(self):
self.dungeon.spawn(self.hero)
self.dungeon.move_hero("right")
# self.dungeon.print_map()
self.assertFalse(self.dungeon.move_hero("right"))
def test_move_left(self):
self.dungeon.spawn(self.hero)
self.dungeon.move_hero("right")
self.assertTrue(self.dungeon.move_hero("left"))
# self.dungeon.print_map()
def test_move_up(self):
self.dungeon.spawn(self.hero)
self.assertFalse(self.dungeon.move_hero("up"))
def test_move_down(self):
self.dungeon.spawn(self.hero)
self.assertFalse(self.dungeon.move_hero("down"))
def test_moving_around_the_map(self):
dungeon = Dungeon("level2.txt")
dungeon.spawn(self.hero)
dungeon.move_hero("right")
dungeon.move_hero("down")
self.assertFalse(dungeon.move_hero("right"))
dungeon.move_hero("down")
self.assertFalse(dungeon.move_hero("left"))
# dungeon.print_map()
self.assertTrue(dungeon.move_hero("down"))
def test_the_game(self):
h = Hero(name="Bron", title="Dragonslayer",
health=100, mana=100, mana_regeneration_rate=2)
#.........这里部分代码省略.........