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)
def test_respawn_on_someone_tail(self): gm = GameMap(5) p1 = PlayerState(id=1, name="p1", game_map=gm, position=Position(1, 1)) p2 = PlayerState(id=2, name="p2", game_map=gm, position=Position(1, 2)) gs = GameState(gm, [p1, p2]) # p1: spawn position = 1,1, current position=3,1, tail [2,1 and 3,1] # p2: spawn position = 1,2, current position=2,2, tail [1,1, 1,2 and 2,2] p1.position = Position(3, 1) p1.tail = [Position(2, 1), Position(3, 1)] gm.set_tile(Position(1, 1), GameMap.EMPTY, 2) p2.position = Position(2, 2) p2.tail = [Position(1, 1), Position(1, 2), Position(2, 2)] p2.direction = Direction(Direction.UP) gs.apply_action(0, p2, Action.FORWARD) self.assertTrue(p1.killed) self.assertFalse(p2.killed) # respawn gs.respawn_player(p1) self.assertFalse(p1.killed) self.assertTrue(p2.killed)