예제 #1
0
 public List<String> getPlayers() {
   List l = new ArrayList<String>();
   for (Player p : this.g_players) {
     l.add(p.getUName());
   }
   return l;
 }
예제 #2
0
 public synchronized void vote(String u_name) {
   this.g_round_vote_count++;
   for (Player p : this.g_players) {
     if ((p.getUName()).equals(u_name)) {
       p.setVoteCount(p.getVoteCount() + 1);
     }
   }
 }
예제 #3
0
 public List<String> getGameLosers() {
   List l = new ArrayList<String>();
   for (Player p : this.g_players) {
     if (!(p.getUName()).equals(this.g_winner)) {
       l.add(p.getUName());
     }
   }
   return l;
 }
예제 #4
0
 public boolean isGameOver() {
   for (Player p : this.g_players) {
     if (p.getRoundsWon() == 5) {
       this.g_winner = p.getUName();
       return true;
     }
   }
   return false;
 }
예제 #5
0
  public boolean containsPlayer(String u_name) {
    for (Player p : this.g_players) {
      if ((p.getUName()).equals(u_name)) {
        return true;
      }
    }

    return false;
  }
예제 #6
0
 public void removePlayer(String u_name) {
   // we have to use an iterator to avoid throwing a concurrentModificationException
   Iterator<Player> iter = this.g_players.iterator();
   while (iter.hasNext()) {
     Player p = iter.next();
     if ((p.getUName()).equals(u_name)) {
       iter.remove();
       System.out.println("successfully removed player " + u_name + " from game " + this.g_id);
     }
   }
 }
예제 #7
0
  public boolean isRoundOver() {
    if (g_round_vote_count == 5) {
      int max = 0;
      String winner = "";
      for (Player p : this.g_players) {
        if (p.getVoteCount() > max) {
          winner = p.getUName();
          max = p.getVoteCount();
        }
      }
      if (max == 1) {
        this.g_round_winner = "roundTied";
      } else {
        for (Player p : this.g_players) {
          if ((p.getUName()).equals(winner)) {
            p.setRoundsWon(p.getRoundsWon() + 1);
          }
        }
        this.g_round_winner = winner;
      }
      return true;
    }

    return false;
  }
예제 #8
0
 private void resetPlayerVoteCounts() {
   for (Player p : this.g_players) {
     p.setVoteCount(0);
   }
 }