/// <summary> /// Initializes a new instance of the <see cref="T:Server.Game"/> class. /// </summary> /// <param name="id">Identifier.</param> /// <param name="users">Users.</param> public Game(int id, List <UserManager> users) { this.id = id; deck = new List <Card>(); players = new List <Player>(); foreach (UserManager n in users) { players.Add(new Player(players.Count, (players.Count % 2 == 0 ? Team.FIRST : Team.SECOND), n)); GameManager.SendPrivate(players.Last(), "You are player " + (players.Count - 1) + " and you are in the " + ((players.Count - 1) % 2 == 0 ? Team.FIRST : Team.SECOND) + " team."); GameManager.SendAll(players, "Player " + (players.Count - 1) + " is joining in the " + ((players.Count - 1) % 2 == 0 ? Team.FIRST : Team.SECOND) + " team."); } contract = new Contract(); }
/// <summary> /// Counts the score. /// </summary> private void countScore() { int team1 = 0; int team2 = 0; GameManager.SendAll(players, " "); foreach (Player i in players) { i.countScore(); GameManager.SendAll(players, "Player " + i.getId() + " of the " + i.getTeam() + " team got " + i.getScore() + " points."); if (i.getTeam() == Team.FIRST) { team1 += i.getScore(); } else { team2 += i.getScore(); } } GameManager.SendAll(players, "\n" + Team.FIRST + " team got " + team1 + " points."); GameManager.SendAll(players, Team.SECOND + " team got " + team2 + " points."); }
/// <summary> /// Whos the won. /// </summary> /// <returns>The won.</returns> /// <param name="board">Board.</param> private int whoWon(List <Card> board) { int winner = -1; for (int i = 0; i != board.Count; i += 1) { if (i == 0) { winner = i; } else { if (board.ElementAt(i).getColor() == contract.getColor()) { if (board.ElementAt(winner).getColor() == contract.getColor()) { if (Array.IndexOf(Card.withAsset, board.ElementAt(i).getValue()) > Array.IndexOf(Card.withAsset, board.ElementAt(winner).getValue())) { winner = i; } } else { winner = i; } } else if (board.ElementAt(winner).getColor() != contract.getColor() && Array.IndexOf(Card.withAsset, board.ElementAt(i).getValue()) > Array.IndexOf(Card.withoutAsset, board.ElementAt(winner).getValue())) { winner = i; } } } GameManager.SendAll(players, "\n *** Player " + winner + " won this round. *** \n"); players.ElementAt(winner).addWonTrick(board); return(winner); }