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


Python Monster.attack方法代码示例

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


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

示例1: test_attack

# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import attack [as 别名]
class test_attack(unittest.TestCase):
    def setUp(self):
        self.monsta = Monster()
        print(self.shortDescription())

    #Tests if heal function works
    def test_attack_live(self):
        self.monsta.health = 6
        expected = 1
        actual = self.monsta.attack(5)
        self.assertEqual(expected, actual)

    #Heal function should not work if total > 10
    def test_attack_die(self):
        self.monsta.health = 4
        expected = -1
        actual = self.monsta.attack(5)
        self.assertEqual(expected, actual)

    #Tests if invalid output was printed
    @patch ('sys.stdout', new_callable=StringIO)
    def test_attack_die_KO(self, mock_stdout):
        health = self.monsta.health(4)

        expected = "K.O.'d"
        actual = self.monsta.attack(6)
        self.assertNotEqual(mock_stdout.getValue(), text)
开发者ID:PDXDevCampJuly,项目名称:daniel_pearl,代码行数:29,代码来源:test_attack.py

示例2: AttackTest

# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import attack [as 别名]
class AttackTest(unittest.TestCase):

    """Test Monster Class attack function"""

    def setUp(self):
        print(self.shortDescription())
        self.test_monster = Monster("The Boogie Monster")

    def test_ideal_attack(self):
        """test ideal attack, won't ko"""
        self.assertEqual(5, self.test_monster.attack(5))

    def test_kod_attack(self):
        """test kod attack"""
        self.test_monster.attack(15)
        self.assertEqual("K.O.'d", self.test_monster.status)

    def test_kod_attack_health(self):
        """test kod attack"""
        self.test_monster.attack(15)
        self.assertEqual(-5, self.test_monster.health)

    def test_incorrect_type_attack(self):
        """test if we prevent bad types"""
        with self.assertRaises(TypeError):
            self.test_monster.attack("some bad types")

    def test_negative_healt(self):
        """we should test for negative health catches"""
        pass
开发者ID:grumps,项目名称:max-resnick,代码行数:32,代码来源:test_attack.py

示例3: AttackTest

# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import attack [as 别名]
class AttackTest(unittest.TestCase):
    """Test the functionality of the Monster class attack function."""

    def setUp(self):
        self.new_monster = Monster("Cookie")

    def tearDown(self):
        del self.new_monster

    def test_attack_stay_alive(self):
        """
        Initialize health to 10. Call function with 7 and check that 3 is
        returned and status is unchanged.
        """
        self.new_monster.health = 10
        original_status = self.new_monster.status

        # Call function
        new_health = self.new_monster.attack(7)

        self.assertEqual(new_health, 3,
                         "Expected 3 for updated health.")
        self.assertEqual(self.new_monster.status, original_status,
                         "Status should have remained {}".
                         format(original_status))

    def test_attack_ko_ed(self):
        """
        Initialize health to 10. Call function with 12 and check that -2 is
        returned and status is "K.O.'d".
        """

        self.new_monster.health = 10

        # Call function
        new_health = self.new_monster.attack(12)

        self.assertEqual(new_health, -2,
                         "Expected 3 for updated health.")
        self.assertEqual(self.new_monster.status, "K.O.'d",
                         "Status should be K.O.'d")
开发者ID:PDXDevCampJuly,项目名称:atifar,代码行数:43,代码来源:test_attack.py

示例4: test_heal

# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import attack [as 别名]
class test_heal(unittest.TestCase):
    def setUp(self):
        self.monsta = Monster()
        self.monsta.health = 5

    #Tests if monster heals
    def test_valid_heal(self):
        health = self.monsta.heal(5)

        self.assertEqual(health, 10, "Heal did not work")

    #Monster should not heal if sum > 10
    def test_invalid_heal(self):
        health = self.monsta.heal(6)

        self.assertNotEqual(health, 11, "Heal should not have worked")

    #Tests invalid output
    @patch ('sys.stdout', new_callable=StringIO)
    def test_attack_die_KO(self, mock_stdout):
        health = self.monsta.attack(6)

        text = "Invalid heal amount"
        self.assertNotEqual(mock_stdout.getValue(), text)
