Example #1
0
 public void Deal()
 {
     while (d.NumCards > 0)
     {
         playerDeck.AddCard(d.RemoveTopCard());
         computerDeck.AddCard(d.RemoveTopCard());
     }
 }
Example #2
0
 public void comparisonEval()
 {
     while (playerDeck.NumCards > 0 && computerDeck.NumCards > 0)
     {
         Console.ReadLine();
         Card pCard = playerDeck.RemoveTopCard();
         Card cCard = computerDeck.RemoveTopCard();
         table.AddCard(cCard);
         table.AddCard(pCard);
         Console.WriteLine($"player card is {pCard}");
         Console.WriteLine($"computer card is {cCard}");
         if (pCard > cCard)
         {
             Console.WriteLine("player is winner");
             while (table.NumCards > 0)
             {
                 playerDeck.AddCard(table.RemoveTopCard());
             }
             Console.WriteLine($"player deck number of cards {playerDeck.NumCards}");
             Console.WriteLine($"computer deck number of cards is {computerDeck.NumCards}");
         }
         else if (pCard < cCard)
         {
             Console.WriteLine("computer wins the hand");
             while (table.NumCards > 0)
             {
                 computerDeck.AddCard(table.RemoveTopCard());
             }
             Console.WriteLine($"player deck number of cards {playerDeck.NumCards}");
             Console.WriteLine($"computer deck number of cards is {computerDeck.NumCards}");
         }
         else if (pCard == cCard)
         {
             Console.WriteLine("******************WARRR***********************");
             Console.WriteLine("press enter to play war");
             Console.ReadLine();
             war();
         }
     }
     Console.WriteLine("game over");
     if (playerDeck.NumCards == 0)
     {
         Console.WriteLine($"player is loser, number of cards is {playerDeck.NumCards}");
         Console.WriteLine($"computer is winner, number of cards is {computerDeck.NumCards}");
         Console.ReadLine();
     }
     else if (computerDeck.NumCards == 0)
     {
         Console.WriteLine($"computer is loser, number of cards is {computerDeck.NumCards} ");
         Console.WriteLine($"player is winner, number of cards is {playerDeck.NumCards}");
         Console.ReadLine();
     }
 }
Example #3
0
 public static void TestWin(ref Deck compDeck)
 {
     // For testing purposes - we just throw away the computers cards until they have 5 left.
     compDeck.ShuffleWinnings();
     while (compDeck.NumCards > 5)
     {
         compDeck.RemoveTopCard();
     }
 }
