Exemplo n.º 1
0
        //---------------------------------------------------------------------
        public void Shuffle()
        {
            this.listOfCards = AllCards.Shuffle(Random).ToList();

            mapSameTypeCard = new Dictionary <CardTypeNiuNiu, List <Card> >();
            mapSameSuitCard = new Dictionary <CardSuit, List <Card> >();
            foreach (var i in listOfCards)
            {
                CardTypeNiuNiu card_type         = (CardTypeNiuNiu)i.Type;
                List <Card>    list_sametypecard = null;
                mapSameTypeCard.TryGetValue(card_type, out list_sametypecard);
                if (list_sametypecard == null)
                {
                    list_sametypecard          = new List <Card>();
                    mapSameTypeCard[card_type] = list_sametypecard;
                }

                list_sametypecard.Add(i);

                CardSuit    card_suit         = (CardSuit)i.Suit;
                List <Card> list_samesuitcard = null;
                mapSameSuitCard.TryGetValue(card_suit, out list_samesuitcard);
                if (list_samesuitcard == null)
                {
                    list_samesuitcard          = new List <Card>();
                    mapSameSuitCard[card_suit] = list_samesuitcard;
                }

                list_samesuitcard.Add(i);
            }
        }
Exemplo n.º 2
0
        //---------------------------------------------------------------------
        Card _getNextOrLastCardTypeCard(CardTypeNiuNiu card_type, CardSuit card_suit, bool is_same_suit, bool is_next)
        {
            Card           card          = null;
            CardTypeNiuNiu need_cardtype = CardTypeNiuNiu.Two;

            if (is_next)
            {
                int next_cardtype = ((int)card_type) + 1;
                if (next_cardtype == 15)
                {
                    need_cardtype = CardTypeNiuNiu.Two;
                }
                else
                {
                    need_cardtype = (CardTypeNiuNiu)next_cardtype;
                }
            }
            else
            {
                int last_cardtype = ((int)card_type) - 1;
                if (last_cardtype == 1)
                {
                    need_cardtype = CardTypeNiuNiu.Ace;
                }
                else
                {
                    need_cardtype = (CardTypeNiuNiu)last_cardtype;
                }
            }

            if (is_same_suit)
            {
                List <Card> list_same_suitcards = null;
                if (mapSameSuitCard.TryGetValue(card_suit, out list_same_suitcards))
                {
                    var list_suit_card = list_same_suitcards.Where(x => (CardTypeNiuNiu)x.Type == need_cardtype);
                    if (list_suit_card != null && list_suit_card.Count() > 0)
                    {
                        card = list_suit_card.First();
                        _removeCard(card);
                    }
                }
            }
            else
            {
                card = _getSameTypeCard(need_cardtype);
            }

            return(card);
        }
Exemplo n.º 3
0
        //---------------------------------------------------------------------
        Card _getSameTypeCard(CardTypeNiuNiu card_type)
        {
            Card        card = null;
            List <Card> list_sametypecard = null;

            mapSameTypeCard.TryGetValue(card_type, out list_sametypecard);
            if (list_sametypecard != null && list_sametypecard.Count > 0)
            {
                int index = RandomEx.Next(0, list_sametypecard.Count);
                card = list_sametypecard[index];
                _removeCard(card);
            }

            return(card);
        }