开发者ID:TheOneTAR,项目名称:daniel_pearl,代码行数:26,代码来源:test_heal.py

示例5: run

# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import attack [as 别名]
class World:
    def run(self):
        self.player = Monster(name='Player')
        self._load_history(self.player)

        monster = random.choice(list(monsters.viewkeys()))
        self.monster = Monster(monsters[monster][0], monster, description=monsters[monster][1])
        self.ui = UI(self.player)
        self.ui.monster = self.monster

        self.ui.welcome()
        
        a = 1
        while a != 0:
            self._load_history(self.monster)

            a = self.run_loop()

            if a != 0:
                self.ui.update_display()

            self._save_history(self.player)
            self._save_history(self.monster)
            
            monster = random.choice(list(monsters.viewkeys()))
            self.monster = Monster(monsters[monster][0], monster, description=monsters[monster][1])
            self.ui.monster = self.monster

    def run_loop(self):
        player_move = "Run"
        while player_move.lower() != ACTION_QUIT:

            if self.player.offbalance:
                moves = [MOVE_BASH, MOVE_DEFEND]
            else:
                moves = [MOVE_ATTACK, MOVE_BASH, MOVE_DEFEND]
            if self.monster.offbalance:
                monster_moves = [MOVE_BASH, MOVE_DEFEND]
            else:
                monster_moves = [MOVE_ATTACK, MOVE_BASH, MOVE_DEFEND]

            player_move = self.ui.player_move(moves)

            if player_move == ACTION_QUIT:
                break
            if player_move not in moves:
                self.ui.msg = "I don't understand your input, try again."
                self.ui.update_display()
                continue

            monster_move = self.monster.attack(monster_moves, self.player)
            
            self.ui.monster.move = monster_move
            self.ui.player.move = player_move

            if player_move + monster_move in action_table:
                outcome = action_table[player_move + monster_move]
                self.monster.take_damage(outcome[2])
                self.monster.offbalance = outcome[3]
                self.player.take_damage(outcome[0])
                self.player.offbalance = outcome[1]
            else:
                outcome = action_table[monster_move + player_move]
                self.monster.take_damage(outcome[0])
                self.monster.offbalance = outcome[1]
                self.player.take_damage(outcome[2])
                self.player.offbalance = outcome[3]

            # record the moves just made for the AI
            self.player.history.append(player_move)
            self.monster.history.append(monster_move)

            self.ui.update_display()

            if self.player.is_dead() and self.monster.is_dead():
                self.ui.msg = "You have slain the foul " + self.monster.name + ", but it appears that, in its dying throes, the " + self.monster.name + "has also slain you."
                return 0
            elif self.player.is_dead():
                self.ui.msg = "Oh no! You seem to have perished!"
                return 0
            elif self.monster.is_dead():
                self.ui.msg = "You have slain the " + self.monster.name + "."
                return 1
        return 0

    def _load_history(self, monster):
        name = 'player'
        if monster.name.lower() != 'player':
            name = 'monster'

        try:
            f = open(name + '.moves', 'r+')
            monster.history = pickle.load(f)
            f.close()
        except Exception:
            pass

    def _save_history(self, monster):
        name = 'player'
        if monster.name.lower() != 'player':
#.........这里部分代码省略.........
开发者ID:schiem,项目名称:ai_project,代码行数:103,代码来源:world.py

示例6: attack

# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import attack [as 别名]
 def attack(self, target):
     """Attack the target."""
     Monster.attack(self, Object.obj_dict[target])
开发者ID:aruse,项目名称:Bludgeon,代码行数:5,代码来源:player.py


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