Esempio n. 1
0
        // 定义线程方法:等待人的叫分信息
        private void waitPeopleCallScore(object msg)
        {
            try {
                //等待玩家叫分的时间,如果玩家在指定时间内没有叫分,认为玩家那方出现问题,设置玩家离线
                ThreadMsg threadMsg = (ThreadMsg)msg;
                Thread.Sleep(threadMsg.waitTime);

                lobby.players[threadMsg.curPeople].setLeaveState();
                //设置随机的叫分
                CallScoreProcess.callScore(0, ref lobby.players[threadMsg.curPeople]);
            }
            catch (Exception e) {
            }
        }
Esempio n. 2
0
        // 定义线程方法:等待人的出牌信息
        private void waitPeopleOutCard(object msg)
        {
            try {
                //等待玩家出牌的时间,如果玩家在指定时间内没有出牌,认为玩家那方出现问题,设置玩家离线
                ThreadMsg threadMsg = (ThreadMsg)msg;
                Thread.Sleep(threadMsg.waitTime);

                lobby.players[threadMsg.curPeople].setLeaveState();
                //设置AI为其出牌
                AIoutCard(threadMsg.curPeople);
            }
            catch (Exception e) {
            }
        }
Esempio n. 3
0
        //游戏进程执行
        private void executeProcess()
        {
            switch (step)
            {
            //游戏开始
            case GameProcessEnum.GAME_START: {
                //初始化peoples和cardPile
                for (int i = 0; i < 4; i++)
                {
                    peoples[i] = new People();
                }
                cardPile = new List <Card>();

                //洗牌,将卡发给四个人,留8张底牌
                peopleOperator.shuffle(peoples, cardPile);
                //给每个人发卡组信息和底牌信息
                string msg = "[";
                for (int i = 0; i < 4; i++)
                {
                    msg += JsonHelper.sendCards("deck" + i, peoples[i].deck) + ",";
                }
                msg += JsonHelper.sendCards("cardPile", cardPile) + "]";
                lobby.sendMesToAllPlayers(msg);

                //随机叫分的第一人
                firstCallScore = random.Next(4);
                curCallScore   = firstCallScore;
                //将消息发给四个人
                lobby.sendMesToAllPlayers(JsonHelper.jsonObjectInt("firstCallScore", firstCallScore));
            }
            break;

            //进入叫分环节(叫分阶段结束)
            case GameProcessEnum.CALL_SCORE: {
                startCallScore = true;
                int nowPeople = curCallScore;           //记录当前的玩家
                curCallScore = (curCallScore + 1) % 4;  //轮到下一位玩家

                //计算当前人叫分的时间(断线重连使用)
                timeCount.Restart();

                //如果当前玩家处于断线状态或它是机器人,则自动认为不叫(等待一段时间)
                if (lobby.players[nowPeople] == null || lobby.players[nowPeople].playerEnum != PlayerEnum.PLAYING)
                {
                    System.Timers.Timer t = new System.Timers.Timer(Constants.WAIT_AUTO_CALLSCORE_OUTCARD);
                    t.AutoReset = false;
                    t.Enabled   = true;
                    t.Elapsed  += new ElapsedEventHandler(delegate(object sender, ElapsedEventArgs e) {
                            //在其他地方已经把process给desroy了
                            if (lobby != null)
                            {
                                if (lobby.players[nowPeople] == null || lobby.players[nowPeople].playerEnum != PlayerEnum.PLAYING)
                                {
                                    //如果是电脑可以不只是叫0分
                                    int callScore =
                                        lobby.players[nowPeople] != null && lobby.players[nowPeople].playerEnum == PlayerEnum.ROBOT
                                    ? random.Next(4 - intergation) + intergation + 1 : 0;
                                    callScore = callScore > 3 ? 0 : callScore;
                                    CallScoreProcess.callScore(callScore, ref lobby.players[nowPeople]);
                                }
                                else
                                {
                                    autoCallScoreThread[nowPeople] = new Thread(waitPeopleCallScore);
                                    timeCount.Stop();
                                    ThreadMsg threadMsg = new ThreadMsg(nowPeople, Constants.WAIT_PEOPLE_CALL_SCORE - (int)timeCount.ElapsedMilliseconds / 1000);
                                    timeCount.Start();
                                    autoCallScoreThread[nowPeople].Start(threadMsg);
                                }
                            }
                        });
                }
                //否则开启一个线程,如果玩家没能在指定时间内叫分,则自动叫分
                else
                {
                    autoCallScoreThread[nowPeople] = new Thread(waitPeopleCallScore);
                    ThreadMsg threadMsg = new ThreadMsg(nowPeople, Constants.WAIT_PEOPLE_CALL_SCORE);
                    autoCallScoreThread[nowPeople].Start(threadMsg);
                }
            }
            break;

            //进入出牌阶段(出牌阶段结束)
            case GameProcessEnum.OUT_CARD: {
                startOutCard = true;
                int nowPeople = curOutCard;           //记录当前的玩家
                curOutCard = (curOutCard + 1) % 4;    //轮到下一位玩家

                //计算当前人出牌的时间(断线重连使用)
                timeCount.Restart();

                //如果当前玩家处于断线状态,则自动出牌
                if (lobby.players[nowPeople] == null || lobby.players[nowPeople].playerEnum != PlayerEnum.PLAYING)
                {
                    System.Timers.Timer t = new System.Timers.Timer(Constants.WAIT_AUTO_CALLSCORE_OUTCARD);
                    t.AutoReset = false;
                    t.Enabled   = true;
                    t.Elapsed  += new ElapsedEventHandler(delegate(object sender, ElapsedEventArgs e) {
                            //在其他地方已经把process给desroy了
                            if (lobby != null)
                            {
                                if (lobby.players[nowPeople] == null || lobby.players[nowPeople].playerEnum != PlayerEnum.PLAYING)
                                {
                                    AIoutCard(nowPeople);
                                }
                                else
                                {
                                    autoOutCardThread[nowPeople] = new Thread(waitPeopleOutCard);
                                    timeCount.Stop();
                                    ThreadMsg threadMsg = new ThreadMsg(nowPeople, Constants.WAIT_PEOPLE_OUT_CARD - (int)timeCount.ElapsedMilliseconds / 1000);
                                    timeCount.Start();
                                    autoOutCardThread[nowPeople].Start(threadMsg);
                                }
                            }
                        });
                }
                //否则开启一个线程,如果玩家没能在指定时间内出牌,则自动为其出牌,并设置托管
                else
                {
                    autoOutCardThread[nowPeople] = new Thread(waitPeopleOutCard);
                    ThreadMsg threadMsg = new ThreadMsg(nowPeople, Constants.WAIT_PEOPLE_OUT_CARD);
                    autoOutCardThread[nowPeople].Start(threadMsg);
                }
            }
            break;
            }

            //如果是游戏开始状态,执行一次直接进入下一状态
            if (step == GameProcessEnum.GAME_START)
            {
                processUpdate();
            }
        }