本文整理汇总了Python中unit.Unit.move_random方法的典型用法代码示例。如果您正苦于以下问题:Python Unit.move_random方法的具体用法?Python Unit.move_random怎么用?Python Unit.move_random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unit.Unit
的用法示例。
在下文中一共展示了Unit.move_random方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUnit
# 需要导入模块: from unit import Unit [as 别名]
# 或者: from unit.Unit import move_random [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))