Пример #1
0
    def create_state(self):
        game_map = GameMap(21)
        game_state = GameState(game_map)
        p0 = game_state.add_player("0")
        p0.stats.kill_player("p1")
        p0.stats.killed_by_player("p2")
        p0.stats.add_stat(PlayerStats.SUICIDES)
        p0.stats.add_stat(PlayerStats.BLITZIUMS)
        p0.stats.add_stat(PlayerStats.CONQUERED)
        p0.tail = [Position(1, 2), Position(2, 3), Position(4, 5)]
        p0.history.append(
            HistoryItem(11, "message-11",
                        datetime.datetime(1900, 1, 1, 13, 14, 15, 555)))
        p0.history.append(
            HistoryItem(10, "message-10",
                        datetime.datetime(1900, 1, 1, 13, 14, 15, 444)))

        p1 = game_state.add_player("1")
        p1.stats.kill_player("p1")
        p1.stats.killed_by_player("p2")
        p1.stats.add_stat(PlayerStats.SUICIDES)
        p1.stats.add_stat(PlayerStats.BLITZIUMS)
        p1.stats.add_stat(PlayerStats.CONQUERED)
        p1.tail = [Position(1, 2), Position(2, 3), Position(4, 5)]
        p1.history.append(
            HistoryItem(11, "message-11",
                        datetime.datetime(1900, 1, 1, 13, 14, 15, 555)))
        p1.history.append(
            HistoryItem(10, "message-10",
                        datetime.datetime(1900, 1, 1, 13, 14, 15, 444)))

        return game_state
Пример #2
0
    def test_add_player_should_respect_orientation(self):
        gc = GameConfig(GameMap(20),
                        spawn_positions=[Position(1, 1)],
                        spawn_directions=[Direction(Direction.LEFT)])
        gs = GameState(gc, players=None)
        self.assertEqual(len(gs.players), 0)
        gs.add_player("Karl Marx")

        self.assertEqual(Direction(Direction.LEFT), gs.players[0].direction)
Пример #3
0
    def test_add_player(self):
        gs = GameState(GameMap(20), players=None)
        self.assertEqual(len(gs.players), 0)

        nb_players = 10
        for i in range(nb_players):
            gs.add_player(str(i))
        self.assertEqual(len(gs.players), nb_players)

        # no two players at the same place
        self.assertEqual(nb_players,
                         len(set([p.spawn_position for p in gs.players])))
Пример #4
0
    def test_add_player_with_game_config(self):
        game_config = GameConfig.from_str("WWWW\nW 2W\nW 1W\nWWWW")
        gs = GameState(game_config)
        self.assertEqual(len(gs.players), 0)

        ps0 = gs.add_player("0")
        self.assertEqual(Position(2, 2), ps0.spawn_position)

        ps1 = gs.add_player("1")
        self.assertEqual(Position(2, 1), ps1.spawn_position)

        with self.assertRaises(Exception):
            gs.add_player("2")
Пример #5
0
 def test_respawn_player(self):
     gs = GameState(GameMap(5))
     player = gs.add_player("1")
     gs.move_player(player, Action.FORWARD)
     self.assertNotEqual(player.position, player.spawn_position)
     player.killed = True
     gs.respawn_player(player)
     self.assertEqual(player.position, player.spawn_position)
     self.assertFalse(player.killed)