/// <summary> /// The constructor. /// </summary> /// <param name="server">The server.</param> /// <param name="white">The white player.</param> /// <param name="black">The black player.</param> public ChessServerGame(ChessServer server, ChessServerPlayer white, ChessServerPlayer black) { this.Actions = new Dictionary<string, Action<TcpClientHandler, string>> { {"Move", ActionMove}, {"Send", ActionSend} }; this.Server = server; this.Board = new ChessBoard(); this.Board.GameEnded += (b, w) => { this.Results = w; }; this.WhitePlayer = white; this.BlackPlayer = black; this.WhitePlayer.Client.Disconnected += PlayerDisconnected; this.BlackPlayer.Client.Disconnected += PlayerDisconnected; this.WhitePlayer.Client.SendMessage("Welcome White " + this.BlackPlayer.ToString()); this.BlackPlayer.Client.SendMessage("Welcome Black " + this.WhitePlayer.ToString()); this.NextTurn(); this.Server.Logger.Log("Game created: " + this.ToString()); }
/// <summary> /// Sends a list of all the players to the specifed client, except for himself. /// </summary> /// <param name="client">The specified client.</param> private void SendAllPlayers(ChessServerPlayer client) { StringBuilder sb = new StringBuilder("ListPlayers "); foreach (ChessServerPlayer c in this.Clients.Where(c => c != client && !this.Games.Any(g => g.BlackPlayer == c || g.WhitePlayer == c))) { c.ToString(sb); sb.AppendLine(); } client.Client.SendMessage(sb.ToString()); }