def test_move(self): self._picker.move(action=Action.RIGHT, limit=Limit(0, self._height, 0, self._width)) self.assertTrue(self._picker.get_position() == Position(x=1, y=15)) self._picker.move(action=Action.RIGHT, limit=Limit(0, self._height, 0, self._width)) self.assertTrue(self._picker.get_position() == Position(x=2, y=15)) self._picker.move(action=Action.LEFT, limit=Limit(0, self._height, 0, self._width)) self.assertTrue(self._picker.get_position() == Position(x=1, y=15)) self._picker.move(action=Action.LEFT, limit=Limit(0, self._height, 0, self._width)) self.assertTrue(self._picker.get_position() == Position(x=0, y=15))
def draw(self): x = self.__fruit.get_position().x y = self.__fruit.get_position().y self.__viewer.draw_polygon(v=[ transform(Position(x, y), self.__scale), transform(Position(x + self.__fruit.get_size().width, y), self.__scale), transform( Position(x + self.__fruit.get_size().width, y - self.__fruit.get_size().height), self.__scale), transform(Position(x, y - self.__fruit.get_size().height), self.__scale) ], filled=True, color=self.__color)
def setUp(self) -> None: self._width = 100 self._height = 100 picker_width = 20 picker_height = 10 self._picker = Picker(pos0=Position(x=0, y=15), dx=1, size=Size(width=picker_width, height=picker_height))
def move(self, action: Action, limit: Limit): assert isinstance( action, Action), "picker.error : action must be an Action instance" assert isinstance( limit, Limit), "picker.error : limit must be a Limit instance" assert limit.top > limit.bottom, "picker.error : top must be greater than bottom" assert limit.left < limit.right, "picker.error : left must be lower than bottom" assert limit.left <= self.__pos.x <= limit.right - self.__size.width, "picker.error : x position must be between left and right limit" assert limit.bottom + self.__size.height <= self.__pos.y <= limit.top, "picker.error : y position must be between top and bottom limit" x = self.__pos.x y = self.__pos.y # Realizar acción if action == Action.LEFT and limit.left <= x - self.__dx: x -= self.__dx self.__pos = Position(x, y) elif action == Action.RIGHT and x + self.__size.width + self.__dx <= limit.right: x += self.__dx self.__pos = Position(x, y)
def transform(position: Position, scale): x = position.x / scale y = position.y / scale return Position(x, y)
def move(self): if not self.__collected: x = self.__pos.x y = self.__pos.y self.__pos = Position(x, y - self.__dy)
def setUp(self) -> None: self.width = 100 self.height = 100 x = 0 y = self.height self.fruit = Fruit(pos0=Position(x=x, y=y), size=Size(10, 10), dy=1)
def test_move_right_limit(self): for _ in range(1000): self._picker.move(action=Action.RIGHT, limit=Limit(0, self._height, 0, self._width)) self.assertTrue(self._picker.get_position() == Position( x=100 - self._picker.get_size().width, y=15))
def test_move_left_limit(self): for _ in range(1000): self._picker.move(action=Action.LEFT, limit=Limit(0, self._height, 0, self._width)) self.assertTrue(self._picker.get_position() == Position(x=0, y=15))