Beispiel #1
0
  private void SetPlayerManager(JsonArray players, JsonObject turnTracker) {
    Player[] catanPlayers = new Player[players.size()];
    int longestRoad = turnTracker.getAsJsonPrimitive("longestRoad").getAsInt();
    int largestArmy = turnTracker.getAsJsonPrimitive("largestArmy").getAsInt();

    for (int i = 0; i < players.size(); i++) {
      if (!players.get(i).isJsonNull()) {
        JsonObject player = players.get(i).getAsJsonObject();
        int index = player.getAsJsonPrimitive("playerIndex").getAsInt();

        String name = player.getAsJsonPrimitive("name").getAsString();
        String color = player.getAsJsonPrimitive("color").getAsString();
        int playerId = player.getAsJsonPrimitive("playerID").getAsInt();
        int cities = player.getAsJsonPrimitive("cities").getAsInt();
        int settlements = player.getAsJsonPrimitive("settlements").getAsInt();
        int roads = player.getAsJsonPrimitive("roads").getAsInt();
        int victoryPoints = player.getAsJsonPrimitive("victoryPoints").getAsInt();

        Player newPlayer = new Player();
        newPlayer.setPoints(victoryPoints);
        try {
          newPlayer.setColor(color);
        } catch (InvalidColorException e) {
          e.printStackTrace();
        }
        if (longestRoad == index) {
          newPlayer.setLongestRoad(true);
        }
        if (largestArmy == index) {
          newPlayer.setLargestArmy(true);
        }

        newPlayer.setId(playerId);
        newPlayer.setCitiesRemaining(cities);
        newPlayer.setSettlementsRemaining(settlements);
        newPlayer.setRoadsRemaining(roads);
        newPlayer.setPlayerIndex(index);
        newPlayer.setName(name);

        // <========Construct part of player manager here============>
        catanPlayers[index] = newPlayer;
      }
    }
    // <========Construct player manager here============>
    PlayerManager newPlayerManager = new PlayerManager();
    newPlayerManager.setCatanPlayers(catanPlayers);
    newPlayerManager.setIndexOfLargestArmy(largestArmy);
    newPlayerManager.setIndexOfLongestRoad(longestRoad);

    this.playerManager = newPlayerManager;
  }
Beispiel #2
0
  private void SetTurnManager(JsonObject turnTracker)
      throws TurnIndexException, InvalidTurnStatusException, GeneralPlayerException {
    int currentTurn = turnTracker.getAsJsonPrimitive("currentTurn").getAsInt();
    String status = turnTracker.getAsJsonPrimitive("status").getAsString();

    PlayerTurnTracker playerTurnTracker =
        new PlayerTurnTracker(currentTurn, TurnType.toEnum(status));
    playerManager.setTurnTracker(playerTurnTracker);
  }