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


Python Unit.chase方法代码示例

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


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

示例1: TestUnit

# 需要导入模块: from unit import Unit [as 别名]
# 或者: from unit.Unit import chase [as 别名]
class TestUnit(unittest.TestCase):
    def setUp(self):
        self.constraint = (1000, 1000)
        self.unit = Unit(self.constraint, 100, 100, Directions.left, 160, 65)

    def test_init(self):
        self.assertEqual(self.unit.x, 100)
        self.assertEqual(self.unit.y, 100)
        self.assertEqual(self.unit.direction, Directions.left)
        self.assertEqual(self.unit.image_size, 160)
        self.assertEqual(self.unit.radius, 65)

    def test_move_random(self):
        x = self.unit.x
        y = self.unit.y
        self.unit.move_random()
        self.assertNotEqual((x, y), (self.unit.x, self.unit.y))

    def test_change_direction(self):
        direction = self.unit.direction
        self.unit.change_direction(self.unit.direction)
        self.assertNotEqual(direction, self.unit.direction)

    def test_constrain(self):
        self.unit.direction = Directions.down
        self.unit.y = 1000
        self.unit.constrain()
        self.assertEqual(self.unit.direction, Directions.up)

        self.unit.direction = Directions.up
        self.unit.y = -1000
        self.unit.constrain()
        self.assertEqual(self.unit.direction, Directions.down)

        self.unit.direction = Directions.right
        self.unit.x = 3000
        self.unit.constrain()
        self.assertEqual(self.unit.direction, Directions.left)

        self.unit.direction = Directions.left
        self.unit.x = -100
        self.unit.constrain()
        self.assertEqual(self.unit.direction, Directions.right)

    def test_collision_circle(self):
        x = self.unit.x + self.unit.image_size / 2
        y = self.unit.y + self.unit.image_size / 2
        coordinates = (x, y, self.unit.radius)
        self.assertEqual(self.unit.collision_circle(), coordinates)

    def test_get_direcion(self):
        x = 0
        y = 0
        self.unit.x = 0
        self.unit.direction = Directions.down
        self.unit.y = 1000
        self.unit.get_direction(x, y)
        self.assertEqual(self.unit.direction, Directions.up)

        self.unit.x = 0
        self.unit.direction = Directions.up
        self.unit.y = -1000
        self.unit.get_direction(x, y)
        self.assertEqual(self.unit.direction, Directions.down)

        self.unit.y = 0
        self.unit.direction = Directions.right
        self.unit.x = 3000
        self.unit.get_direction(x, y)
        self.assertEqual(self.unit.direction, Directions.left)

        self.unit.y = 0
        self.unit.direction = Directions.left
        self.unit.x = -100
        self.unit.get_direction(x, y)
        self.assertEqual(self.unit.direction, Directions.right)

    def test_chase(self):
        x = self.unit.x
        y = self.unit.y
        prey = Unit(self.constraint, 200, 200, Directions.left, 100, 100)
        self.unit.chase(prey)
        self.assertNotEqual((x, y), (self.unit.x, self.unit.y))

        prey = Unit(self.constraint, 98, 100, Directions.left, 100, 100)
        self.unit.chase(prey)
        self.assertEqual((prey.x, prey.y), (self.unit.x, self.unit.y))

        prey = Unit(self.constraint, 100, 98, Directions.left, 100, 100)
        self.unit.chase(prey)
        self.assertEqual((prey.x, prey.y), (self.unit.x, self.unit.y))
开发者ID:gvpavlov,项目名称:Insaniquarium,代码行数:93,代码来源:unit_test.py


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