@Test(timeout = 100000) public void testPlayGame() throws InterruptedException, IOException { testPlayAny(); client1.awaitUntil(PlayerConfigMessage.class); TCGGame game = (TCGGame) server.getGames().get(1); ClientIO io = server.getClients().get(userId); assertEquals(2, game.getGameModel().getEntitiesWithComponent(PlayerComponent.class).size()); game.incomingPlayerConfig( new PlayerConfigMessage(game.getId(), getTestMod(), new HashMap<>()), io); assertEquals(ECSGameState.RUNNING, game.getGameModel().getGameState()); Entity human = game.playerFor(io); Entity ai = game.getGameModel().getEntitiesWithComponent(AIComponent.class).stream().findFirst().get(); ai.getComponent(AIComponent.class).setDelay(0); CardshifterAI humanActions = new ScoringAI(AIs.medium()); client1.awaitUntil(ResetAvailableActionsMessage.class); client1.awaitUntil(ResetAvailableActionsMessage.class); client1.awaitUntil(UsableActionMessage.class); while (!game.isGameOver()) { ECSAction action = humanActions.getAction(human); if (action != null) { System.out.println("Perform " + action); int[] targets = new int[] {}; if (!action.getTargetSets().isEmpty()) { targets = action .getTargetSets() .get(0) .getChosenTargets() .stream() .mapToInt(e -> e.getId()) .toArray(); } UseAbilityMessage message = new UseAbilityMessage( game.getId(), action.getOwner().getId(), action.getName(), targets); System.out.println("Sending message: " + message); client1.send(message); client1.awaitUntil(ResetAvailableActionsMessage.class); } else { System.out.println("Nothing to perform, busy-loop"); } } }
@Test(timeout = 50000) public void testStartGame() throws InterruptedException, IOException { client1.send(new StartGameRequest(2, getTestMod())); NewGameMessage gameMessage = client1.await(NewGameMessage.class); assertEquals(1, gameMessage.getGameId()); client1.awaitUntil(PlayerConfigMessage.class); TCGGame game = (TCGGame) server.getGames().get(1); assertEquals(2, game.getGameModel().getEntitiesWithComponent(PlayerComponent.class).size()); assertTrue(game.hasPlayer(server.getClients().get(userId))); assertTrue(game.hasPlayer(server.getClients().get(2))); game.incomingPlayerConfig( new PlayerConfigMessage(game.getId(), getTestMod(), new HashMap<>()), server.getClients().get(2)); game.incomingPlayerConfig( new PlayerConfigMessage(game.getId(), getTestMod(), new HashMap<>()), server.getClients().get(userId)); client1.awaitUntil(ResetAvailableActionsMessage.class); assertEquals(ECSGameState.RUNNING, game.getState()); }