Пример #1
0
        /// <summary>
        /// 开始游戏的请求
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateGame_Click(object sender, EventArgs e)
        {
            //新建游戏的时候,已经决定游戏的先后手
            if (!String.IsNullOrEmpty(txtServerIP.Text))
            {
                TcpSocketServer.strIP = txtServerIP.Text;
            }
            if (!String.IsNullOrEmpty(txtNickName.Text))
            {
                GameManager.MyClientManager.PlayerNickName = txtNickName.Text;
            }
            if (String.IsNullOrEmpty(cmbCardDeck.Text))
            {
                MessageBox.Show("请选择套牌");
                return;
            }
            SystemManager.游戏类型 = Engine.Utility.SystemManager.GameType.客户端服务器版;
            GameManager.MyClientManager.actionStatus.IsHost = true;
            String GameId = ClientRequest.CreateGame(GameManager.MyClientManager.PlayerNickName);

            Engine.Utility.CardUtility.Init(txtCardPath.Text);
            GameManager.MyClientManager.GameId = int.Parse(GameId);
            var CardList = GetCardDeckList();

            ClientRequest.SendDeck(GameManager.MyClientManager.GameId.ToString(GameServer.GameIdFormat), GameManager.MyClientManager.actionStatus.IsHost, CardList);
            btnJoinGame.Enabled   = false;
            btnRefresh.Enabled    = false;
            btnCreateGame.Enabled = false;
            int Count = 0;

            while (!ClientRequest.IsGameStart(GameManager.MyClientManager.GameId.ToString(GameServer.GameIdFormat)) && Count <= 10)
            {
                Thread.Sleep(3000);
                Count++;
            }
            if (Count == 11)
            {
                MessageBox.Show("找不到对手");
            }
            else
            {
                GameManager.MyClientManager.IsFirst = ClientRequest.IsFirst(GameManager.MyClientManager.GameId.ToString(GameServer.GameIdFormat), true);
                GameManager.MyClientManager.IsStart = true;
                this.Close();
            }
        }