public void summarizePlayer(int playerID) {
    Player p = players.get(playerID);
    Map<Integer, Playing> playersGames = p.games;
    Set<Integer> gamesKeys = playersGames.keySet();
    Integer[] gameIDs = gamesKeys.toArray(new Integer[gamesKeys.size()]);

    System.out.println("Player: " + p);
    System.out.println("Total Gamerscore: " + p.getGamerScore());
    System.out.printf(
        "%4s %-20s %-16s %-16s %-16s \n", " ", "Game", "Achievements", "Gamerscore", "IGN");
    System.out.println(
        "--------------------------------------------------------------------------------");
    for (int i = 0; i < gameIDs.length; i++) {
      Game g = games.get(gameIDs[i]);
      Playing playerInfo = p.games.get(gameIDs[i]);
      int nPlayerAchieve = playerInfo.achievements.size();
      int nTotalAchieve = g.achievements.size();
      System.out.printf(
          "%4s %-20s %-16s %-16s %-16s \n",
          (i + 1 + "."),
          g,
          (nPlayerAchieve + "/" + nTotalAchieve),
          (playerInfo.getPoints() + " pts"),
          playerInfo.ign);
    }

    System.out.printf("\n%4s %-16s %-16s \n", " ", "Friend", "Gamerscore");
    System.out.println(
        "--------------------------------------------------------------------------------");
    printSortedPlayers(p.friends);
  }
  public void printSortedPlayers(Collection<? extends Integer> playerIDs) {
    ArrayList<Player> sortPlayers = new ArrayList<Player>();
    for (int id : playerIDs) {
      sortPlayers.add(players.get(id));
    }
    Collections.sort(sortPlayers, new Player.PlayerComparator());

    int nPlayers = sortPlayers.size();
    for (int i = 0; i < nPlayers; i++) {
      Player p = sortPlayers.get(nPlayers - i - 1);
      System.out.printf("%4s %-16s %-16s \n", (i + 1 + "."), p, (p.getGamerScore() + " pts"));
    }
    System.out.println();
  }
Exemple #3
0
 static int isEnd(Player player) {
   int i;
   for (i = 1; i <= 5; i++) {
     if (player.haveHide("End" + i)) return i;
   }
   return 0;
 }
 public void achieve(int playerID, int gameID, int achievementID) {
   if (players.containsKey(playerID) && achievements.containsKey(achievementID)) {
     Player p = players.get(playerID);
     Achievement a = achievements.get(achievementID);
     if (p.games.containsKey(gameID)
         && !p.games.get(gameID).achievements.contains(achievementID)) {
       Playing playerInfo = p.games.get(gameID);
       int pointsEarned = a.points;
       playerInfo.achievements.add(achievementID);
       playerInfo.addPoints(pointsEarned);
       p.addPoints(pointsEarned);
       a.players.add(playerID);
     } else {
       // System.out.println("player does not play this game or already has this achievement");
     }
   } else {
     // System.out.println("player or achievement does not exist");
   }
 }