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


Python fight.Fight类代码示例

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


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

示例1: hero_attack

    def hero_attack(self, by=""):
        if by == 'weapon' and self.hero.weapon is None:
            raise Exception("Hero cannot attack by weapon")

        if by == 'spell' and self.hero.spell is None:
            raise Exception("Hero cannot attack by spell")

        if by == 'spell' and self.hero.spell is not None:
            for i in range(self.__coords[1]+1, self.__coords[1]+1+self.hero.spell.cast_range**2):
                try:
                    print(self.map[self.__coords[0]][i], self.__coords[1], self.__coords[1]+1+self.hero.spell.cast_range**2)
                    if self.map[self.__coords[0]][i] == Dungeon.WALKABLE_PATH:
                        continue

                    elif self.map[self.__coords[0]][i] == Dungeon.ENEMY:
                        print("A fight is started between our {} and {}".format(repr(self.hero), repr(self.enemy)))
                        f = Fight(self.hero, self.enemy)
                        f.fight(self.hero.weapon_to_fight())
                        break
                    print("Nothing in casting range {}".format(self.hero.spell.cast_range))
                    return False
                except IndexError:
                    break

        if by == 'weapon' and self.hero.weapon is not None:
            print("A fight is started between our {} and {}".format(repr(self.hero), repr(self.enemy)))
            Fight(self.hero, self.enemy).fight(self.hero.weapon_to_fight())
            return True
开发者ID:animilh,项目名称:Dungeons-and-Pythons,代码行数:28,代码来源:dungeon.py

示例2: FightTest

class FightTest(unittest.TestCase):

    def setUp(self):
        self.hero = Hero("Arthas", 660, "Lich King")
        self.orc = Orc("Thrall", 700, 1.7)
        self.heroWeapon = Weapon("Frostmourne", 35, 0.7)
        self.orcWeapon = Weapon("Doomhammer", 40, 0.6)
        self.hero.weapon = self.heroWeapon
        self.orc.weapon = self.orcWeapon
        self.fight = Fight(self.hero, self.orc)

    def test_init(self):
        self.assertEqual(self.fight.hero, self.hero)
        self.assertEqual(self.fight.orc, self.orc)

    def test_coin_toss_for_first_attacker(self):
        self.assertIn(self.fight.coin_toss(),
                      [(self.orc, self.hero), (self.hero, self.orc)])

    def test_simulate_fight_with_no_weapons(self):
        self.fight.hero.weapon = None
        self.fight.orc.weapon = None
        result = self.fight.simulate_fight()
        self.assertEqual(result, "No winner")

    def test_simulate_fight_with_only_one_weapon(self):
        self.fight.hero.weapon = None
        result = self.fight.simulate_fight()
        self.assertEqual(result, self.fight.orc)

    def test_simulate_fight_with_both_armed_chars(self):
        result = self.fight.simulate_fight()
        self.assertIn(result, [self.fight.orc, self.hero])
开发者ID:sslavov93,项目名称:TreasureDungeon,代码行数:33,代码来源:test_all.py

示例3: TestFightingSkills

class TestFightingSkills(unittest.TestCase):
    def setUp(self):
        self.orc = Orc("Gerasim", 100, 1.7)
        self.hero = Hero("Spiridon", 100, "Lich King")
        self.bitka = Fight(self.orc, self.hero)
        self.orc.weapon = Weapon("Wirt's Leg", 30, 0.9)
        self.hero.weapon = Weapon("WarGlaive", 30, 0.5)

    def test_init_fighters(self):
        self.assertEqual(self.orc.name, "Gerasim")
        self.assertEqual(self.orc.health, 100)
        self.assertEqual(self.orc.berserk_factor, 1.7)
        self.assertEqual(self.hero.name, "Spiridon")
        self.assertEqual(self.hero.health, 100)
        self.assertEqual(self.hero.nickname, "Lich King")

    def test_simulate_fight(self):
        result = self.bitka.simulate_fight()
        self.assertIn(result, [self.orc, self.hero])

    def test_simulate_fight_with_no_weapon(self):
        self.orc.weapon = None
        result = self.bitka.simulate_fight()
        self.assertEqual(self.hero, result)

    def test_simulate_fight_with_unarmed_characters(self):
        self.orc.weapon = None
        self.hero.weapon = None
        result = self.bitka.simulate_fight()
        self.assertEqual(result, "No winner")
