Esempio n. 1
0
        /// <summary>
        /// 发牌
        /// </summary>
        public static void deal()
        {
            PokerGroup player2Pokers = new PokerGroup();
            PokerGroup player3Pokers = new PokerGroup();

            player1.pokers.Clear();
            for (int i = 0; i < 17; i++)
            {
                player1.pokers.Add(allPoker[i]);
            }
            for (int i = 17; i < 34; i++)
            {
                player2Pokers.Add(allPoker[i]);
            }
            for (int i = 34; i < 51; i++)
            {
                player3Pokers.Add(allPoker[i]);
            }
            LandLordNum = new Random().Next(1, 4);
            PokerGroup landLordPokers = new PokerGroup();

            for (int i = 51; i < 54; i++)
            {
                landLordPokers.Add(allPoker[i]);
            }
            LandLordPokers = landLordPokers;
            player1.sort();
            if (server.SendDataForClient("StartPokers", player2Pokers, 1) && server.SendDataForClient("StartPokers", player3Pokers, 2))
            {
                DConsole.Write("[系统消息]发牌成功!");
                server.SendOrder(LandLordNum);
            }
            //if (server.SendDataForClient(player2.pokers, 1) && server.SendDataForClient(player3.pokers, 2))
            //{
            //    DConsole.Write("[系统消息]发牌成功!");
            //    server.SendOrder(DConsole.LandLordNum);
            //}
            else
            {
                DConsole.Write("[系统消息]发牌失败!");
            }

#if DEBUG //调试时在Console上显示的信息
            Console.WriteLine("玩家一的牌");
            foreach (Poker onePoker in player1.pokers)
            {
                Console.WriteLine(onePoker.pokerColor.ToString() + onePoker.ToString());
            }
#endif
        }
Esempio n. 2
0
        /// <summary>
        /// 对飞机和飞机带翅膀进行排序,把飞机放在前面,翅膀放在后面.
        /// </summary>
        /// <param name="PG">牌组</param>
        /// <returns>是否为连续三张牌</returns>
        public static PokerGroup SameThreeSort(PokerGroup PG)
        {
            Poker      FourPoker      = null;             //如果把4张当三张出并且带4张的另外一张,就需要特殊处理,这里记录出现这种情况的牌的点数.
            bool       FindedThree    = false;            //已找到三张相同的牌
            PokerGroup tempPokerGroup = new PokerGroup(); //记录三张相同的牌
            int        count          = 0;                //记录在连续三张牌前面的翅膀的张数
            int        Four           = 0;                // 记录是否连续出现三三相同,如果出现这种情况则表明出现把4张牌(炸弹)当中的三张和其他牌配成飞机带翅膀,并且翅膀中有炸弹牌的点数.

            // 比如有如下牌组: 998887777666 玩家要出的牌实际上应该为 888777666带997,但是经过从大到小的排序后变成了998887777666 一不美观,二不容易比较.
            for (int i = 2; i < PG.Count; i++)                //直接从2开始循环,因为PG[0],PG[1]的引用已经存储在其他变量中,直接比较即可
            {
                if (PG[i] == PG[i - 2] && PG[i] == PG[i - 1]) // 比较PG[i]与PG[i-1],PG[i]与PG[i-2]是否同时相等,如果相等则说明这是三张相同牌
                {
                    if (Four >= 1)                            //默认的Four为0,所以第一次运行时这里为false,直接执行else
                                                              //一旦连续出现两个三三相等,就会执行这里的if
                    {
                        FourPoker = PG[i];                    //当找到四张牌时,记录下4张牌的点数
                        Poker changePoker;
                        for (int k = i; k > 0; k--)           //把四张牌中的一张移动到最前面.
                        {
                            changePoker = PG[k];
                            PG[k]       = PG[k - 1];
                            PG[k - 1]   = changePoker;
                        }
                        count++; //由于此时已经找到三张牌,下面为count赋值的程序不会执行,所以这里要手动+1
                    }
                    else
                    {
                        Four++;                    //记录本次循环,因为本次循环找到了三三相等的牌,如果连续两次找到三三相等的牌则说明找到四张牌(炸弹)
                        tempPokerGroup.Add(PG[i]); //把本次循环的PG[i]记录下来,即记录下三张牌的点数
                    }
                    FindedThree = true;            //标记已找到三张牌
                }
                else
                {
                    Four = 0;         //没有找到时,连续找到三张牌的标志Four归零
                    if (!FindedThree) //只有没有找到三张牌时才让count增加.如果已经找到三张牌,则不再为count赋值.
                    {
                        count = i - 1;
                    }
                }
            }
            foreach (Poker tempPoker in tempPokerGroup) //迭代所有的三张牌点数
            {
                Poker changePoker;                      //临时交换Poker
                for (int i = 0; i < PG.Count; i++)      //把所有的三张牌往前移动
                {
                    if (PG[i] == tempPoker)             //当PG[i]等于三张牌的点数时
                    {
                        if (PG[i] == FourPoker)         //由于上面已经把4张牌中的一张放到的最前面,这张牌也会与tempPoker相匹配所以这里进行处理
                                                        // 当第一次遇到四张牌的点数时,把记录四张牌的FourPoker赋值为null,并中断本次循环.由于FourPoker已经为Null,所以下次再次遇到四张牌的点数时会按照正常情况执行.
                        {
                            FourPoker = null;
                            continue;
                        }
                        changePoker   = PG[i - count];
                        PG[i - count] = PG[i];
                        PG[i]         = changePoker;
                    }
                }
            }
            return(PG);
        }