Exemple #1
0
    def test_tools_function(self):
        b = engine.Board()
        g = engine.Game()
        g.player = constants.NO_PLAYER
        self.assertIsNone(g.add_board(1, b))
        self.assertIsNone(g.change_level(1))
        self.assertIsNone(
            g.add_npc(1, board_items.NPC(value=10, inventory_space=1), 1, 1))
        self.assertIsNone(
            b.place_item(board_items.Door(value=10, inventory_space=1), 1, 2))
        self.assertIsNone(
            b.place_item(board_items.Wall(value=10, inventory_space=1), 1, 3))
        self.assertIsNone(
            b.place_item(
                board_items.GenericStructure(value=10, inventory_space=1), 1,
                4))
        self.assertIsNone(
            b.place_item(
                board_items.GenericActionableStructure(value=10,
                                                       inventory_space=1),
                1,
                5,
            ))
        self.assertIsNone(
            b.place_item(
                board_items.Door(value=10,
                                 inventory_space=1,
                                 sprixel=core.Sprixel("#")),
                2,
                2,
            ))
        self.assertIsNone(
            b.place_item(board_items.Treasure(value=10, inventory_space=1), 1,
                         6))
        with self.assertRaises(base.PglInvalidTypeException):
            g.neighbors("2")

        with self.assertRaises(base.PglInvalidTypeException):
            g.neighbors(2, "crash")

        g.object_library.append(board_items.NPC())
        self.assertIsNone(
            g.save_board(1, "test-pygamelib.engine.Game.lvl1.json"))
        with self.assertRaises(base.PglInvalidTypeException):
            g.save_board("1", "test-pygamelib.engine.Game.lvl1.json")
        with self.assertRaises(base.PglInvalidTypeException):
            g.save_board(1, 1)
        with self.assertRaises(base.PglInvalidLevelException):
            g.save_board(11, "test-pygamelib.engine.Game.lvl1.json")
        self.assertIsInstance(
            g.load_board("test-pygamelib.engine.Game.lvl1.json", 1),
            engine.Board)
        self.assertEqual(g._string_to_constant("UP"), constants.UP)
        self.assertEqual(g._string_to_constant("DOWN"), constants.DOWN)
        self.assertEqual(g._string_to_constant("LEFT"), constants.LEFT)
        self.assertEqual(g._string_to_constant("RIGHT"), constants.RIGHT)
        self.assertEqual(g._string_to_constant("DRUP"), constants.DRUP)
        self.assertEqual(g._string_to_constant("DRDOWN"), constants.DRDOWN)
        self.assertEqual(g._string_to_constant("DLUP"), constants.DLUP)
        self.assertEqual(g._string_to_constant("DLDOWN"), constants.DLDOWN)
 def test_genericstructure(self):
     bi = board_items.GenericStructure(value=5)
     self.assertFalse(bi.pickable())
     self.assertFalse(bi.overlappable())
     self.assertFalse(bi.restorable())
     with self.assertRaises(board_items.base.PglInvalidTypeException):
         bi.set_restorable(1)
     bi.set_restorable(True)
     self.assertTrue(bi.restorable())
     bi = board_items.GenericActionableStructure()