Example #4
0
        public static void NewGame()
        {
            // Create decks
            Deck myDeck = new Deck();
            Deck compDeck = new Deck();
            Deck gameDeck = new Deck("game");
            Deck pool = new Deck("pool");

            // Deal deck
            while (gameDeck.NumCards > 0)
            {
                myDeck.AddCard(gameDeck.RemoveTopCard());
                compDeck.AddCard(gameDeck.RemoveTopCard());
            }
            string progress = "";
            while (progress.Length <= 10)
            {
                progress += "-";
                Thread.Sleep(100);
                Console.Clear();
                Console.WriteLine($"\n\n\t\t Dealing deck: [{progress.PadRight(10, ' ')}]");
            }

            // Game variables
            bool playing = true;
            int i = 0;

            // The hands
            Card myCard;
            Card compCard;


            // Start rounds
            while (playing)
            {
                i++;
                Console.Clear();
                Console.WriteLine($"\nRound {i}:");
                if (CheckDeck(ref myDeck, ref playing)) Console.WriteLine("\n-You ran out of cards. You shuffle your winnings into your deck.");
                if (CheckDeck(ref compDeck, ref playing)) Console.WriteLine("\n-The computer ran out of cards. They shuffle their winnings into their deck.");
                if (!playing) break;
                myCard = myDeck.RemoveTopCard();
                compCard = compDeck.RemoveTopCard();
                Console.WriteLine("Your Card:                                         Computer Card:");
                Console.WriteLine($"\t{myCard.ToString().PadRight(18, ' ')} vs\t{compCard}");

                // Evaluate round
                while (myCard == compCard)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\t             ~*~*~**~*~*~~*~*~**~*~*~");
                    Console.WriteLine("\t~*~*~**~*~*~     !!!!!!WAARR!!!!!     ~*~*~**~*~*~");
                    Console.WriteLine("\t             ~*~*~**~*~*~~*~*~**~*~*~\n");
                    Console.ForegroundColor = ConsoleColor.White;
                    pool.AddCard(myCard);
                    pool.AddCard(compCard);
                    Console.WriteLine("\nYou and the computer both draw a card from your hands and place it face down on the board.");
                    Console.WriteLine("You both draw a new hand.\n");
                    // Add hand to pool
                    if (CheckDeck(ref myDeck, ref playing)) Console.WriteLine("\n-You ran out of cards. You shuffle your winnings into your deck.");
                    if (CheckDeck(ref compDeck, ref playing)) Console.WriteLine("\n-The computer ran out of cards. They shuffle their winnings into their deck.");
                    if (!playing) break;
                    pool.AddCard(myDeck.RemoveTopCard());
                    pool.AddCard(compDeck.RemoveTopCard());
                    // Get new hand
                    if (CheckDeck(ref myDeck, ref playing)) Console.WriteLine("\n-You ran out of cards. You shuffle your winnings into your deck.");
                    if (CheckDeck(ref compDeck, ref playing)) Console.WriteLine("\n-The computer ran out of cards. They shuffle their winnings into their deck.");
                    if (!playing) break;
                    myCard = myDeck.RemoveTopCard();
                    compCard = compDeck.RemoveTopCard();
                    Console.WriteLine("Your Card:                                         Computer Card:");
                    Console.WriteLine($"             {myCard}  vs  {compCard}");

                }
                if (myCard > compCard && playing)
                {
                    YouWin();
                    myDeck.AddWinnings(myCard);
                    myDeck.AddWinnings(compCard);
                    while (pool.NumCards > 0)
                    {
                        myCard = pool.RemoveTopCard();
                        Console.WriteLine($"You also won: {myCard}");
                        myDeck.AddWinnings(myCard);
                    }
                }
                else if (playing)
                {
                    YouLose();
                    compDeck.AddWinnings(myCard);
                    compDeck.AddWinnings(compCard);
                    while (pool.NumCards > 0)
                    {
                        compCard = pool.RemoveTopCard();
                        Console.WriteLine($"The computer also won: {compCard}");
                        compDeck.AddWinnings(compCard);
                    }
                }
                Console.WriteLine($"\nYour cards remaining: {myDeck.NumCards} \t Winnings: {myDeck.NumWinnings}");
                Console.WriteLine($"Computer cards remaining: {compDeck.NumCards} \t Winnings: {compDeck.NumWinnings}");
                
                // Always making sure we didnt run out of cards
                if (CheckDeck(ref myDeck, ref playing)) Console.WriteLine("\n-You ran out of cards. You shuffle your winnings into your deck.");
                if (CheckDeck(ref compDeck, ref playing)) Console.WriteLine("\n-The computer ran out of cards. They shuffle their winnings into their deck.");

                if (!playing)
                {
                    if (myDeck.NumCards > 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\n\tThe computer ran out of cards!");
                        Console.WriteLine("\n\tYou beat the computer!");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (compDeck.NumCards > 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\n\tYou ran out of cards!");
                        Console.WriteLine("\n\tThe computer beat you!");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                }

                Console.WriteLine("\n-Press enter to continue (Press X to exit)");
                char gameInput = (char)Console.ReadKey().Key;
                if (gameInput == 'X') break;

                // This is just to test win condition/shuffling
                if (gameInput == 'T') TestWin(ref compDeck);

                
            }

        }