当前位置: 首页>>代码示例>>Python>>正文


Python hero.Hero类代码示例

本文整理汇总了Python中hero.Hero的典型用法代码示例。如果您正苦于以下问题:Python Hero类的具体用法?Python Hero怎么用?Python Hero使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Hero类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

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
开发者ID:NikiMaslarski,项目名称:Dark-Wonderers,代码行数:60,代码来源:player.py

示例2: setUp

 def setUp(self):
     weapon = Weapon('Dagger', 10, 0.0)
     hero = Hero('Asd', 100, 'Hero')
     hero.equip_weapon(weapon)
     orc = Orc('Dsa', 1, 1.4)
     orc.equip_weapon(weapon)
     self.fight = fight.Fight(hero, orc)
开发者ID:smo93,项目名称:hackbulgaria,代码行数:7,代码来源:fight_test.py

示例3: TestFight

class TestFight(unittest.TestCase):

    def setUp(self):
        self.my_hero = Hero("Hero",  100, "Hero")
        self.my_orc = Orc("Orc", 100, 1.5)
        self.the_fight = Fight(self.my_hero, self.my_orc)

    def test_init(self):
        self.assertEqual(self.my_hero.name, "Hero")
        self.assertEqual(self.my_hero.health, 100)
        self.assertEqual(self.my_hero.nickname, "Hero")
        self.assertEqual(self.my_orc.name, "Orc")
        self.assertEqual(self.my_orc.health, 100)
        self.assertEqual(self.my_orc.berserk_factor, 1.5)

    def test_attacks_first(self):
        my_arr = []
        for i in range(0, 100):
            if self.the_fight.attacks_first() == True:
                my_arr.append(1)
            my_arr.append(0)
        self.assertIn(1, my_arr)
        self.assertIn(0, my_arr)

    def test_simulate_fight(self):
        proba1 = Weapon("axe", 1, 0.1)
        proba2 = Weapon("sword", 40, 0.9)
        self.my_hero.equip_weapon(proba1)
        self.my_orc.equip_weapon(proba2)
        the_fight = Fight(self.my_hero, self.my_orc)
        self.assertFalse(the_fight.simulate_fight())
开发者ID:skdls-,项目名称:Python,代码行数:31,代码来源:test_fight.py

示例4: FightTest

class FightTest(unittest.TestCase):

    def setUp(self):
        self.bron_hero = Hero("Bron", 100, "DragonSlayer")
        self.torug_orc = Orc("Torug", 100, 1.2)
        self.new_fight = Fight(self.bron_hero, self.torug_orc)
        self.axe = Weapon("Axe", 20, 0.2)
        self.sword = Weapon("Sword", 12, 0.7)
        self.bron_hero.equip_weapon(self.sword)
        self.torug_orc.equip_weapon(self.axe)

    def test_init(self):
        self.assertEqual(self.new_fight.orc, self.torug_orc)
        self.assertEqual(self.new_fight.hero, self.bron_hero)

    def test_who_is_first(self):
        first_entity = self.new_fight.who_is_first()
        self.assertIn(first_entity, [self.bron_hero, self.torug_orc])

    def test_fight(self):
        self.new_fight.simulate_battle()
        self.assertFalse(self.torug_orc.is_alive() and self.bron_hero.is_alive())

    def test_fight_with_no_weapons(self):
        self.torug_orc.weapon = None
        self.new_fight.simulate_battle()
        self.assertFalse(self.torug_orc.is_alive())
开发者ID:ivaylospasov,项目名称:programming-101,代码行数:27,代码来源:fight_test.py

示例5: test_simulate_fight_hero_win

 def test_simulate_fight_hero_win(self):
     orc_l = Orc("Loser", 300, 2)
     hero_w = Hero("Winner", 300, "TheWinner")
     wep = Weapon("Ubiec", 15, 0.5)
     hero_w.equip_weapon(wep)
     hero_fight = Fight(hero_w, orc_l)
     self.assertEqual(hero_fight.simulate_fight(), hero_fight._HERO_WINNER)