Exemple #3
0
    def test_tools_function(self):
        b = engine.Board()
        g = engine.Game()
        g.player = constants.NO_PLAYER
        self.assertIsNone(g.add_board(1, b))
        self.assertIsNone(g.change_level(1))
        self.assertIsNone(
            g.add_npc(1, board_items.NPC(value=10, inventory_space=1), 1, 1))
        tmp_npc = g.get_board(1).item(1, 1)
        tmp_npc.actuator = actuators.PathFinder(game=g,
                                                actuated_object=tmp_npc)
        tmp_npc.actuator.set_destination(2, 5)
        tmp_npc.actuator.find_path()
        self.assertIsNone(
            b.place_item(board_items.Door(value=10, inventory_space=1), 1, 2))
        self.assertIsNone(
            b.place_item(board_items.Wall(value=10, inventory_space=1), 1, 3))
        self.assertIsNone(
            b.place_item(
                board_items.GenericStructure(value=10, inventory_space=1), 1,
                4))
        self.assertIsNone(
            b.place_item(
                board_items.GenericActionableStructure(value=10,
                                                       inventory_space=1),
                1,
                5,
            ))
        self.assertIsNone(
            b.place_item(
                board_items.Door(value=10,
                                 inventory_space=1,
                                 sprixel=core.Sprixel("#")),
                2,
                2,
            ))
        self.assertIsNone(
            b.place_item(board_items.Treasure(value=10, inventory_space=1), 1,
                         6))
        with self.assertRaises(base.PglInvalidTypeException):
            g.neighbors("2")

        with self.assertRaises(base.PglInvalidTypeException):
            g.neighbors(2, "crash")

        g.object_library.append(board_items.NPC())
        self.assertIsNone(
            g.save_board(1, "test-pygamelib.engine.Game.lvl1.json"))
        with self.assertRaises(base.PglInvalidTypeException):
            g.save_board("1", "test-pygamelib.engine.Game.lvl1.json")
        with self.assertRaises(base.PglInvalidTypeException):
            g.save_board(1, 1)
        with self.assertRaises(base.PglInvalidLevelException):
            g.save_board(11, "test-pygamelib.engine.Game.lvl1.json")
        self.assertIsInstance(
            g.load_board("test-pygamelib.engine.Game.lvl1.json", 1),
            engine.Board)
        self.assertEqual(g._string_to_constant("UP"), constants.UP)
        self.assertEqual(g._string_to_constant("DOWN"), constants.DOWN)
        self.assertEqual(g._string_to_constant("LEFT"), constants.LEFT)
        self.assertEqual(g._string_to_constant("RIGHT"), constants.RIGHT)
        self.assertEqual(g._string_to_constant("DRUP"), constants.DRUP)
        self.assertEqual(g._string_to_constant("DRDOWN"), constants.DRDOWN)
        self.assertEqual(g._string_to_constant("DLUP"), constants.DLUP)
        self.assertEqual(g._string_to_constant("DLDOWN"), constants.DLDOWN)

        with self.assertRaises(base.PglInvalidTypeException):
            g.delete_level()
        with self.assertRaises(base.PglInvalidLevelException):
            g.delete_level(42)
        g.delete_level(1)
        g.delete_all_levels()
        self.assertIsNone(g.current_board())
        bi = board_items.Door(
            value=10,
            inventory_space=0,
            pickable=False,
            overlappable=True,
            restorable=True,
        )
        obj = engine.Game._ref2obj(bi.serialize())
        self.assertIsInstance(obj, board_items.Door)
        bi = board_items.Treasure(
            value=10,
            inventory_space=0,
            pickable=False,
            overlappable=True,
            restorable=True,
        )
        obj = engine.Game._ref2obj(bi.serialize())
        self.assertIsInstance(obj, board_items.Treasure)
        bi = board_items.GenericActionableStructure(
            value=10,
            inventory_space=0,
            pickable=False,
            overlappable=True,
            restorable=True,
        )
        obj = engine.Game._ref2obj(bi.serialize())
        self.assertIsInstance(obj, board_items.GenericActionableStructure)
        bi = board_items.NPC(
            value=10,
            inventory_space=10,
            pickable=False,
            overlappable=True,
            restorable=True,
        )
        bi.actuator = actuators.PathActuator(path=[constants.UP])
        obj = engine.Game._ref2obj(bi.serialize())
        self.assertIsInstance(obj, board_items.NPC)
        bi.actuator = actuators.PatrolActuator(path=[constants.UP])
        obj = engine.Game._ref2obj(bi.serialize())
        self.assertIsInstance(obj.actuator, actuators.PatrolActuator)
    cst.LEFT,
    cst.LEFT,
    cst.LEFT,
])

game.add_board(1, lvl1)
game.add_board(2, lvl2)

t = board_items.Treasure(model=sprite_treasure,
                         name="Cool treasure",
                         type="gem")
money_bag = board_items.Treasure(model=sprite_treasure2,
                                 name="money",
                                 value=20)

tree = board_items.GenericStructure(model=sprite_tree)
tree.set_overlappable(False)
tree.set_pickable(False)

portal2 = board_items.GenericActionableStructure(model=sprite_portal)
portal2.set_overlappable(False)
portal2.action = change_current_level
portal2.action_parameters = [game, 2]

portal1 = board_items.GenericActionableStructure(model=sprite_portal)
portal1.set_overlappable(False)
portal1.action = change_current_level
portal1.action_parameters = [game, 1]

life_heart = board_items.GenericActionableStructure(model=sprite_heart,
                                                    name="life_100")