示例#1
0
        /// <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());
        }
示例#2
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="client">The client.</param>
        public ChessServerPlayer(ChessServer server, TcpClientHandler client)
        {
            this.Actions = new Dictionary<string, Action<string>>
            {
                {"ListPlayers", ActionListPlayers},
                {"Quit",        ActionPlayerQuit},
                {"Play",        ActionPlay},
                {"PlayOk",      ActionPlayOk},
                {"SetName",     ActionSetName},
                {"Game",        ActionGame},
                {"Send",        ActionSend}
            };

            this.Server = server;
            client.MessageReceived += MessageReceived;
            client.Disconnected += Disconnected;
            this.Client = client;
            this.Client.PingInterval = 2000;
        }
示例#3
0
文件: Program.cs 项目: mygibbs/Chess
        public static void Main(string[] args)
        {
            InteractiveConsole IConsole = new InteractiveConsole();
            Logger = new Logger(s => IConsole.WriteLine(s));

            string[] quitMsgs = new string[] { "QUIT", "STOP", "EXIT", "END", "Q" };

            using (Server = new CS.ChessServer(1337.To(13337), Logger, true))
            {
                string msg = null;

                do
                {
                    msg = IConsole.ReadCommand().Trim().ToUpper();
                    ParseMessage(msg);
                } while (!quitMsgs.Contains(msg));
            }

            Environment.Exit(0);
        }