예제 #1
0
 //让AI帮其出牌
 private void AIoutCard(int nowPeople)
 {
     try {
         //设置AI为其出牌
         outCards[nowPeople] = peopleOperator.AIOutCard
                                   (peoples, whoIsLand, whoOut, nowPeople, whoOut == nowPeople ? null : outCards[whoOut]);
         string msg = JsonHelper.sendCards("outCard", outCards[nowPeople]);
         //模仿玩家发送消息
         OutCardProcess.receiveOutCardMsg(msg, ref lobby.players[nowPeople]);
     } catch (Exception e) {
         serverForm.server.ShowMsg(e.ToString());
     }
 }
예제 #2
0
        //服务器进程更新
        public void processUpdate()
        {
            //判断是不是心跳信息
            if (JudgeOtherInfo.judgeHeartBeatMsg(msg) == true)
            {
                return;
            }
            //判断是否为玩家离开的消息
            else if (JudgeOtherInfo.judgeLeaveMsg(msg) == true)
            {
                clientBreak(false);
                return;
            }

            switch (step)
            {
            //如果是登录状态(注册)(断线重连)
            case ServerProcess.LOGIN_PROCESS: {
                //登录验证阶段(分析登录是否成功,返回登录结果)
                LoginResult loginResult   = LoginResult.NONE;
                bool        isReconnected = false;
                string      senderLogin   = LoginProcess.startLogin(msg, ref loginResult, ref player, ref isReconnected);

                //向客户端发送登录是否成功
                sendMessange(senderLogin);

                //如果登录成功(如果为断线重连状态,由player中的函数进行状态跳转)
                if (loginResult == LoginResult.LOGIN_SUCCESS)
                {
                    //将已登录的用户存入到players中
                    serverForm.server.players.TryAdd(player.username, null);
                    //将当前进程赋给玩家
                    player.curServerDeal = this;
                    //下一步进入游戏大厅匹配环节
                    next_step = ServerProcess.MATCH_PROCESS;
                }
                else if (isReconnected)
                {
                    //将当前进程赋给玩家
                    player.curServerDeal = this;
                    //将自身接受的消息改为对应的状态
                    if (player.gameProcess.step == GameProcessEnum.CALL_SCORE)
                    {
                        next_step = ServerProcess.CALL_SCORE_PROCESS;
                    }
                    else if (player.gameProcess.step == GameProcessEnum.OUT_CARD)
                    {
                        next_step = ServerProcess.OUT_CARD_PROCESS;
                    }
                }
            }
            break;

            //如果是游戏大厅匹配阶段(个人信息修改)(断线重连)
            case ServerProcess.MATCH_PROCESS: {
                bool isMatched     = false;
                bool isReconnected = false;
                //创建匹配处理的进程
                string matchResult = MatchProcess.startMatch(msg, ref player, out isMatched, ref isReconnected);

                //向客户端发送匹配结果(成功,返回当前房间的状态)
                sendMessange(matchResult);

                //如果匹配成功(进入房间)(如果为断线重连状态,由player中的函数进行状态跳转)
                if (isMatched == true)
                {
                    next_step = ServerProcess.PREPARE_GAME_PROCESS;
                }
                else if (isReconnected)
                {
                    //将当前进程赋给玩家
                    player.curServerDeal = this;
                    //将自身接受的消息改为对应的状态
                    if (player.gameProcess.step == GameProcessEnum.CALL_SCORE)
                    {
                        next_step = ServerProcess.CALL_SCORE_PROCESS;
                    }
                    else if (player.gameProcess.step == GameProcessEnum.OUT_CARD)
                    {
                        next_step = ServerProcess.OUT_CARD_PROCESS;
                    }
                }
            }
            break;

            //如果是游戏房间准备阶段
            case ServerProcess.PREPARE_GAME_PROCESS: {
                //创建准备处理的进程
                PrepareGameProcess.startPrepareGame(msg, ref player);
                //向客户端发送匹配结果
                //sendMessange(prepareResult);
            }
            break;

            //游戏开始,接受叫分的信息(卡组信息已在GameProcess中发过)
            case ServerProcess.CALL_SCORE_PROCESS: {
                CallScoreProcess.receiveScoreMsg(msg, ref player);
            }
            break;

            //接受玩家的出牌信息(这局结束后由GameProcess进行步骤跳转,跳到PREPARE_GAME_PROCESS)
            case ServerProcess.OUT_CARD_PROCESS: {
                OutCardProcess.receiveOutCardMsg(msg, ref player);
            }
            break;
            }

            //改变状态前的初始化(跳入下一阶段)
            initProcessUpdate();
        }