本文整理汇总了Python中hero.Hero.attack方法的典型用法代码示例。如果您正苦于以下问题:Python Hero.attack方法的具体用法?Python Hero.attack怎么用?Python Hero.attack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hero.Hero
的用法示例。
在下文中一共展示了Hero.attack方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WeaphonTest
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [as 别名]
class WeaphonTest(unittest.TestCase):
def setUp(self):
self.sniper = Weaphon("Gun", 85, 0.10)
self.hammer = Weaphon("One-Hand", 30, 0)
self.bron_orc = Orc("Pesho", 100, 1.50)
self.bron_hero = Hero("Ivan", 100, "Magician")
def test_weaphon_initialization(self):
self.assertEquals("Gun", self.sniper.type)
self.assertEquals(85, self.sniper.damage)
self.assertEquals(0.10, self.sniper.critical_strike_percent)
def test_crit_hit_sniper(self):
temp = False
for i in range(100):
if temp:
break
else:
temp = self.sniper.critical_hit()
self.assertTrue(temp)
def test_crit_hit_hammer(self):
temp = False
for i in range(100):
if temp:
break
else:
temp = self.hammer.critical_hit()
self.assertFalse(temp)
def test_entity_has_weaphon(self):
self.bron_orc.equip_weapon(self.hammer)
self.assertTrue(self.bron_orc.has_weaphon())
def test_entity_do_not_has_wep(self):
self.assertFalse(self.bron_orc.has_weaphon())
def test_entity_equip_weaphon_first_time(self):
self.bron_orc.equip_weapon(self.hammer)
self.assertEqual("One-Hand", self.bron_orc.weaphon.type)
def test_equip_weaphon_when_the_entity_allready_has_one(self):
self.bron_orc.equip_weapon(self.hammer)
self.bron_orc.equip_weapon(self.sniper)
self.assertEqual("Gun", self.bron_orc.weaphon.type)
def test_attack_no_weaphon(self):
self.assertEqual(0, self.bron_orc.attack())
def test_atack_hero(self):
self.bron_hero.equip_weapon(self.hammer)
self.assertEqual(30, self.bron_hero.attack())
def test_atack_orc(self):
self.bron_orc.equip_weapon(self.hammer)
self.assertEqual(45, self.bron_orc.attack())
示例2: TestHero
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [as 别名]
class TestHero(unittest.TestCase):
def setUp(self):
self.h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2)
self.w = Weapon(name="The Axe of Destiny", damage=20)
self.s = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)
def test_init(self):
self.assertEqual(self.h.name, "Bron")
self.assertEqual(self.h.title, "Dragonslayer")
self.assertEqual(self.h.health, 100)
self.assertEqual(self.h.mana, 100)
self.assertEqual(self.h.mana_regeneration_rate, 2)
self.assertEqual(self.h.start_mana, 100)
self.assertEqual(self.h.damage, 0)
def test_known_as(self):
result = "Bron the Dragonslayer"
self.assertEqual(self.h.known_as(), result)
def test_is_alive(self):
self.assertTrue(self.h.is_alive() is True)
def test_take_damage(self):
damage = self.h.take_damage(40)
self.assertTrue(self.h.health is 60)
def test_can_cast(self):
self.assertTrue(self.h.can_cast() is True)
def test_take_healing(self):
self.h.take_damage(100)
self.new_health = self.h.take_healing(30)
self.assertTrue(self.h.health is 0)
def test_take_mana(self):
self.h.learn(self.s)
self.h.attack(by="spell")
self.h.take_mana(10)
self.assertEqual(self.h.mana, 60)
def test_attack(self):
self.h.equip(self.w)
self.assertEqual(self.h.attack(by="weapon"), 20)
self.h.learn(self.s)
self.assertEqual(self.h.attack(by="spell"), 30)
def test_exception(self):
self.h.learn(self.s)
self.assertEqual(self.h.attack(by="spell"), 30)
with self.assertRaises(NotEnaughMana):
self.s.mana_cost = 50
self.h.attack(by="spell")
示例3: HeroTest
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [as 别名]
class HeroTest(unittest.TestCase):
def setUp(self):
self.hero = Hero("Arthas", 1000, "Lich King")
self.hero.weapon = Weapon("Frostmourne", 35, 0.7)
def test_init(self):
self.assertEqual(self.hero.name, "Arthas")
self.assertEqual(self.hero.health, 1000)
self.assertEqual(self.hero.nickname, "Lich King")
def test_known_as(self):
self.assertEqual(self.hero.known_as(), "Arthas the Lich King")
def test_has_weapon_when_present(self):
self.assertEqual(self.hero.has_weapon(), True)
def test_has_weapon_when_not_present(self):
self.hero.weapon = None
self.assertEqual(self.hero.has_weapon(), False)
def test_equip_stronger_weapon(self):
test_weapon = Weapon("Stick", 500, 0.1)
self.hero.equip_weapon(test_weapon)
self.assertEqual(self.hero.weapon, test_weapon)
def test_equip_weaker_weapon(self):
test_weapon = Weapon("Stick", 5, 0.1)
self.hero.equip_weapon(test_weapon)
self.assertNotEqual(self.hero.weapon, test_weapon)
def test_attack_when_no_weapon_is_equipped(self):
self.hero.weapon = None
self.assertEqual(self.hero.attack(), 0)
def test_attack_when_weapon_is_equipped(self):
self.assertIn(self.hero.attack(), [35, 70])
示例4: Test
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [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)
示例5: TestHero
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [as 别名]
class TestHero(unittest.TestCase):
def setUp(self):
self.hero = Hero("Martin", "Manqk", 200, 300, 3)
def test_hero_init_(self):
self.assertEqual(self.hero.health, 200)
self.assertEqual(self.hero.mana, 300)
self.assertEqual(self.hero.damage, 0)
self.assertEqual(self.hero.name, "Martin")
self.assertEqual(self.hero.title, "Manqk")
self.assertEqual(self.hero.mana_regen, 3)
def test_hero_known_as(self):
self.assertEqual(self.hero.known_as(), "Martin the Manqk")
def test_hero_equip(self):
w = Weapon('noj', 20)
self.hero.equip(w)
self.assertEqual(self.hero.damage, self.hero.phisical_damage + w.damage)
self.assertEqual(self.hero.max_equiped_weapons, 1)
self.assertFalse(self.hero.equip(w))
def test_hero_learn(self):
s = Spell("BatkaAttack", 30, 50, 2)
self.hero.learn(s)
self.assertEqual(self.hero.magic_damage, s.damage)
self.assertEqual(self.hero.max_learned_spells, 1)
self.assertFalse(self.hero.learn(s))
def test_hero_attack(self):
w = Weapon('noj', 20)
self.hero.equip(w)
self.hero.attack(by='weapon')
self.assertTrue(self.hero.can_attack())
self.assertEqual(self.hero.damage, self.hero.phisical_damage + self.hero.damage)
s = Spell("BatkaAttack", 30, 50, 2)
self.hero.learn(s)
self.hero.attack(by='magic')
self.assertEqual(self.hero.damage, self.hero.magic_damage)
self.hero.attack(by='RKO')
self.assertRaises(Exception)
示例6: HeroTests
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [as 别名]
class HeroTests(unittest.TestCase):
def setUp(self):
self.h = Hero("Blah", 100, "the Blah")
def test_hero_name(self):
self.assertEqual(self.h.name, "Blah")
def test_known_as(self):
self.assertEqual("Blah the Blah", self.h.known_as())
def test_get_health(self):
self.assertEqual(100, self.h.get_health())
def test_is_alive_full_health(self):
self.assertEqual(True, self.h.is_alive())
def test_take_healing(self):
self.h.take_damage(50)
self.assertEqual(True, self.h.take_healing(30))
self.assertEqual(80, self.h.get_health())
def test_take_more_healing_than_needed(self):
self.h.take_damage(50)
self.assertEqual(50, self.h.get_health())
self.assertEqual(False, self.h.take_healing(70))
self.assertEqual(100, self.h.get_health())
def test_damage_hero(self):
self.assertEqual(True, self.h.take_damage(50))
self.assertEqual(50, self.h.get_health())
def test_damage_hero_with_more_points_than_he_has_in_health(self):
self.assertEqual(False, self.h.take_damage(200))
self.assertEqual(0, self.h.get_health())
self.assertEqual(False, self.h.is_alive())
def test_healing(self):
self.h.take_damage(50)
self.assertEqual(50, self.h.get_health())
self.assertEqual(True, self.h.take_healing(50))
self.assertEqual(100, self.h.get_health())
def test_healing_with_more_points_than_are_needed(self):
self.h.take_damage(50)
self.assertEqual(50, self.h.get_health())
self.assertEqual(False, self.h.take_healing(150))
self.assertEqual(100, self.h.get_health())
def test_heal_dead_hero(self):
self.h.take_damage(100)
self.assertEqual(False, self.h.is_alive())
self.assertEqual(False, self.h.take_healing(30))
self.assertEqual(0, self.h.get_health())
def test_equip_weapon(self):
w = Weapon("sword", 50, 0.7)
self.assertEqual(True, self.h.equip_weapon(w))
self.assertEqual(w, self.h.weapon)
def test_attack(self):
self.assertEqual(10, self.h.attack())
w = Weapon("sword", 50, 0)
self.assertEqual(True, self.h.equip_weapon(w))
self.assertEqual(50, self.h.attack())
def test_fail_equipment(self):
self.assertEqual(False, self.h.equip_weapon("not a weapon"))
def test_equipment(self):
w = Weapon("grandma's cake", 99, 0.5)
self.h.equip_weapon(w)
self.assertEqual(w.type, self.h.weapon.type)
w_second = Weapon("grandpa's tong", 100, 1.0)
self.h.equip_weapon(w_second)
self.assertEqual(w_second.type, self.h.weapon.type)
示例7: HeroTest
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [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):
#.........这里部分代码省略.........
示例8: TestHero
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [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)
示例9: HeroTest
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [as 别名]
class HeroTest(unittest.TestCase):
def setUp(self):
self.hero = Hero(name="Bron",
title="Dragonslayer",
health=100, mana=100,
mana_regeneration_rate=2)
self.weapon = Weapon(name="The Axe of Destiny", damage=20)
self.spell = Spell(name="Fireball",
damage=30,
mana_cost=50,
cast_range=2)
def test_exists_class(self):
self.assertTrue(isinstance(self.hero, Hero))
def test_hero_known_as(self):
self.assertTrue(self.hero.known_as(), "Bron the DragonSlayer")
def test_hero_is_alive(self):
self.assertTrue(self.hero.is_alive(), True)
def test_is_hero_not_alive(self):
self.hero.reduce_health(100)
self.assertFalse(self.hero.is_alive())
def test_hero_can_cast(self):
self.assertTrue(self.hero.can_cast(), True)
def test_hero_can_cast_false(self):
self.hero.reduce_mana(100)
self.assertFalse(self.hero.can_cast())
def test_mana_regeneration_rate(self):
self.assertEqual(self.hero.mana_regeneration_rate(), 2)
def test_hero_take_damage(self):
damage_points = 20
self.hero.take_damage(damage_points)
self.assertEqual(self.hero.get_health(), 80)
def test_hero_take_healing(self):
healing_points = 20
damage_points = 90
self.hero.take_damage(damage_points)
self.hero.take_healing(healing_points)
self.assertTrue(self.hero.get_health(), 30)
def test_hero_take_mana(self):
damage_points = 50
mana_points = 40
new_mana_points = 20
self.hero.take_damage(damage_points)
self.hero.reduce_mana(mana_points)
self.assertTrue(self.hero.take_mana(new_mana_points), 80)
def test_hero_weapon(self):
weapon_equipment = []
weapon_equipment.append(self.weapon)
self.assertEqual(weapon_equipment[0], self.weapon)
def test_hero_can_equip_with_weapon(self):
self.hero.equip(self.weapon)
self.assertEqual(str(self.hero.weapon_equipment[0]),
self.weapon.get_name())
def test_hero_spell(self):
learned_spell = []
learned_spell.append(self.spell)
self.assertEqual(learned_spell[0], self.spell)
def test_hero_can_learn_new_spell(self):
self.hero.learn(self.spell)
self.assertEqual(str(self.hero.learned_spell[0]),
self.spell.get_name())
def test_hero_attack_with_spell(self):
self.hero.learn(self.spell)
self.assertEqual(self.hero.attack(by="spell"),
self.spell.get_damage())
def test_hero_attack_with_weapon(self):
self.hero.equip(self.weapon)
self.assertEqual(self.hero.attack(by="weapon"),
self.weapon.get_damage())
示例10: HeroTests
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [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)
#.........这里部分代码省略.........
示例11: EntityTest
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [as 别名]
class EntityTest(unittest.TestCase):
def setUp(self):
self.shosh_hero = Hero('Shosh', 100, 'GraveRobber')
self.zaithan_orc = Orc('Zaithan', 150, 0.5)
self.destroyer_weapon = Weapon('Destroyer Axe', 30, 0.7)
self.crystal_weapon = Weapon('Crystal Dagger', 15, 0.2)
self.molten_weapon = Weapon('Molten Sword', 27, 0.4)
def test_init(self):
self.assertEqual(self.shosh_hero.name, 'Shosh')
self.assertEqual(self.shosh_hero.health, 100)
self.assertEqual(self.shosh_hero.nickname, 'GraveRobber')
def test_get_health(self):
self.assertEqual(self.shosh_hero.get_health(), 100)
def test_is_alive(self):
self.assertTrue(self.shosh_hero.is_alive())
def test_is_dead(self):
self.shosh_hero.health = 0
self.assertFalse(self.shosh_hero.is_alive())
def test_take_damage_integer_value(self):
self.shosh_hero.take_damage(25)
self.assertEqual(self.shosh_hero.get_health(), 75)
def test_take_damage_decimal_value(self):
self.shosh_hero.take_damage(0.5)
self.assertEqual(self.shosh_hero.get_health(), 99.5)
def test_take_huge_amount_of_damage(self):
self.shosh_hero.take_damage(150)
self.assertEqual(self.shosh_hero.get_health(), 0)
def test_take_huge_amount_of_damage_decimal(self):
self.shosh_hero.take_damage(120.5)
self.assertEqual(self.shosh_hero.get_health(), 0)
def test_take_healing_when_dead(self):
self.shosh_hero.health = 0
self.assertFalse(self.shosh_hero.take_healing(30))
def test_take_hiper_super_big_healing(self):
self.shosh_hero.health = 70
self.assertTrue(self.shosh_hero.take_healing(200))
self.assertEqual(self.shosh_hero.health, self.shosh_hero.get_health())
def test_take_healing(self):
self.shosh_hero.health = 20
self.assertTrue(self.shosh_hero.take_healing(50))
self.assertEqual(self.shosh_hero.health, 70)
def test_has_weapon(self):
self.zaithan_orc.weapon = None
self.shosh_hero.weapon = self.crystal_weapon
self.assertTrue(self.shosh_hero.has_weapon())
self.assertFalse(self.zaithan_orc.has_weapon())
def test_equip_weapon(self):
self.shosh_hero.equip_weapon(self.destroyer_weapon)
self.assertTrue(self.shosh_hero.has_weapon())
self.assertEqual(self.shosh_hero.weapon.type, 'Destroyer Axe')
def test_equip_weapon_and_discard_the_old_one(self):
self.assertFalse(self.zaithan_orc.has_weapon())
self.zaithan_orc.equip_weapon(self.crystal_weapon)
self.assertTrue(self.zaithan_orc.has_weapon())
self.assertEqual(self.zaithan_orc.weapon.type, 'Crystal Dagger')
self.zaithan_orc.equip_weapon(self.molten_weapon)
self.assertTrue(self.zaithan_orc.has_weapon())
self.assertNotEqual(self.zaithan_orc.weapon.type, 'Crystal Dagger')
self.assertEqual(self.zaithan_orc.weapon.type, 'Molten Sword')
def test_attack_without_weapon(self):
self.assertEqual(self.shosh_hero.attack(), 0)
def test_attack_with_weapon(self):
self.shosh_hero.equip_weapon(self.destroyer_weapon)
self.assertIn(self.shosh_hero.attack(), [30, 60])
示例12: Game
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import attack [as 别名]
class Game(object):
def __init__(self, canvas):
self.canvas = canvas
self.hero = Hero()
self.map = Map(self.hero, self.canvas)
self.font_status = font.Font(size=11)
self.font_game_over = font.Font(size=25)
def is_hero_dead(self):
return self.hero.current_hp <= 0
def is_monster_dead(self, monster):
return monster.hp <= 0
def is_boss_dead(self, monster):
if monster.position == self.map.boss_position()[0].position:
return self.is_monster_dead(monster)
def combat(self):
if self.is_hero_dead():
self.canvas.delete('all')
self.draw_end_screen()
monster = self.map.get_monster()[0]
self.hero.attack(monster)
if self.is_boss_dead(monster):
self.hero.level_up()
self.new_level_buff()
self.map.generate_level()
self.hero.position = {'x': 0, 'y': 0}
self.draw_map()
if type(monster) == Skeleton:
self.map.map_texture.remove(monster)
self.hero.level_up()
def random_chance(self):
return random.randrange(0, 100)
def new_level_buff(self):
if self.random_chance() >= 90:
self.hero.current_hp = self.hero.hp
elif self.random_chance() >= 60:
self.hero.current_hp += self.hero.current_hp // 3
if self.hero.current_hp > self.hero.hp:
self.hero.current_hp = self.hero.hp
else:
self.hero.current_hp += self.hero.current_hp // 10
if self.hero.current_hp > self.hero.hp:
self.hero.current_hp = self.hero.hp
def move_route(self, key):
# if self.hero.move_count == 2:
# print("move")
# self.map.move_monsters()
# self.draw_map()
# self.hero.move_count = 0
pressed_key = key.keysym
if pressed_key == 'Up':
self.hero.move_up()
if not self.map.is_valid_move():
self.hero.move_down()
elif pressed_key == 'Down':
self.hero.move_down()
if not self.map.is_valid_move():
self.hero.move_up()
elif pressed_key == 'Right':
self.hero.move_right()
if not self.map.is_valid_move():
self.hero.move_left()
elif pressed_key == 'Left':
self.hero.move_left()
if not self.map.is_valid_move():
self.hero.move_right()
elif pressed_key == 'space':
if self.map.is_valid_move():
self.combat()
def draw_map(self):
if self.is_hero_dead():
self.draw_end_screen()
for i in self.map.map_texture:
i.draw()
self.draw_hero(self.hero.position['x'], self.hero.position['y'])
self.draw_hero_status_bar()
if self.map.is_valid_attack():
self.draw_monster_status_bar(self.map.get_monster()[0])
def draw_hero(self, x, y):
self.canvas.create_image(x * 72, y * 72, image=self.hero.current_img, anchor=NW)
def draw_hero_status_bar(self):
self.canvas.delete("status")
self.canvas.create_text(5, 722, text=self.hero, justify=CENTER, tags="status", anchor=NW, font=self.font_status)
def draw_monster_status_bar(self, monster):
self.canvas.create_text(400, 722, text=monster, tags="status", anchor=NW, font=self.font_status, fill="red")
def draw_end_screen(self):
self.canvas.delete('all')
self.canvas.create_text(300, 350, text="You died", anchor=NW, font=self.font_game_over, fill="red")