Exemplo n.º 1
0
        /// <summary>
        /// 比较两张牌是否一致.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is PlayingCards))
            {
                // 数据类型不一致,直接返回.
                return(false);
            }

            // 类型装换.
            PlayingCards card = obj as PlayingCards;

            if (card.Suit != this.Suit)
            {
                // 花色不一致.
                return(false);
            }

            if (card.cardDisplayValue != this.cardDisplayValue)
            {
                // 点数不一致.
                return(false);
            }

            // 数据类型、花色、点数都一致.
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 显示一张牌.
        /// 初始化发牌2张.
        /// 需要显示一张.
        /// </summary>
        /// <param name="card"></param>
        public void ShowOneCard(PlayingCards card)
        {
            foreach (PlayingCards myCard in cardList)
            {
                if (myCard.Equals(card))
                {
                    myCard.IsShowOnTable = true;

                    // 多幅牌的情况下
                    // 万一拿到2张完全一样的
                    // 也是仅仅显示其中的一张.
                    break;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 开始发牌.
        /// </summary>
        public void StartGame()
        {
            // 遍历每一个玩家.
            foreach (Player player in playerList)
            {
                // 首先清理掉手上的牌.
                player.ClearPlayingCards();
            }


            // 初始情况下,发2张牌.
            for (int i = 0; i < 2; i++)
            {
                // 遍历每一个玩家.
                foreach (Player player in playerList)
                {
                    // 根据需要, 触发事件.
                    bool bCancel = false;
                    if (BeforeTakeOneCard != null)
                    {
                        BeforeTakeOneCard(player, ref bCancel);
                    }

                    // 扑克牌出队列.
                    PlayingCards card = playingCardsQueue.Dequeue();

                    // 扑克牌给玩家.
                    player.TakeOneCard(card);


                    // 根据需要, 触发事件.
                    if (AfterTakeOneCard != null)
                    {
                        AfterTakeOneCard(player, card);
                    }
                }
            }


            // 触发事件.
            if (AfterTakeFirstTwoCard != null)
            {
                AfterTakeFirstTwoCard();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 构造函数.
        /// </summary>
        public PlayingDeck()
        {
            // 初始化排列表.
            playingCardsList = new List<PlayingCards>();

            foreach (string val in PlayingCards.CardDisplayArray)
            {
                // 黑桃.
                PlayingCards card1 = new PlayingCards()
                {
                     Suit = Suit.Spades,
                     CardDisplayValue = val,
                };
                playingCardsList.Add(card1);

                // 红心
                PlayingCards card2 = new PlayingCards()
                {
                    Suit = Suit.Hearts,
                    CardDisplayValue = val,
                };
                playingCardsList.Add(card2);

                // 梅花.
                PlayingCards card3 = new PlayingCards()
                {
                    Suit = Suit.Clubs,
                    CardDisplayValue = val,
                };
                playingCardsList.Add(card3);

                // 方块.
                PlayingCards card4 = new PlayingCards()
                {
                    Suit = Suit.Diamonds,
                    CardDisplayValue = val,
                };
                playingCardsList.Add(card4);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 构造函数.
        /// </summary>
        public PlayingDeck()
        {
            // 初始化排列表.
            playingCardsList = new List <PlayingCards>();

            foreach (string val in PlayingCards.CardDisplayArray)
            {
                // 黑桃.
                PlayingCards card1 = new PlayingCards()
                {
                    Suit             = Suit.Spades,
                    CardDisplayValue = val,
                };
                playingCardsList.Add(card1);

                // 红心
                PlayingCards card2 = new PlayingCards()
                {
                    Suit             = Suit.Hearts,
                    CardDisplayValue = val,
                };
                playingCardsList.Add(card2);

                // 梅花.
                PlayingCards card3 = new PlayingCards()
                {
                    Suit             = Suit.Clubs,
                    CardDisplayValue = val,
                };
                playingCardsList.Add(card3);

                // 方块.
                PlayingCards card4 = new PlayingCards()
                {
                    Suit             = Suit.Diamonds,
                    CardDisplayValue = val,
                };
                playingCardsList.Add(card4);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 玩家 再拿一张牌。
        /// 玩家(包括闲家和庄家)只要手上牌相加点数不超过21点都可要牌。
        /// </summary>
        /// <param name="player"></param>
        public void PlayerHit(Player player)
        {
            if (player.GetPoint() <= MAX_POINT)
            {
                bool bCancel = false;
                // 根据需要, 触发事件.
                if (BeforeTakeOneCard != null)
                {
                    BeforeTakeOneCard(player, ref bCancel);
                }


                // 扑克牌出队列.
                PlayingCards card = playingCardsQueue.Dequeue();

                // 后续发的牌, 都要显示了.
                card.IsShowOnTable = true;

                // 扑克牌给玩家.
                player.TakeOneCard(card);



                // 根据需要, 触发事件.
                if (AfterTakeOneCard != null)
                {
                    AfterTakeOneCard(player, card);
                }


                if (player.GetPoint() >= MAX_POINT)
                {
                    // 暴了.
                    player.IsStand = true;
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 获取一张牌.
 /// </summary>
 /// <param name="card"></param>
 public void TakeOneCard(PlayingCards card)
 {
     cardList.Add(card);
 }
Exemplo n.º 8
0
        /// <summary>
        /// 显示一张牌.
        /// 初始化发牌2张.
        /// 需要显示一张.
        /// </summary>
        /// <param name="card"></param>
        public void ShowOneCard(PlayingCards card)
        {
            foreach (PlayingCards myCard in cardList)
            {
                if (myCard.Equals(card))
                {
                    myCard.IsShowOnTable = true;

                    // 多幅牌的情况下
                    // 万一拿到2张完全一样的
                    // 也是仅仅显示其中的一张.
                    break;
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// 获取一张牌.
 /// </summary>
 /// <param name="card"></param>
 public void TakeOneCard(PlayingCards card)
 {
     cardList.Add(card);
 }
Exemplo n.º 10
0
        /// <summary>
        /// 取得指定牌的图片.
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        private PictureBox GetDisplayPicBox(PlayingCards card)
        {
            string fileName = @"pic\BackGround.jpg";

            if (card.IsShowOnTable)
            {
                // 牌是要显示正面的.
                fileName = String.Format(@"pic\{0}_{1}.jpg",
                    card.Suit, card.CardDisplayValue);
            }

            PictureBox result = new PictureBox()
            {
                Dock = DockStyle.Fill,
                SizeMode = PictureBoxSizeMode.StretchImage,
                Image = new Bitmap(fileName),
            };

            return result;
        }