示例#1
0
        public void Run()
        {
            TcpClient     client = null;
            NetworkStream ns     = null;
            Player        player = game.Player2;

            try
            {
                client = new TcpClient();
                client.Connect(new IPEndPoint(IPAddress.Parse(server), port));
                ns = client.GetStream();
                view.AddToLog(String.Format("Подключен к серверу {0}:{1}\nИграем за черных", server, port));
                WriteString(ns, player.Name);
                WriteInt(ns, player.GetWin());
                WriteInt(ns, player.GetLose());
                // get first player
                player = game.Player1;
                string playername = ReadString(ns);
                int    lose, win;
                win         = ReadInt(ns);
                lose        = ReadInt(ns);
                player.Name = playername;
                player.SetStatistic(win, lose);
                view.Invoke(new Action(() => game.ClientGameView()));
                CommandLoop(ns, view, game);
            }
            catch (Exception e) {
                view.Message(e.Message);
            }
            finally
            {
                if (ns != null)
                {
                    ns.Close();
                }
                if (client != null)
                {
                    client.Close();
                }
            }
        }