public List<String> getPlayers() { List l = new ArrayList<String>(); for (Player p : this.g_players) { l.add(p.getUName()); } return l; }
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); } } }
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; }
public boolean isGameOver() { for (Player p : this.g_players) { if (p.getRoundsWon() == 5) { this.g_winner = p.getUName(); return true; } } return false; }
public boolean containsPlayer(String u_name) { for (Player p : this.g_players) { if ((p.getUName()).equals(u_name)) { return true; } } return false; }
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); } } }
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; }
private void resetPlayerVoteCounts() { for (Player p : this.g_players) { p.setVoteCount(0); } }