本文整理汇总了Python中hero.Hero.get_mana方法的典型用法代码示例。如果您正苦于以下问题:Python Hero.get_mana方法的具体用法?Python Hero.get_mana怎么用?Python Hero.get_mana使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hero.Hero
的用法示例。
在下文中一共展示了Hero.get_mana方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import get_mana [as 别名]
class Test(unittest.TestCase):
def setUp(self):
self.w = Weapon("axe", 20)
self.spell = Spell("love spell", 70, 2, 4)
self.h = Hero("Arthur", "great", 100, 100, 100, 2, self.w, self.spell)
def test_hero_init(self):
self.assertEqual(self.h.get_name(), "Arthur")
self.assertEqual(self.h.get_title(), "great")
self.assertEqual(self.h.get_health(), 100)
self.assertEqual(self.h.get_start_health(), 100)
self.assertEqual(self.h.get_mana(), 100)
self.assertEqual(self.h.get_mana_rate(), 2)
self.assertEqual(self.h.get_weapon(), "axe")
def test_hero_init(self):
self.assertEqual(str(self.h), "Arthur great 100 100 2")
def test_hero_known_as(self):
self.assertEqual(self.h.known_as(), "Arthur the great")
def test_hero_is_alive(self):
self.assertTrue(self.h.is_alive())
def test_hero_is_dead(self):
self.assertFalse(self.h.is_dead())
def test_hero_can_cast(self):
self.assertTrue(self.h.can_cast())
def test_hero_take_damage(self):
self.assertEqual(self.h.take_damage(70), 30)
def test_hero_take_healing(self):
self.h.take_damage(70)
self.assertEqual(self.h.take_healing(20), 50)
def test_hero_equip(self):
self.assertEqual(self.h.equip(self.w), "Equipped with axe, damage: 20")
def test_hero_attack(self):
self.assertEqual(self.h.attack("weapon"), 20)
示例2: TestHero
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import get_mana [as 别名]
class TestHero(unittest.TestCase):
def setUp(self):
self._hero = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2)
def test_init(self):
self.assertTrue(isinstance(self._hero, Hero))
with self.assertRaises(ValueError):
Hero(name="Bron", title="Dragonslayer", health=-1, mana=100, mana_regeneration_rate=2)
with self.assertRaises(ValueError):
Hero(name="Bron", title="Dragonslayer", health=150, mana=100, mana_regeneration_rate=2)
with self.assertRaises(ValueError):
Hero(name="Bron", title="Dragonslayer", health=100, mana=-1, mana_regeneration_rate=2)
with self.assertRaises(ValueError):
Hero(name="Bron", title="Dragonslayer", health=100, mana=150, mana_regeneration_rate=2)
with self.assertRaises(ValueError):
Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=-1)
with self.assertRaises(TypeError):
Hero(name=0, title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2)
with self.assertRaises(TypeError):
Hero(name="Bron", title=0, health=100, mana=100, mana_regeneration_rate=2)
with self.assertRaises(TypeError):
Hero(name="Bron", title="Dragonslayer", health="str", mana=100, mana_regeneration_rate=2)
with self.assertRaises(TypeError):
Hero(name="Bron", title="Dragonslayer", health=100, mana="str", mana_regeneration_rate=2)
with self.assertRaises(TypeError):
Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate="str")
def test_known_as(self):
self.assertEqual(self._hero.known_as(), "Bron the Dragonslayer")
def test_get_health(self):
self.assertEqual(self._hero.get_health(), self._hero._health)
def test_get_mana(self):
self.assertEqual(self._hero.get_mana(), self._hero._mana)
def test_is_alive(self):
self.assertTrue(self._hero.is_alive())
def test_can_cast(self):
self.assertTrue(self._hero.can_cast())
def test_take_damage(self):
self._hero.take_damage(30)
self.assertEqual(self._hero._health, 70)
with self.assertRaises(ValueError):
self._hero.take_damage(-30)
def test_take_healing(self):
damaged_hero = Hero(name="Bron", title="Dragonslayer", health=50, mana=100, mana_regeneration_rate=2)
self.assertTrue(damaged_hero.take_healing(30))
def test_take_mana(self):
down_mana_hero = Hero(name="Bron", title="Dragonslayer", health=100, mana=10, mana_regeneration_rate=2)
down_mana_hero.take_mana(30)
self.assertEqual(down_mana_hero._mana, 40)
def test_equip(self):
w1 = Weapon(name="The Axe of Destiny", damage=20)
w2 = Weapon(name="Crescent Scimitar", damage=132)
self._hero.equip(w2)
with self.assertRaises(HeroAlreadyHasAWeapon):
self._hero.equip(w1)
def test_learn(self):
s1 = Spell(name="Fireball", damage=30, mana_cost=20, cast_range=2)
s2 = Spell(name="Earth Pulse", damage=50, mana_cost=20, cast_range=2)
self._hero.learn(s1)
self._hero.learn(s2)
self.assertEqual(self._hero._spell, s2)
def test_attack(self):
weapon = Weapon(name="Crescent Scimitar", damage=20)
self.assertEqual(self._hero.attack(by="weapon"), 0)
self._hero.equip(weapon)
self.assertEqual(self._hero.attack(by="weapon"), weapon.damage)
示例3: HeroTest
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import get_mana [as 别名]
class HeroTest(unittest.TestCase):
def setUp(self):
self.hunter = Hero("Lagerta", "Arrow", 120, 120, 2)
def test_create_new_instance(self):
self.assertTrue(isinstance(self.hunter, Hero))
def test_valid_members(self):
self.assertEqual(self.hunter.name, "Lagerta")
self.assertEqual(self.hunter.title, "Arrow")
self.assertEqual(self.hunter.health, 120)
self.assertEqual(self.hunter.mana, 120)
self.assertEqual(self.hunter.mana_regeneration_rate, 2)
self.assertEqual(self.hunter.max_health, 120)
self.assertEqual(self.hunter.max_mana, 120)
def test_known_as(self):
self.assertEqual(self.hunter.known_as(), "Lagerta the Arrow")
def test_get_health(self):
self.assertEqual(self.hunter.get_health(), 120)
def test_get_mana(self):
self.assertEqual(self.hunter.get_mana(), 120)
def test_is_alive(self):
self.assertTrue(self.hunter.is_alive())
self.hunter.health = 0
self.assertFalse(self.hunter.is_alive())
def test_can_cast_without_spell(self):
self.assertFalse(self.hunter.can_cast())
def test_can_cast_with_more_mana(self):
self.hunter.spell = Spell("Chilling Poison", 20, 20, 2)
self.assertTrue(self.hunter.can_cast())
def test_can_cast_with_less_mana(self):
self.hunter.spell = Spell("Chilling Poison", 20, 20, 2)
self.hunter.mana = 0
self.assertFalse(self.hunter.can_cast())
def test_take_damage_more_than_health(self):
self.hunter.take_damage(150)
self.assertEqual(self.hunter.health, 0)
def test_take_damage_less_than_health(self):
self.hunter.take_damage(100)
self.assertEqual(self.hunter.health, 20)
def test_take_healing_dead_hero(self):
self.hunter.health = 0
self.assertFalse(self.hunter.take_healing(200))
def test_take_healing_with_more_points_than_max_health(self):
self.hunter.health = 80
self.assertTrue(self.hunter.take_healing(200))
self.assertEqual(self.hunter.health, 120)
def test_take_healing_with_less_points_than_max_health(self):
self.hunter.health = 90
self.assertTrue(self.hunter.take_healing(20))
self.assertEqual(self.hunter.health, 110)
def test_take_mana_with_more_points_than_max_mana(self):
self.hunter.mana = 80
self.hunter.take_mana(200)
self.assertEqual(self.hunter.mana, 120)
def test_take_mana_with_negative_mana(self):
self.hunter.mana = 50
self.hunter.take_mana(-60)
self.assertEqual(self.hunter.mana, 0)
def test_take_mana_with_less_points_than_max_mana(self):
self.hunter.mana = 65
self.hunter.take_mana(20)
self.assertEqual(self.hunter.mana, 85)
def test_equip(self):
knife = Weapon("Knife", 10)
self.hunter.equip(knife)
self.assertEqual(self.hunter.weapon, knife)
def test_learn(self):
mind_blast = Spell("Mind Blast", 20, 35, 5)
self.hunter.learn(mind_blast)
self.assertEqual(self.hunter.spell, mind_blast)
def test_attack_without_equiped_weapon(self):
self.assertEqual(self.hunter.attack(by="weapon"), 0)
def test_attack_with_equiped_weapon(self):
knife = Weapon("Sword", 30)
self.hunter.equip(knife)
self.assertEqual(self.hunter.attack(by="weapon"), 30)
def test_attack_without_learned_spell(self):
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import get_mana [as 别名]
#.........这里部分代码省略.........
fight_pos = 0
for elem in choices:
if self.__map[elem[0]][elem[1]] == 'E':
fight_pos = elem
if fight_pos != 0:
range_to_enemy = max(row - fight_pos[0], col - fight_pos[1])
for i in range(range_to_enemy):
fight.moving_fight()
result = fight.static_fight()
if result:
print("Hero wins")
self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = 'H'
return True
else:
print("Hero is dead! Respawning...")
self.spawn(self.__hero)
return True
def __movement(self, new_hero_pos):
if self.__map[new_hero_pos[0]][new_hero_pos[1]] in ['#', 'T', 'E']:
if self.__map[new_hero_pos[0]][new_hero_pos[1]] == '#':
return False
if self.__map[new_hero_pos[0]][new_hero_pos[1]] == 'T':
self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = '.'
self.__hero_pos = new_hero_pos
treasure = self.spawn_treasure()
if isinstance(treasure, ManaPotion):
print("Mana pot found")
mana = treasure.get_mana()
self.__hero.take_mana(mana)
print("Hero healed with {} mana".format(mana))
print("Hero's mana is: {}".format(self.__hero.get_mana()))
if isinstance(treasure, HealthPotion):
print("Healing pot found!")
health = treasure.get_health()
self.__hero.take_healing(health)
print("Hero healed with {} health".format(health))
print(
"Hero;s health is: {}".format(
self.__hero.get_health()))
if isinstance(treasure, Weapon):
print("Weapon found!")
self.__hero.equip(treasure)
if isinstance(treasure, Spell):
print("Spell found!")
self.__hero.learn(treasure)
self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = 'H'
return True
if self.__map[new_hero_pos[0]][new_hero_pos[1]] == 'E':
print("Enemy found")
self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = '.'
self.__hero_pos = new_hero_pos
# enemy spawner
enemy = Enemy(health=random.randrange(50, 150),
mana=random.randrange(20, 100),