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


Python Fight.simulate_fight方法代码示例

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


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

示例1: move

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
 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,代码行数:28,代码来源:dungeon.py

示例2: FightTest

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
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,代码行数:35,代码来源:test_all.py

示例3: TestFightingSkills

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
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,代码行数:32,代码来源:fight_test.py

示例4: start_fight

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
 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,代码行数:11,代码来源:dungeon.py

示例5: TestFight

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
class TestFight(unittest.TestCase):

    def setUp(self):
        self.orc = Orc("Berserk", 1000, 2)
        self.hero = Hero("Bron", 1000, "DragonSlayer")
        self.weapon = Weapon("Mighty Axe", 25, 0.3)
        self.orc.equip_weapon(self.weapon)
        self.hero.equip_weapon(self.weapon)
        self.fight = Fight(self.hero, self.orc)

    def test_simulate_fight(self):
        self.fight.simulate_fight()
        self.assertTrue(not self.orc.is_alive() or not self.hero.is_alive())
开发者ID:antonpetkoff,项目名称:Programming101,代码行数:15,代码来源:fight_test.py

示例6: test_fight

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
    def test_fight(self):

        hero = Hero("LevskiHooligan", 650, "ChupimSkuli")
        orc = Orc("CskaSkinhead", 100, 3)
        fight = Fight(hero, orc)
        beer_bottle = Weapon("BeerBottle", 150, 0.8)
        metal_pipe = Weapon("MetalPipe", 180, 0.9)
        fight.hero.weapon = metal_pipe
        fight.orc.weapon = beer_bottle
        fight.simulate_fight()

        self.assertEqual(fight.orc.fight_health, 0)
        self.assertTrue(fight.hero.fight_health > 0)
开发者ID:JusttRelaxx,项目名称:HackBulgaria,代码行数:15,代码来源:fight_test.py

示例7: move

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
    def move(self, player_name, direction):
        if player_name in self.players:
            player = self.players[player_name]
            # go_to -> (coord_x1, coord_y1)
            go_to = self.go_to_field(player[1], player[2], direction)
            if go_to:
                if self.dungeon[go_to[1]][go_to[0]] == '#':
                    print('Obstacle in that direction.')
                    return False
                elif self.dungeon[go_to[1]][go_to[0]] == '.':
                    self.dungeon[go_to[1]][go_to[0]] = self.dungeon[
                        player[2]][player[1]]
                    self.dungeon[player[2]][player[1]] = '.'
                    self.players[player_name] = (player[0], go_to[0], go_to[1])
                elif self.dungeon[go_to[1]][go_to[0]] == 'W':
                    weapon = self.get_weapon(go_to[0], go_to[1])
                    player[0].equip_weapon(weapon)
                    self.dungeon[go_to[1]][go_to[0]] = self.dungeon[
                        player[2]][player[1]]
                    self.dungeon[player[2]][player[1]] = '.'
                    self.players[player_name] = (player[0], go_to[0], go_to[1])
                    print('{} weapon equipped!'.format(weapon.type))
                else:  # in that case we meet enemy
                    # recognise hero and orc
                    if isinstance(player[0], Hero):
                        hero = (player_name, player[0])
                        orc = self.entity_at_field(go_to[0], go_to[1])
                    else:
                        hero = self.entity_at_field(go_to[0], go_to[1])
                        orc = (player_name, player[0])

                    # get the winner
                    fight = Fight(hero[1], orc[1])
                    fight.simulate_fight()
                    if fight.hero.health != 0:
                        print('{} wins!!!'.format(hero[0]))
                        self.dungeon[go_to[1]][go_to[0]] = 'H'
                        self.players.pop(orc[0])
                        self.players[hero[0]] = (hero[1], go_to[0], go_to[1])
                    else:
                        print('{} wins!!!'.format(orc[0]))
                        self.dungeon[go_to[1]][go_to[0]] = 'O'
                        self.players.pop(hero[0])
                        self.players[orc[0]] = (orc[1], go_to[0], go_to[1])
                    self.dungeon[player[2]][player[1]] = '.'
            else:
                print('Movement out of bounds.')
                return False
        else:
            message = 'There is no such player in the game.'
            raise ValueError(message)
开发者ID:Fusl,项目名称:Hack-Bulgaria-Programming-101,代码行数:53,代码来源:dungeon.py

示例8: compleate_fight

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
 def compleate_fight(self, player_name, enemy_pos):
     enemy_name = self.get_entity_name(enemy_pos)
     #get player from dict
     player_one = Hero("Bron", 10, "DragonSlayer")
     player_two = Orc("Bron", 10, 1.3)
     for keys in self.heroes_dict:
         if self.heroes_dict[keys] == "%s" % (enemy_name) or self.heroes_dict[keys] == "%s" % (player_name):
             if self.heroes_dict[keys] == "%s" % (player_name):
                 player_one = keys
             if self.heroes_dict[keys] == "%s" % (enemy_name):
                 player_two = keys
     fight = Fight(player_one, player_two)
     fight.simulate_fight()
     return player_one.is_alive()
开发者ID:AlexanderTankov,项目名称:HackBulgaria-Programming-101,代码行数:16,代码来源:dungeon.py

示例9: battle

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
    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,代码行数:28,代码来源:dungeon.py

示例10: move

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
    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,代码行数:62,代码来源:dungeon.py

示例11: test_simulate_fight_hero_win

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
 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,代码行数:9,代码来源:fight_test.py

示例12: fight_for_territory

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
    def fight_for_territory(self, position, new_position):
        initial_enemy_health = 100
        if self.map[new_position.x][new_position.y] == 'P':
            enemy = Python(initial_enemy_health)
        elif self.map[new_position.x][new_position.y] == 'A':
            enemy = Anaconda(initial_enemy_health)
        if not enemy:
            return False

        fight_to_the_death = Fight(self.hero, enemy)
        fight_to_the_death.simulate_fight()
        if self.hero.is_alive():
            self.change_position(position, new_position)
            if isinstance(enemy, Anaconda):
                self.hero.add_boss_benefits()
            return True
开发者ID:tdhris,项目名称:HackBulgaria,代码行数:18,代码来源:dungeon.py

示例13: test_simulate_fight

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
 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,代码行数:9,代码来源:test_fight.py

示例14: TestFight

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
class TestFight(unittest.TestCase):

    def setUp(self):
        self.hero = Hero("Aiden", 500, "Daro Wonderer")
        self.orc = Orc("Thrall", 400, 1.4)
        weapon1 = Weapon("The Ash Bringer", 80, 0.5)
        weapon2 = Weapon('DoomHammer', 80, 0.5)
        self.hero.equip_weapon(weapon1)
        self.orc.equip_weapon(weapon2)

        self.fight = Fight(self.hero, self.orc)

    def test_simulate_fight(self):
        self.fight.simulate_fight()
        self.assertTrue(self.hero.is_alive() or self.orc.is_alive())
        self.assertFalse(self.orc.is_alive() and self.hero.is_alive())
开发者ID:NikiMaslarski,项目名称:HackBulgari_Programming101,代码行数:18,代码来源:fight_test.py

示例15: test_simulate_fight_orc_win

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import simulate_fight [as 别名]
 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,代码行数:9,代码来源:fight_test.py


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