开发者ID:kazuohirai,项目名称:HackBulgaria,代码行数:30,代码来源:fight_test.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: FightTest

class FightTest(unittest.TestCase):

    def setUp(self):
        self.orc = Orc("PeshoOrc", 100, 1.2)
        self.hero = Hero("PeshoHero", 100, "peshooo")
        self.weapon1 = Weapon("axe", 50, 0.5)
        self.weapon2 = Weapon("axe2", 70, 0.3)
        self.fighting = Fight(self.hero, self.orc)
        self.orc.weapon = self.weapon1

    def test_init(self):
        self.assertEqual(self.fighting.Orc,self.orc)
        self.assertEqual(self.fighting.Hero,self.hero)

    def test_coin(self):
        arr = []
        flag = [False, False]
        for i in range(1, 100):
            arr.append(self.fighting.coin())

        for i in arr:
            if i:
                flag[0] = True
            else:
                flag[1] = True
        self.assertEqual(flag, [True, True])

    def test_simulate_fight(self):
        self.assertEqual("PeshoOrc", self.fighting.simulate_fight())
开发者ID:kal0ian,项目名称:HackBulgaria,代码行数:29,代码来源:fight-test.py

示例6: test_simulate_fight

 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,代码行数:7,代码来源:test_fight.py

示例7: battle

    def battle(self, name, dest, otpt, chr_loc):
        """Invoked when an Entity's destination map block
        is occupied by the opposite entity type

        Args:
            name - Name of the Entity that walks over. Type(String)
            dest - Coordinates of move direction. Type(Tuple)
            otpt - Converted map. Type(List of Lists of Strings)
            chr_loc - Current coordinates of entity. Type(Tuple)"""
        to_fight = None
        for each in self.ingame:
            if self.ingame[each].location == dest:
                to_fight = self.ingame[each]

        battle = Fight(self.ingame[name], to_fight)
        battle_result = battle.simulate_fight()
        otpt[chr_loc[0]][chr_loc[1]] = "."
        otpt[dest[0]][dest[1]] = self.get_entity_indicator(battle_result)
        if self.ingame[name] == battle_result:
            self.ingame[name].location = dest
        else:
            self.map = self.map.replace("H", ".")
        for item in self.ingame:
            if self.ingame[item] == battle_result:
                self.map = self.revert_map_to_string_state(otpt)
                return "{} wins!".format(item)
开发者ID:sslavov93,项目名称:TreasureDungeon,代码行数:26,代码来源:dungeon.py

