Ejemplo n.º 1
0
 public static HandCards CreateInstance(CardGroup _cardGroup)
 {
     if (_cardGroup.numOfCards == 5)
     {
         _cardGroup.sortCards();
         return(new HandCards(_cardGroup));
     }
     return(null);
 }
Ejemplo n.º 2
0
        public CardGroup popCards(int index, int count)
        {
            List <Card> popedCards = cards.GetRange(index, count);

            cards.RemoveRange(index, count);
            CardGroup popedCardGroup = new CardGroup(popedCards);

            return(popedCardGroup);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            bool quit = false;

            while (!quit)
            {
                Console.WriteLine("Start Game\n");

                // generate a new whole deck
                WholeDeckCards wholeDeckcards = new WholeDeckCards();
                wholeDeckcards.generateDeck();

                // shuffle deck
                wholeDeckcards.shuffleCards();
                Console.WriteLine("the shuffled deck are showing below: ");
                wholeDeckcards.printCards();
                Console.WriteLine("\n");

                // deal cards to 4 players
                Console.WriteLine("deal cards to 4 players");

                CardGroup player1Deck = wholeDeckcards.popCards(0, 5);
                CardGroup player2Deck = wholeDeckcards.popCards(0, 5);
                CardGroup player3Deck = wholeDeckcards.popCards(0, 5);
                CardGroup player4Deck = wholeDeckcards.popCards(0, 5);

                HandCards player1HandCards = HandCards.CreateInstance(player1Deck);
                HandCards player2HandCards = HandCards.CreateInstance(player2Deck);
                HandCards player3HandCards = HandCards.CreateInstance(player3Deck);
                HandCards player4HandCards = HandCards.CreateInstance(player4Deck);

                Console.WriteLine("\n");

                if (player1HandCards != null && player2HandCards != null && player3HandCards != null && player4HandCards != null)
                {
                    List <HandCards> handCardsList = new List <HandCards> {
                        player1HandCards,
                        player2HandCards,
                        player3HandCards,
                        player4HandCards,
                    };

                    int numOfPlayer = 1;
                    foreach (HandCards handCards in handCardsList)
                    {
                        numOfPlayer += 1;
                        Console.WriteLine($"player{numOfPlayer}'s hand:");
                        handCards.printCards();
                        Console.Write($"player{numOfPlayer}'s hand Categoery: ");
                        Console.WriteLine(handCards.handCategory);
                        Console.WriteLine("-------------------------------------------------------------");
                    }

                    // compare category
                    HandCards.HandCategory largesetCategory = getLargestCategory(handCardsList);
                    Console.WriteLine($"the largest category is {largesetCategory}");
                    Console.WriteLine("\n");

                    // get player's who have largest category
                    List <HandCards> lCHandCardsList = new List <HandCards>();

                    foreach (HandCards handCards in handCardsList)
                    {
                        if (handCards.handCategory == largesetCategory)
                        {
                            lCHandCardsList.Add(handCards);
                        }
                    }

                    HandCards winner = compareSameCategory(lCHandCardsList);
                    Console.WriteLine($"Winner has a {winner.handCategory}");
                    Console.WriteLine("Winner's Cards are:");
                    winner.printCards();

                    Console.WriteLine("game finished");
                    Console.WriteLine("\n");

                    // Wait for the user to respond before closing.
                    Console.Write("Press 'n' and Enter to close the app, or press any other key and Enter to continue: ");
                    if (Console.ReadLine() == "n")
                    {
                        quit = true;
                    }

                    Console.WriteLine("\n");                     // Friendly linespacing.
                }
            }
        }
Ejemplo n.º 4
0
 private HandCards(CardGroup _cardGroup) : base(_cardGroup)
 {
     this.handCategory = GetCategory();
 }
Ejemplo n.º 5
0
 protected CardGroup(CardGroup other)
 {
     this.cards      = other.cards;
     this.numOfCards = this.cards.Count;
 }