Ejemplo n.º 1
0
        //改变状态前的初始化
        private void initProcessUpdate()
        {
            switch (next_step)
            {
            //游戏开始阶段的初始化
            case GameProcessEnum.GAME_START: {
                firstCallScore = -1;
                intergation    = 0;
                whoIsLand      = -1;
                startCallScore = false;
                startOutCard   = false;
            }
            break;

            case GameProcessEnum.CALL_SCORE: {
                for (int i = 0; i < 4; i++)
                {
                    fourCallScore[i] = -1;
                }
            }
            break;

            //出牌阶段前的初始化
            case GameProcessEnum.OUT_CARD: {
                //地主先出牌
                whoOut     = whoIsLand;
                curOutCard = whoOut;
                //初始化四人的出牌队列
                for (int i = 0; i < 4; i++)
                {
                    outCards[i] = null;
                }
                //给地主8张牌
                peopleOperator.dealCardToLandlord(peoples, cardPile, whoIsLand);
            }
            break;
            }

            if (next_step != GameProcessEnum.NONE)
            {
                step = next_step;
            }
            //如果下一步为叫分环节,等待客户端发牌动画结束,开始计时叫分
            if (next_step == GameProcessEnum.CALL_SCORE)
            {
                System.Timers.Timer t = new System.Timers.Timer(Constants.DIDPLAY_DEAL_CARD);
                t.AutoReset = false;
                t.Enabled   = true;
                t.Elapsed  += new ElapsedEventHandler(delegate(object sender, ElapsedEventArgs e) {
                    //执行叫分环节
                    processExecute();
                });
            }
        }
Ejemplo n.º 2
0
        //游戏进程的更新
        public void processUpdate()
        {
            switch (step)
            {
            //游戏开始
            case GameProcessEnum.GAME_START: {
                //进入下一步的叫分环节
                next_step = GameProcessEnum.CALL_SCORE;

                //四名玩家同时进入叫分阶段
                for (int i = 0; i < 4; i++)
                {
                    //如果该玩家不是机器人(离线的玩家也要对其状态进行更新)
                    if (lobby.players[i].playerEnum != PlayerEnum.ROBOT && lobby.players[i].playerEnum != PlayerEnum.OFFLINE)
                    {
                        lobby.players[i].curServerDeal.next_step = ServerProcess.CALL_SCORE_PROCESS;
                        lobby.players[i].curServerDeal.initProcessUpdate();
                    }
                }
            }
            break;

            //进入叫分环节(叫分阶段结束)
            case GameProcessEnum.CALL_SCORE: {
                if (intergation >= 3 || curCallScore % 4 == firstCallScore || reCallScoreNum == MAX_RE_CALLSCORE_NUM - 1)
                {
                    //停止计时
                    timeCount.Stop();

                    //已经连续三局没人叫地主了,强制要求一个人当地主
                    if (reCallScoreNum == MAX_RE_CALLSCORE_NUM - 1 && intergation == 0)
                    {
                        reCallScoreNum = 0;
                        //随机指定一个地主,叫分为1
                        intergation = 1;
                        whoIsLand   = random.Next(4);
                        CallScoreProcess.setLandlord(whoIsLand, ref lobby);
                    }

                    //如果当前有人叫分
                    if (intergation > 0)
                    {
                        next_step = GameProcessEnum.OUT_CARD;
                        //四名玩家同时进入出牌阶段(离线的玩家也要对其状态进行更新)
                        for (int i = 0; i < 4; i++)
                        {
                            if (lobby.players[i].playerEnum != PlayerEnum.ROBOT && lobby.players[i].playerEnum != PlayerEnum.OFFLINE)
                            {
                                lobby.players[i].curServerDeal.next_step = ServerProcess.OUT_CARD_PROCESS;
                                lobby.players[i].curServerDeal.initProcessUpdate();
                            }
                        }
                    }
                    //如果当前没人叫分,则重新开始(三局之内)
                    else if (reCallScoreNum < MAX_RE_CALLSCORE_NUM - 1)
                    {
                        //当前叫分轮数加一
                        reCallScoreNum++;
                        next_step = GameProcessEnum.GAME_START;
                    }
                }
            }
            break;

            //进入出牌阶段(出牌阶段结束)
            case GameProcessEnum.OUT_CARD: {
                //停止计时
                timeCount.Stop();

                //进行积分结算
                peopleOperator.settleScore(peoples, intergation);

                //如果玩家不为机器人,将结算完的积分写入数据库
                for (int i = 0; i < 4; i++)
                {
                    if (lobby.players[i] != null && lobby.players[i].playerEnum != PlayerEnum.ROBOT)
                    {
                        string username = lobby.players[i].username;
                        int    score    = peoples[i].integration;
                        SqlDbHelper.ExecuteNonQuery
                            ("update user_table set score = " + score + " where username = '******'");
                    }
                }

                //房间对剩余玩家进行处理,如果还剩玩家,将其放入大厅中,如果不剩,做销毁处理
                if (lobby.dealTurnGame() == false)
                {
                    destroyGameProcessDeal();
                    return;
                }

                //积分结算完等待下一局游戏开始
                next_step = GameProcessEnum.GAME_START;
            }
            break;
            }

            //改变状态前的初始化
            initProcessUpdate();
        }