示例8: move

    def move(self, player_name, direction):
        # If wrong direction is given, do nothing
        directions = ["left", "right", "up", "down"]
        if direction not in directions:
            return "Wrong direction given."

        # Read map from file
        output = ""
        f = open(self.filepath, "r+")
        output += f.read()
        f.close()

        # converts output to list of lists of single-character strings (easier to work with)
        getGPS = output = [list(x) for x in output.split("\n")]
        # current coordinates
        location = self.get_coordinates(getGPS, player_name)
        # destination coordinates
        destination = self.modify_indexes(self.get_coordinates(getGPS, player_name), direction)

        # if coordinate tuple exceeds the map boundaries - terminate
        if destination[0] < 0 or destination[1] < 0 or destination[0] > len(output) or destination[1] > len(output[0]):
            return "Out of Bounds."

        # What is the ASCI character in the given map location
        target = output[destination[0]][destination[1]]
        # Gets indicator of player who wants to execute a move on the board
        indicator = self.get_player_indicator(self.spawnlist[player_name])
        # enemy is opposite indicator
        enemy = "OH".replace(indicator, "")
        if target == "#":
            return "You will hit the wall."
        elif target == ".":
            # swap the "." and current moving player indicator in map
            output[location[0]][location[1]], output[destination[0]][destination[1]] = (
                output[destination[0]][destination[1]],
                output[location[0]][location[1]],
            )
        elif target == enemy:
            # tokill is opposite object of currently-moving player
            enemyElem = {i: self.spawnlist[i] for i in self.spawnlist if i != player_name}
            ToKill = self.get_value_from_single_element_dict(enemyElem)
            # creates fight and simulates it, leaving only winning player on map
            # if winner attacked, its indicator overwrites the fallen enemy's one
            # if winner was attacked, the fallen enemy one's is changed wiht "." on map
            bitka = Fight(self.spawnlist[player_name], ToKill)
            battle_result = bitka.simulate_fight()
            output[location[0]][location[1]] = "."
            output[destination[0]][destination[1]] = self.get_player_indicator(battle_result)
            for item in self.spawnlist:
                if self.spawnlist[item] == battle_result:
                    print("{} wins!".format(item))

        # saves information to the dungeon map text file
        f = open(self.filepath, "w+")
        for i in range(0, len(output)):
            if i != (len(output) - 1):
                f.write("".join(output[i]) + "\n")
            else:
                f.write("".join(output[i]))
        f.close()
开发者ID:kazuohirai,项目名称:HackBulgaria,代码行数:60,代码来源:dungeon.py

示例9: 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

示例10: test_simulate_fight_orc_win

 def test_simulate_fight_orc_win(self):
     orc_w = Orc("Winner", 300, 2)
     hero_l = Hero("Loser", 300, "TheLoser")
     wep = Weapon("Ubiec", 15, 0.5)
     orc_w.equip_weapon(wep)
     orc_fight = Fight(hero_l, orc_w)
     self.assertEqual(orc_fight.simulate_fight(), orc_fight._ORC_WINNER)
开发者ID:SlaviSotirov,项目名称:HackBulgaria,代码行数:7,代码来源:fight_test.py

示例11: move

 def move(self, player_name, direction):
     player = self.players[player_name]
     old_player_pos = list(player[1])
     is_move_correct, new_player_pos = self._check_move_possible(
         old_player_pos, direction)
     self.players[player_name][1] = new_player_pos
     if is_move_correct:
         old_row = old_player_pos[1]
         old_col = old_player_pos[0]
         self.map_grid[old_row][old_col] = '.'
         del self.occupied_cells[tuple(old_player_pos)]
         new_row = new_player_pos[1]
         new_col = new_player_pos[0]
         if self.map_grid[new_row][new_col] != '.':
             attacker = player[0]
             defender = self.occupied_cells[tuple(new_player_pos)]
             fight = Fight(attacker, defender)
             fight.simulate_fight()
             if not fight.attacker.is_alive():
                 self._update_map()
                 return True
         self.occupied_cells[tuple(new_player_pos)] = player[0]
         self.map_grid[new_row][new_col] = Dungeon._get_entity_symbol(
             player[0])
         self._update_map()
     return is_move_correct
开发者ID:stoyaneft,项目名称:HackBulgariaProgramming-101,代码行数:26,代码来源:dungeon.py