开发者ID:SlaviSotirov,项目名称:HackBulgaria,代码行数:7,代码来源:fight_test.py

示例6: TestHero

class TestHero(unittest.TestCase):
    def test_hero_known_as_not_Jenkins(self):
        self.bron_hero = Hero("Bron", 100, "Dragon Slayer")
        self.assertEqual(self.bron_hero.known_as(), "Bron the Dragon Slayer")

    def test_hero_known_as_Jenkins(self):
        self.leeroy = Hero("Leeroy", 100, "Jenkins")
        self.assertEqual(self.leeroy.known_as(), "Leeroy Jenkins")
开发者ID:kazuohirai,项目名称:HackBulgaria,代码行数:8,代码来源:hero_test.py

示例7: test_fight1

 def test_fight1(self):
     new_hero = Hero("Jack", 100, "Ripper")
     new_orc = Orc("Gruumsh", 40, 1.2)
     hero_weapon = Weapon("The Sting", 8, 0.33)
     orc_weapon = Weapon("The Pacifier", 12, 1)
     new_hero.equip_weapon(hero_weapon)
     new_orc.equip_weapon(orc_weapon)
     Fight(new_hero, new_orc)
开发者ID:didoman,项目名称:prog101tasks,代码行数:8,代码来源:dnp_tests.py

示例8: test_fight_with_one_weapon

 def test_fight_with_one_weapon(self):
     hero = Hero("Bron", 15, "DragonSlayer")
     evil_orc = Orc('karakondjul', 10 , 1.5)
     weapon1 = Weapon("Axe", 5, 0.5)
     hero.equip_weapon(weapon1)
     fight = Fighting(hero,evil_orc)
     winner = fight.simulate_fight()
     self.assertTrue(isinstance(winner,Hero) or isinstance(winner,Orc))
开发者ID:dsspasov,项目名称:HackBulgaria,代码行数:8,代码来源:fighting_test.py

示例9: test_fight_equal

 def test_fight_equal(self):
     hero_one = Hero("Bron", 100, "DragonSlayer")
     orc_one = Orc("Orcy", 150, 1.5)
     hero_one.weapon = Weapon("Axe", 20, 0.5)
     orc_one.weapon = Weapon("Axe", 20, 0.5)
     self.fight_one.simulate_battle()
     # both has the same weapon, but the orc has berserc_factor,\
     # he should be alive at the end
     self.assertTrue(self.orc_one.is_alive())
开发者ID:GalinaDimitrova,项目名称:Hack,代码行数:9,代码来源:fight_test.py

示例10: TestDungeon

class TestDungeon(unittest.TestCase):

    def setUp(self):

        self.without_weapon = Weapon("With bare hands", 0, 0)
        self.thanes_hummer = Weapon("Thanes hummer", 15, 0.4)
        self.yurnero_blade = Weapon("Yurneros blade", 10, 0.35)
        self.the_hero = Hero("Thanes", 150, 150, "Mountain King")
        self.the_orc = Orc("Yurnero the Blademaster", 150, 150, 1.3)
        self.the_chen = Orc("Chen", 150, 150, 1.3)
        self.small_potion = Potion("Small potion", 15)
        self.midium_potion = Potion("Midium potion", 25)
        self.the_hero.equip_weapon(self.thanes_hummer)
        self.the_orc.equip_weapon(self.yurnero_blade)
        self.map = Dungeon("map.txt")
        self.map.read_map()
        self.map.dict_of_items[self.yurnero_blade] = []
        self.map.dict_of_items[self.thanes_hummer] = []
        self.map.dict_of_items[self.small_potion] = []
        self.map.dict_of_items[self.midium_potion] = []
        self.map.dict_of_herous[self.the_orc] = []
        self.map.dict_of_herous[self.the_hero] = []
        self.map.spawn_player("shosho", self.the_hero)
        #self.map.spawn_player("kosho", self.the_orc)
        #self.map.dict_champion_name[self.the_hero] = "shosho"
        self.map.dict_champion_name[self.the_orc] = "kosho"



    #def test_validate_player(self):
    #    self.assertEqual(self.the_hero, self.map.validate_player_name("hero"))
    def test_spawn_player(self):
        #self.assertFalse(self.map.spawn_player("shosho", self.the_hero))
        self.assertTrue(self.map.spawn_player("kosho", self.the_orc))
        self.assertFalse(self.map.spawn_player("kosho", self.the_chen))

    def test_can_move(self):
        #print("{}\n{}".format(self.map.number_of_rows, self.map.number_of_chars))
        #print((self.map.number_of_rows))
        self.current_user = self.the_orc
        self.map.print_map()

        self.assertFalse(self.map.can_move_up(-1, 0))
        self.assertFalse(self.map.can_move_down(1, 0))
        self.assertTrue(self.map.can_move_right(0, 1))
        self.map.validate_player_name("orc")
        print("{}     {}".format(self.map.current_x, self.map.current_y))
        self.assertFalse(self.map.can_move_up(-1, 0))
        self.assertFalse(self.map.can_move_down(1, 0))
        self.assertTrue(self.map.can_move_right(0, 1))
        self.assertFalse(self.map.can_move_left(0, -1))

    def test_validate_player_name(self):

        self.map.spawn_player("kosho", self.the_orc)
        self.assertEqual(self.map.validate_player_name("kosho"), self.the_orc)
        self.map.print_map()
