Example #1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            DConsole.IsStart = true;
            if (this.server != null)
            {
                for (int i = 3; i < 18; i++)  //嵌套for循环初始化54张牌
                {
                    for (int j = 1; j < 5; j++)
                    {
                        if (i <= 15)
                        {
                            DConsole.allPoker.Add(new Poker((PokerNum)i, (PokerColor)j));
                        }
                    }
                    if (i >= 16)
                    {
                        DConsole.allPoker.Add(new Poker((PokerNum)i, PokerColor.黑桃));
                    }
                }                           //嵌套for循环初始化54张牌

#if DEBUG
                Console.WriteLine(DConsole.allPoker.Count);
                foreach (Poker onePoker in DConsole.allPoker)
                {
                    Console.WriteLine(onePoker.pokerColor.ToString() + onePoker.ToString());
                }
#endif
                if (!DConsole.IsRestart)
                {
                    server.SendDataForClient("YouAreClient1", 1);
                }
                DConsole.shuffle();                                  //洗牌
                DConsole.deal();                                     //发牌
                this.player1.sort();                                 //把牌从大到小排序
                this.player1.g = this.panelPlayer1.CreateGraphics(); //把panelPlayer1的Graphics传递给player1
                this.player1.Paint();                                //在panelPlayer1中画出player1的牌
                this.player2.sort();
                this.player3.sort();
                server.SendDataForClient("SPokerCount" + "17", 1);
                Thread.Sleep(200);
                server.SendDataForClient("SPokerCount" + "17", 2);
                Thread.Sleep(200);
                server.SendDataForClient("PokerCount" + "17", 1);
                Thread.Sleep(200);
                server.SendDataForClient("PokerCount" + "17", 2);
                Thread.Sleep(200);
                DConsole.PaintClient(17, 1);
                DConsole.PaintClient(17, 2);
                DConsole.PaintLandLord(false);
                //this.panelPlayer1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.panelPlayer1_MouseClick); //给panelPlayer1添加一个点击事件
                this.btnStart.Enabled = false;
                this.btnStart.Visible = false;
            }
        }
Example #2
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
        }