Beispiel #1
0
    static void Main()
    {
        Array suits = Enum.GetValues(typeof(Suit));

        int []            nums = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
        PlayingCard []    deck = new PlayingCard [suits.Length * nums.Length + 2];
        int               i    = 0; // index for deck
        AFs <PlayingCard> afs  = new AFs <PlayingCard>();

        // deck の中身を詰める。
        foreach (Suit s in suits)
        {
            foreach (int n in nums)
            {
                deck[i] = new NormalCard(s, n);
                i++;
            }
        }
        deck[i]     = new JokerCard("!");
        deck[i + 1] = new JokerCard("?");
        // 遊ぶ。
        Console.WriteLine(afs.to_s(deck));
        afs.shuffle(deck);
        Console.WriteLine(afs.to_s(deck));
    }
Beispiel #2
0
        public void AllCardShouldHaveAValue()
        {
            var sut = new NormalCard(Suit.Clubs, CardValues.Ace);

            Assert.Equal(CardValues.Ace, sut.Value);
            var jSut = new JokerCard();

            Assert.Equal(CardValues.Joker, jSut.Value);
        }
Beispiel #3
0
        public void AllCardShouldHaveASuit()
        {
            var sut = new NormalCard(Suit.Clubs, CardValues.Ace);

            Assert.Equal(Suit.Clubs, sut.Suit);
            var jSut = new JokerCard();

            Assert.Equal(Suit.None, jSut.Suit);
        }
Beispiel #4
0
 static void Main()
 {
     Array suits          = Enum.GetValues(typeof(Suit));
     int [] nums          = { 1,2,3,4,5,6,7,8,9,10,11,12,13 };
     PlayingCard [] deck  = new PlayingCard [ suits.Length * nums.Length + 2 ];
     int i                = 0; // index for deck
     AFs<PlayingCard> afs = new AFs<PlayingCard>();
     // deck の中身を詰める。
     foreach(Suit s in suits) {
       foreach(int n in nums) {
     deck[i] = new NormalCard(s,n);
     i++;
       }
     }
     deck[i  ] = new JokerCard("!");
     deck[i+1] = new JokerCard("?");
     // 遊ぶ。
     Console.WriteLine( afs.to_s(deck) );
     afs.shuffle(deck);
     Console.WriteLine( afs.to_s(deck) );
 }
Beispiel #5
0
        public List <Card> GetCardList()
        {
            var jokerCount = 0;
            var realCards  = new List <Card>();

            var hashSet     = new HashSet <string>();
            var isDuplicate = false;

            foreach (var eachCard in _cards)
            {
                if (eachCard != "JR")
                {
                    if (!hashSet.Add(eachCard))
                    {
                        isDuplicate = true;
                        SetCardValidationResults(ErrorMessage.Duplicated);
                        break;
                    }
                }
            }

            if (isDuplicate)
            {
                return(realCards);
            }
            foreach (var card in _cards)
            {
                if (card.Length == 2)
                {
                    switch (card)
                    {
                    case "JR":

                        var itsJoker = new JokerCard();
                        jokerCount += 1;
                        if (jokerCount > 2)
                        {
                            SetCardValidationResults(ErrorMessage.TowJokers);
                            break;
                        }

                        realCards.Add(itsJoker);
                        break;

                    default:
                        var charArr    = card.ToCharArray();
                        var cardNumber = GetCardNumberFromChar(charArr[0]);
                        if (cardNumber != CardNumber.Zero)
                        {
                            var cardSuit = GetCardSuitFromChar(charArr[1]);
                            if (cardSuit != Suit.None)
                            {
                                var itsCard = new Card
                                {
                                    Suit       = cardSuit,
                                    CardNumber = cardNumber
                                };
                                realCards.Add(itsCard);
                            }
                            else
                            {
                                SetCardValidationResults(ErrorMessage.NotRecognised);
                            }
                        }
                        else
                        {
                            SetCardValidationResults(ErrorMessage.NotRecognised);
                        }

                        break;
                    }
                }
                else
                {
                    SetCardValidationResults(ErrorMessage.InvalidInputString);
                    break;
                }
            }

            return(realCards);
        }
Beispiel #6
0
        public void AnJokerCardShouldHaveDefaultConstructorOnly()
        {
            var sut = new JokerCard();

            Assert.NotNull(sut);
        }