开发者ID:VictorVangelov,项目名称:HackBulgaria,代码行数:57,代码来源:test_dungeon.py

示例11: __init__

   def __init__(self):
      #super is a builtin python function that represents the parent class of
      #this object (parent class = Creature here). This makes a monster inside  
      #the parent class of creature, with all the properties of creature. 

      Monster.__init__(self)
      Hero.__init__(self)
      
      self.weapon2 = None
开发者ID:Pjmcnally,项目名称:teaching,代码行数:9,代码来源:monsterhero.py

示例12: WeaphonTest

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())
开发者ID:golfdman,项目名称:HackBulgaria,代码行数:57,代码来源:test_hero.py

示例13: test_print_map_after_battle

    def test_print_map_after_battle(self):
        hero = Hero("Alan", 1, "Turing")
        hero.weapon = Weapon("Stick", 1, 0.1)
        self.dungeon.map = "ZSNZ"
        self.dungeon.spawn("1", hero)
        self.dungeon.spawn_npcs()

        self.dungeon.move_player("1", "right")
        self.assertEqual(self.dungeon.map, "Z.OZ")
开发者ID:sslavov93,项目名称:TreasureDungeon,代码行数:9,代码来源:test_all.py

示例14: test_orc_wins

 def test_orc_wins(self):
     hero = Hero("Bron", 50, "DragonSlayer")
     evil_orc = Orc('karakondjul', 100 , 1.5)
     weapon1 = Weapon("Axe", 1, 0.5)
     weapon2 = Weapon("Sword", 34, 0.5)
     hero.equip_weapon(weapon1)
     evil_orc.equip_weapon(weapon2)
     fight = Fighting(hero,evil_orc)
     winner = fight.simulate_fight()
     self.assertTrue(isinstance(winner,Orc))
开发者ID:dsspasov,项目名称:HackBulgaria,代码行数:10,代码来源:fighting_test.py

示例15: test_fight

 def test_fight(self):
     my_Hero = Hero("Ivan", 100, "bad ass")
     my_Orc = Orc("Boko", 100, 1.5)
     my_weapon1 = Weapon("Axe1", 31, 0.2)
     my_weapon2 = Weapon("Axe2", 31, 0.2)
     my_Hero.equip_weapon(my_weapon1)
     my_Orc.equip_weapon(my_weapon2)
     fight1 = Fight(my_Hero, my_Orc)
     fight1.simulate_fight()
     self.assertFalse(my_Orc.is_alive() and my_Hero.is_alive())
开发者ID:Hristiyan-Andreev,项目名称:HackBuglaria,代码行数:10,代码来源:fightingTest.py


注:本文中的hero.Hero类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。