本文整理汇总了Python中hero.Hero.decrease_army方法的典型用法代码示例。如果您正苦于以下问题:Python Hero.decrease_army方法的具体用法?Python Hero.decrease_army怎么用?Python Hero.decrease_army使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hero.Hero
的用法示例。
在下文中一共展示了Hero.decrease_army方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import decrease_army [as 别名]
class Player:
def __init__(self, name, race):
self.race = race
self.town = Town(race)
self.gold = 1000
self.hero = None
self.name = name
def hire_hero(self, name):
self.hero = Hero(name)
def upgrade_building(self, building):
""" Accepts the building you want to upgrade """
if building.price > self.gold:
raise NoGold
if not building.upgrade_available():
raise BuildingAtMaxLevel
self.gold -= building.price
building.upgrade()
def move_army_from_town_to_hero(self, unit_type, unit_count):
if self.hero.is_in_town == False:
raise HeroNotInTown
if self.hero == None:
raise NoHero
if self.town.army[unit_type] < unit_count:
raise NoUnits
self.town.decrease_army(unit_type, unit_count)
self.hero.increase_army(unit_type, unit_count)
def move_army_from_hero_to_town(self, unit_type, unit_count):
if self.hero == None:
raise NoHero
if self.hero.is_in_town == False:
raise HeroNotInTown
if self.hero.army[unit_type] < unit_count:
raise NoUnits
self.hero.decrease_army(unit_type, unit_count)
self.town.increase_army(unit_type, unit_count)
def train_army(self, unit_type, unit_count):
if self.town.castle.units_available_to_train < unit_count:
raise NoDailyUnits
if ALL_RACE_UNITS[self.race][self.town.barracs.\
army[unit_type]].price * unit_count > self.gold:
raise NoGold
self.town.army[unit_type] += unit_count
self.gold -= ALL_RACE_UNITS[self.race][self.town.\
barracs.army[unit_type]].price * unit_count
示例2: TestHero
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import decrease_army [as 别名]
class TestHero(unittest.TestCase):
def setUp(self):
self.hero = Hero('San')
def test_hero_constructor(self):
self.assertEqual(self.hero.name, 'San')
self.assertEqual(self.hero.level, 1)
def test_level_up(self):
self.hero.experience = 245
self.hero.check_for_level_up()
self.assertEqual(self.hero.level, 2)
self.assertEqual(self.hero.experience, 45)
self.assertEqual(self.hero.experience_to_level_up, 300)
def test_town_conditions(self):
self.assertTrue(self.hero.is_in_town)
self.hero.leave_town()
self.assertFalse(self.hero.is_in_town)
self.hero.arrive_at_town()
def test_increase_decrease_army(self):
self.hero.increase_army(1, 20)
self.assertEqual(self.hero.army, [0, 20, 0, 0])
self.hero.decrease_army(1, 10)
self.assertEqual(self.hero.army, [0, 10, 0, 0])
self.assertRaises(NoUnits, self.hero.decrease_army, 1, 40)
self.hero.increase_army(3, 100)
self.assertEqual(self.hero.army, [0, 10, 0, 100])
def test_upgrade_bonus(self):
self.hero.upgrade_bonus('health')
self.assertEqual(self.hero.bonuses['health'], 1)
self.assertEqual(self.hero.bonuses['damage'], 0)
self.hero.talent_points = 0
self.assertRaises(NoTalentPoints, self.hero.upgrade_bonus, 'damage')
def test_gain_experience(self):
self.hero.gain_experience(300)
self.assertEqual(self.hero.level, 2)
self.assertEqual(self.hero.experience, 100)
self.assertEqual(self.hero.experience_to_level_up, 300)