예제 #1
0
        public void reset()
        {
            this.setStatus(RoomStatusByDdz.GAME_WAIT_START);

            this._matchResult = MATCH_RESULT.EMPTY;

            //椅子上也许还有人哦
            //因此只还原ready
            setReadyForAllChair(false);

            setReadyAddForAllChair("");         

            //红方和黑方,如果人未离开,不用改

            this.difen = "";
            this.bomb = 0; this.leaveBomb = 0; this.leaveUserId = "";
            this.dizhu = "";
            this.nongming = "";
            this.mingpai = "";
            this.turn = "";

            //棋盘 reset
            this._board = new PaiBoardByDdz();

            //棋子移动 reset
            this._record = new RoundModelByDdz(ROUND_TYPE.JIAO_FEN);

            //回合信息 reset
            this._round = new List<RoundModelByDdz>();

            _isWaitReconnection = false;
            _curWaitReconnectionTime = 0;

            this.setWaitReconnection(null);
            //_waitReconnectionUser = null;
        }
예제 #2
0
        public RoomModelByDdz(int id, IRuleModel rule, int tab, string gridXml)
        {
            
            this._id = id;

            this._tab = tab;

            if ("" == gridXml)
            {
                this._name = string.Empty;
            }
            else
            {
                XmlDocument gridDoc = new XmlDocument();
                gridDoc.LoadXml(gridXml);

                this._name = gridDoc.DocumentElement.Attributes["name"].Value;

            }

            this.setStatus(RoomStatusByDdz.GAME_WAIT_START);

            this._matchResult = MATCH_RESULT.EMPTY;

            this._chair = new List<IChairModel>();

            for (int i = 1; i <= rule.getChairCount(); i++)
            {
                this._chair.Add(ChairModelFactory.Create(i, rule));

            }//end for

            //red = "";
            //black = "";

            this.difen = "";
            this.bomb = 0; this.leaveBomb = 0; this.leaveUserId = "";
            this.dizhu = "";
            this.nongming = "";
            this.mingpai = "";
            this.turn = "";

            this._board = new PaiBoardByDdz();
            this._record = new RoundModelByDdz(ROUND_TYPE.JIAO_FEN);
            this._round = new List<RoundModelByDdz>();

            _runAwayMultiG = 1;

            _isWaitReconnection = false;
            _curWaitReconnectionTime = 0;

            _waitReconnectionUser = null;

        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        
        public void setJiaoFen(string value)
        {
            //
            string[] sp = value.Split(',');

            string userId = sp[0];
            int fen = Convert.ToInt32(sp[1]);

            //底分最多为3分
            if (fen > PAI_RULE.JF_MAXVALUE)
            {
                fen = PAI_RULE.JF_MAXVALUE;
            }

            //loop use
            int i = 0;
            int len = this._chair.Count;

            //save
            for (i = 0; i < len; i++)
            {
                if (this._chair[i].getUser().Id == userId)
                {
                    //判断一圈结束,save and new
                    if (this._record.isFull())
                    {
                        this._round.Add(this._record);
                        this._record = new RoundModelByDdz(ROUND_TYPE.JIAO_FEN);
                    }

                    this._record.setFen(fen, userId); // set player

                    //record在后面的使用时注意要判断empty
                    //保存时注意要先逻辑判断完后再保存

                    //-------------------------------------------------------------------

                    if (RoomStatusByDdz.GAME_START == this.getStatus())
                    {
                        //3圈全部不叫
                        if (2 == this._round.Count &&
                            false == this._record.isEmpty() &&
                            "" != this._record.clock_three)
                        {
                            //check
                            if (PAI_RULE.JF_MINVALUE == (this._round[0] as RoundModelByDdz).clock_one_jiaofen &&
                                PAI_RULE.JF_MINVALUE == (this._round[0] as RoundModelByDdz).clock_two_jiaofen &&
                                PAI_RULE.JF_MINVALUE == (this._round[0] as RoundModelByDdz).clock_three_jiaofen &&

                                PAI_RULE.JF_MINVALUE == (this._round[1] as RoundModelByDdz).clock_one_jiaofen &&
                                PAI_RULE.JF_MINVALUE == (this._round[1] as RoundModelByDdz).clock_two_jiaofen &&
                                PAI_RULE.JF_MINVALUE == (this._round[1] as RoundModelByDdz).clock_three_jiaofen &&

                                PAI_RULE.JF_MINVALUE == this._record.clock_one_jiaofen &&
                                PAI_RULE.JF_MINVALUE == this._record.clock_two_jiaofen &&
                                PAI_RULE.JF_MINVALUE == this._record.clock_three_jiaofen)
                            {
                                
                                this.setStatus( RoomStatusByDdz.GAMEOVER_ROOMCLEAR_WAIT_START);
                                this._round.Add(this._record);
                                //reset里会new
                                return;
                            }
                        }//end if


                        //判断3分
                        //满3分当即决出地主
                        if (PAI_RULE.JF_MAXVALUE == fen)
                        {
                            this.dizhu = userId;
                            this.difen = Convert.ToString(fen);

                            //nongming
                            List<IChairModel> users = this.findUser(this._chair[i].getUser());
                            
                            //
                            this.setNongMing(users);

                            //
                            this.setStatus(RoomStatusByDdz.GAME_START_CAN_GET_DIZHU);
                            this._round.Add(this._record);//这可能是个不完整的档
                            this._record = new RoundModelByDdz(ROUND_TYPE.CHU_PAI);
                            
                            return;
                        }

                        if (PAI_RULE.JF_MAXVALUE > fen)//不满3分
                        {
                            //不满3分,且不是最后一个,继续
                            if ("" == this._record.clock_three)
                            {
                                return;
                            }
                            else
                            {
                                //此圈都不叫
                                if (PAI_RULE.JF_MINVALUE == this._record.clock_one_jiaofen &&
                                   PAI_RULE.JF_MINVALUE == this._record.clock_two_jiaofen &&
                                   PAI_RULE.JF_MINVALUE == this._record.clock_three_jiaofen)
                                {
                                    return;

                                }
                                else
                                {
                                    //此圈有至少一个叫,且已经满一圈
                                    //决出地主                                   

                                    //一轮完毕,有叫分,叫分不能重复
                                    int maxJf = MathUtil.selecMaxNumber(this._record.clock_one_jiaofen,
                                                         this._record.clock_two_jiaofen,
                                                         this._record.clock_three_jiaofen);

                                    if (maxJf == this._record.clock_one_jiaofen)
                                    {
                                        this.dizhu = this._record.clock_one;
                                        this.difen = Convert.ToString(maxJf);

                                        //nongming
                                        List<IChairModel> users = this.findUser(this._record.clock_one);
                                        this.setNongMing(users);

                                    }
                                    else if (maxJf == this._record.clock_two_jiaofen)
                                    {
                                        this.dizhu = this._record.clock_two;
                                        this.difen = Convert.ToString(maxJf);

                                        List<IChairModel> users = this.findUser(this._record.clock_two);
                                        this.setNongMing(users);
                                    }
                                    else if (maxJf == this._record.clock_three_jiaofen)
                                    {
                                        this.dizhu = this._record.clock_three;
                                        this.difen = Convert.ToString(maxJf);

                                        List<IChairModel> users = this.findUser(this._record.clock_three);
                                        this.setNongMing(users);
                                    }
                                    else
                                    {
                                        throw new ArgumentException("can not find max jiao fen");
                                    }

                                    //
                                    this.setStatus(RoomStatusByDdz.GAME_START_CAN_GET_DIZHU);
                                    //操作完再save,此为断挡
                                    this._round.Add(this._record);
                                    this._record = new RoundModelByDdz(ROUND_TYPE.CHU_PAI);
                                }

                            }
                        }


                    }//end if

                    break;

                }//end if

            }//end for 
        }
예제 #4
0
        private string ByRecord(Dictionary<string, string> rd, RoundModelByDdz _round_j)
        {

            if ("" != _round_j.clock_one)
            {
                if (!rd.ContainsValue(_round_j.clock_one) &&
                   !rd.ContainsKey("A"))
                {
                    rd.Add("A", _round_j.clock_one);
                }

                if (!rd.ContainsValue(_round_j.clock_one) &&
                    !rd.ContainsKey("B"))
                {
                    rd.Add("B", _round_j.clock_one);
                }

                if (!rd.ContainsValue(_round_j.clock_one) &&
                    !rd.ContainsKey("C"))
                {
                    rd.Add("C", _round_j.clock_one);
                }
            }

            if ("" != _round_j.clock_two)
            {
                if (!rd.ContainsValue(_round_j.clock_two) &&
                   !rd.ContainsKey("A"))
                {
                    rd.Add("A", _round_j.clock_two);
                }

                if (!rd.ContainsValue(_round_j.clock_two) &&
                    !rd.ContainsKey("B"))
                {
                    rd.Add("B", _round_j.clock_two);
                }

                if (!rd.ContainsValue(_round_j.clock_two) &&
                    !rd.ContainsKey("C"))
                {
                    rd.Add("C", _round_j.clock_two);
                }
            }

            if ("" != _round_j.clock_three)
            {
                if (!rd.ContainsValue(_round_j.clock_three) &&
                   !rd.ContainsKey("A"))
                {
                    rd.Add("A", _round_j.clock_three);
                }

                if (!rd.ContainsValue(_round_j.clock_three) &&
                    !rd.ContainsKey("B"))
                {
                    rd.Add("B", _round_j.clock_three);
                }

                if (!rd.ContainsValue(_round_j.clock_three) &&
                    !rd.ContainsKey("C"))
                {
                    rd.Add("C", _round_j.clock_three);
                }
            }

            string rj = _round_j.toXMLSting();

            //replace
            if(rd.ContainsKey("A"))
            {
                rj = rj.Replace(rd["A"], "A");
            }

            if(rd.ContainsKey("B"))
            {
                rj = rj.Replace(rd["B"], "B");
            }

            if (rd.ContainsKey("C"))
            {
                rj = rj.Replace(rd["C"], "C");
            }

            return rj;
        
        }
예제 #5
0
        /// <summary>
        /// round
        /// board
        /// </summary>
        /// <param name="value"></param>        
        public void setChuPai(string value)
        {
            //loop use
            int i = 0;

            string[] sp = value.Split(',');

            string userId = sp[0];

            //如果是炸弹则记录
            int spLen = sp.Length;

            if (5 == spLen || 
                3 == spLen)
            {
                //List<int> pcArr = new List<int>();
                List<int> pcArr = new List<int>(spLen-1);

                for (i = 1; i < spLen; i++)
                { 
                    pcArr.Add(PaiCode.convertToCode(sp[i]));
                }

                //王炸(火箭)用户要求也算炸弹
                if (PaiRuleCompare.validate_bomb(pcArr) ||
                    PaiRuleCompare.validate_huojian(pcArr))
                {
                    this.bomb++;
                }
            }

            //
            //判断一圈结束,save and new
            if (this._record.isFull())
            {
                this._round.Add(this._record);
                this._record = new RoundModelByDdz(ROUND_TYPE.CHU_PAI);
            }

            string pai = string.Empty;

            //
            spLen = sp.Length;

            for (i = 1; i < spLen; i++)
            {
                pai += sp[i];
                pai += ",";

            }

            this._record.setPai(pai, userId); // set player

           //board
            spLen = sp.Length;

            for (i = 1; i < spLen; i++)
            {
                this._board.update(sp[i],"del");
            }
        
        }