def test_move_complex(self): def _act(p): p[0].assertEqual(p[1], 1) self.board = pgl_engine.Board( name="test_board", size=[10, 10], player_starting_position=[5, 5], ) i = pgl_board_items.ComplexNPC(sprite=gfx_core.Sprite( default_sprixel=gfx_core.Sprixel("*"))) g = pgl_engine.Game(mode=constants.MODE_RT) self.board.place_item(i, 1, 1) self.assertIsInstance(self.board.item(1, 1), pgl_board_items.ComplexNPC) self.assertIsNone(self.board.move(i, constants.RIGHT, 1)) i = pgl_board_items.ComplexPlayer(sprite=gfx_core.Sprite( default_sprixel=gfx_core.Sprixel("*"), sprixels=[[gfx_core.Sprixel("@"), gfx_core.Sprixel("@")]], )) self.board.place_item(i, 3, 1) self.assertIsInstance(self.board.item(3, 1), pgl_board_items.ComplexPlayer) self.board.place_item( pgl_board_items.GenericActionableStructure( action=_act, action_parameters=[self, 1]), i.row, i.column + i.width, ) self.assertIsNone(self.board.move(i, constants.RIGHT, 1)) self.board.place_item(pgl_board_items.Treasure(value=50), i.row + i.height, i.column) self.assertIsNone(self.board.move(i, constants.DOWN, 1)) self.assertEqual(i.inventory.value(), 50) i.parent = g i.dtmove = 0.0 self.assertIsNone(self.board.move(i, pgl_base.Vector2D(1, 0))) i.dtmove = 5.0 self.assertIsNone(self.board.move(i, pgl_base.Vector2D(1, 0))) with self.assertRaises(pgl_base.PglObjectIsNotMovableException): self.board.move(pgl_board_items.Immovable(), constants.DOWN, 1) g.mode = constants.MODE_TBT self.board.place_item(pgl_board_items.Door(), i.row, i.column + i.width) self.assertIsNone(self.board.move(i, constants.RIGHT, 1)) self.assertIsNone(self.board.move(i, constants.RIGHT, 2)) self.assertIsNone(self.board.move(i, constants.DOWN, 2)) with self.assertRaises(pgl_base.PglInvalidTypeException): self.board.move(i, constants.DOWN, "1") with self.assertRaises(pgl_base.PglInvalidTypeException): self.board.move(i, "constants.DOWN", 1)
def test_boarditemcomplexcomponent(self): bi = board_items.BoardItemComplexComponent(parent=None) self.assertFalse(bi.restorable()) self.assertFalse(bi.overlappable()) self.assertFalse(bi.can_move()) self.assertFalse(bi.pickable()) bic = board_items.ComplexPlayer() bi = board_items.BoardItemComplexComponent(parent=bic) bic = board_items.Tile() # Please never do that... Python allowing it is bad enough. bic.can_move = True bic.overlappable = True bi = board_items.BoardItemComplexComponent(parent=bic)
def test_player(self): p = board_items.Player(inventory=board_items.engine.Inventory()) self.assertFalse(p.pickable()) self.assertTrue(p.has_inventory()) sprite = gfx_core.Sprite( name="test_sprite", sprixels=[ [ gfx_core.Sprixel(" ", gfx_core.Color(255, 0, 0)), gfx_core.Sprixel(" ", gfx_core.Color(255, 0, 0)), ] ], ) n = board_items.ComplexPlayer(name="Test Player", sprite=sprite) n.actuator = actuators.RandomActuator() data = n.serialize() self.assertEqual(n.name, data["name"]) self.assertEqual(n.sprite.name, data["sprite"]["name"]) n2 = board_items.ComplexPlayer.load(data) self.assertEqual(n.name, n2.name)