示例12: move

    def move(self, name, direction):
        self.map = [x for x in self.map]
        if direction == "right":
            step = 1
        elif direction == "left":
            step = - 1
        elif direction == "down":
            step = self._ROW_LENGTH
        elif direction == "up":
            step = - self._ROW_LENGTH

        for i in range(len(self.heroes)):
            if self.heroes[i][0] == name:
                if self.map[i + step] == '.':
                    self.map[i + step] = "H" if isinstance(self.heroes[i][1], Hero) else "O"
                    self.map[i] = '.'
                    self.heroes.insert(i + step, self.heroes[i])
                    self.heroes.pop(i)
                    self.map = "".join(self.map)
                    return True
                elif self.map[i + step] == "H" or self.map[i + step] == "O":
                    self.fight = Fight(self.heroes[i][1], self.heroes[i + step][1])
                    self.fight.simulate_fight()
                    if self.heroes[i][1].is_alive():
                        self.map[i + step] = "H" if isinstance(self.heroes[i][1], Hero) else "O"
                        self.map[i] = '.'
                        self.heroes.insert(i + step, self.heroes[i])
                        self.heroes.pop(i)
                    else:
                        self.map[i] = '.'
                        self.heroes.pop(i)
                    self.map = "".join(self.map)

                    return True

                elif self.map[i + step] == '\n':
                    if self.map[i + step + 1] == '.':
                        self.map[i + step + 1] = "H" if isinstance(self.heroes[i][1], Hero) else "O"
                        self.map[i] = '.'
                        self.heroes.insert(i + step + 1, self.heroes[i])
                        self.heroes.pop(i)
                        self.map = "".join(self.map)
                        return True
                    elif self.map[i + step + 1] == "H" or self.map[i + step + 1] == "O":
                        self.fight = Fight(self.heroes[i][1], self.heroes[i + step + 1][1])
                        self.fight.simulate_fight()
                        if self.heroes[i][1].is_alive():
                            self.map[i + step + 1] = "H" if isinstance(self.heroes[i][1], Hero) else "O"
                            self.map[i] = '.'
                            self.heroes.insert(i + step + 1, self.heroes[i])
                            self.heroes.pop(i)
                        else:
                            self.map[i] = '.'
                            self.heroes.pop(i)
                        self.map = "".join(self.map)
                        return True
        self.map = "".join(self.map)
        return False
开发者ID:svetlio2,项目名称:hackbg,代码行数:58,代码来源:Dungeon.py

示例13: start_fight

 def start_fight(self):
     arena = Fight(self.hero_player, self.orc_player)
     arena.simulate_fight(self.orc_player, self.hero_player)
     if not arena.simulate_fight(self.orc_player, self.hero_player):
         return False
     elif self.orc_player.is_alive() and not self.hero_player.is_alive():
         print(self.orc_player_name, "won!")
     elif self.hero_player.is_alive() and not self.orc_player.is_alive():
         print(self.hero_player_name, "won!")
开发者ID:emilenovv,项目名称:HackBulgaria,代码行数:9,代码来源:dungeon.py

示例14: setUp

 def setUp(self):
     self.hero = Hero('Stoyan', 200, 'DeathBringer')
     self.hero.equip_weapon(Weapon('Sword', 20, 0.5))
     self.orc = Orc('Beginner Orc', 100, 1.5)
     self.orc.equip_weapon(Weapon('Stick', 10, 0.1))
     self.legendary_orc = Orc('Broksiguar', 200, 2)
     self.legendary_orc.equip_weapon(Weapon('Frostmourne', 80, 0.9))
     self.fight_hero_vs_orc = Fight(self.hero, self.orc)
     self.fight_hero_vs_legendary_orc = Fight(self.hero, self.legendary_orc)
开发者ID:stoyaneft,项目名称:HackBulgariaProgramming-101,代码行数:9,代码来源:test_fight.py

示例15: duel_accept

 def duel_accept(self, other):
     if other["duel_invite"] == None or len([x for x in other["duel_invite"] if x[0] == self.id]) == 0:
         raise MyException(u"Игрок отменил свой вызов")
     if other["zone"] != self["zone"]:
         raise MyException(u"Игрок находится в другой локации")
     if other["loc"] != "default":
         raise MyException(u"Игрок пока не может начать дуэль")
     other["duel_invite"] = [di for di in other["duel_invite"] if di[0] != self.id]
     Fight.create([other], [self], _type="training")
开发者ID:alexbft,项目名称:Karty-RPG,代码行数:9,代码来源:myuser.py


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