Пример #1
0
 public void Deal()
 {
     while (d.NumCards > 0)
     {
         playerDeck.AddCard(d.RemoveTopCard());
         computerDeck.AddCard(d.RemoveTopCard());
     }
 }
Пример #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();
     }
 }
Пример #3
0
 public void StartGame()
 {
     foreach (CardSuit cs in Enum.GetValues(typeof(CardSuit)))
     {
         foreach (CardValue cv in Enum.GetValues(typeof(CardValue)))
         {
             d.AddCard(new Card(cs, cv));
         }
     }
     System.Console.WriteLine($"The number of cards in deck is {d.NumCards}");
     d.ShuffleDeck();
     Deal();
     System.Console.WriteLine($"The number of cards in deck is {playerDeck.NumCards}");
     System.Console.WriteLine($"The number of cards in deck is {computerDeck.NumCards}");
     comparisonEval();
 }
Пример #4
0
        static void Main(string[] args)
        {
            Deck        d     = new Deck();
            List <Card> Hand1 = new List <Card>();
            List <Card> Hand2 = new List <Card>();
            List <Card> Pile  = new List <Card>();



            foreach (CardSuit cs in Enum.GetValues(typeof(CardSuit)))       // add a card to the deck that is a new card with the same suit and value
            {
                foreach (CardValue cv in Enum.GetValues(typeof(CardValue))) //4 suits 13 card values and 52 cards overall
                {
                    d.AddCard(new Card(cs, cv));
                }
            }

            //d.PrintDeck();
            //This will display the entire deck
            d.ShuffleDeck();
            d.Deal(Hand1, Hand2);


            //d.SortDeck();
            int NUMROUNDS = 0;

            Console.WriteLine("------------------------------------");
            Console.WriteLine("------------------------------------");
            Console.WriteLine("------------Game of WAR-------------");
            Console.WriteLine("------------------------------------");
            Console.WriteLine("------------------------------------");

            string Player1;
            string Player2;

            Console.WriteLine("Please Enter Name of Player1");
            Player1 = Console.ReadLine();
            Console.WriteLine("Please Enter Name of Player2");
            Player2 = Console.ReadLine();



            while (Hand1.Count > 0 && Hand2.Count > 0)
            {
                Card Hand1Card = Hand1[0];
                Card Hand2Card = Hand2[0];
                Hand2.RemoveAt(0);
                Hand1.RemoveAt(0);
                Pile.Add(Hand1Card);
                Pile.Add(Hand2Card);


                while (Hand2Card == Hand1Card)
                {
                    Hand1Card = Hand1[0];
                    Hand1.RemoveAt(0);
                    Pile.Add(Hand1Card);
                    Hand2Card = Hand2[0];
                    Hand2.RemoveAt(0);
                    Pile.Add(Hand2Card);
                    Hand1Card = Hand1[0];
                    Hand1.RemoveAt(0);
                    Pile.Add(Hand1Card);
                    Hand2Card = Hand2[0];
                    Hand2.RemoveAt(0);
                    Pile.Add(Hand2Card);
                }
                if (Hand1Card > Hand2Card)
                {
                    Hand1.AddRange(Pile);
                    Pile.Clear();
                }
                if (Hand2Card > Hand1Card)
                {
                    Hand2.AddRange(Pile);
                    Pile.Clear();
                }

                NUMROUNDS++;



                {
                    Console.WriteLine("Press ENTER to PLAY!");
                    Console.WriteLine("Hold ENTER to Automate");
                    Console.ReadLine();
                    Console.WriteLine("---------------------------------");

                    Console.WriteLine($"{Player1} has: {Hand1Card}");
                    Console.WriteLine($"{Player1} has: {Hand2Card}");
                    Console.WriteLine($"{Player1} Number of cards: {Hand1.Count}");
                    Console.WriteLine($"{Player2} Number of cards: {Hand2.Count}");
                    Console.WriteLine($"Number of rounds played : {NUMROUNDS}");
                    Console.WriteLine("---------------------------------");
                }
            }
        }
Пример #5
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);

                
            }

        }
Пример #6
0
        private static void gamePlay() //Method where the gameplay gets executed
        {
            Deck        d     = new Deck();
            List <Card> Hand1 = new List <Card>();
            List <Card> Hand2 = new List <Card>();
            List <Card> Pile  = new List <Card>();

            foreach (CardSuit cs in Enum.GetValues(typeof(CardSuit)))       //This will get a list of all the card suits
            {
                foreach (CardValue cv in Enum.GetValues(typeof(CardValue))) //This generates out deck for us
                {
                    d.AddCard(new Card(cs, cv));
                }
            }

            d.ShuffleDeck();      //This calls our method, to shuffle the deck
            d.Deal(Hand1, Hand2); //Deals the DECK to hand1, hand2
            //d.PrintDeck(); //This will simply print the whole deck
            System.Console.WriteLine($"The number of cards in deck is {d.NumCards}");
            //d.SortDeck(); //This sorts the deck
            int numRounds = 0;

            while (Hand1.Count > 0 && Hand2.Count > 0)
            {
                Card hand1Card = Hand1[0];
                Hand1.RemoveAt(0);
                Card hand2Card = Hand2[0];
                Hand2.RemoveAt(0);
                Pile.Add(hand1Card);
                Pile.Add(hand2Card);

                while (hand1Card == hand2Card)
                {
                    hand1Card = Hand1[0];
                    Hand1.RemoveAt(0);
                    Pile.Add(hand1Card);
                    hand2Card = Hand2[0];
                    Hand2.RemoveAt(0);
                    Pile.Add(hand2Card);
                    hand1Card = Hand1[0];
                    Hand1.RemoveAt(0);
                    Pile.Add(hand1Card);
                    hand2Card = Hand2[0];
                    Hand2.RemoveAt(0);
                    Pile.Add(hand2Card);
                }
                if (hand1Card > hand2Card)
                {
                    Hand1.AddRange(Pile);
                    Pile.Clear();
                }
                if (hand2Card > hand1Card)
                {
                    Hand2.AddRange(Pile);
                    Pile.Clear();
                }
                numRounds++;
                Console.WriteLine($"Player 1 Number of cards: {Hand1.Count}");
                Console.WriteLine($"Player 2 Number of cards: {Hand2.Count}");
                Console.WriteLine($"Number of rounds played: {numRounds}");
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"Player 1 Number of cards: {Hand1.Count}");
            Console.WriteLine($"Player 2 Number of cards: {Hand2.Count}");
            Console.WriteLine($"Number of rounds: {numRounds}");
            Console.ReadLine(); //This is just to pause the application
        }
Пример #7
0
        static void Main(string[] args)
        {
            Deck d = new Deck();


            foreach (CardSuit cs in Enum.GetValues(typeof(CardSuit)))
            {
                foreach (CardValue cv in Enum.GetValues(typeof(CardValue)))
                {
                    d.AddCard(new Card(cs, cv));
                }
            }
            DisplayMenu();
            string menuSelect = Console.ReadLine();

            // THIS IS THE GAME PLAY STUFF

            if (menuSelect == "w" || menuSelect == "W")
            {
                d.ShuffleDeck();
                d.Deal();
                bool stillPlaying = true;
                int  handIndex    = 0;
                while (stillPlaying == true && Deck.Hand1.Count > 0 && Deck.Hand2.Count > 0)
                {
                    Console.Write($"\nEnter (p) to play card: ");
                    string playInput = Console.ReadLine();
                    Console.WriteLine("");
                    if (playInput == "p" || playInput == "P")
                    {
                        Console.WriteLine($"Your Card: {d.PrintYourCard(handIndex)}");
                        Console.WriteLine($"Enemy Card: {d.PrintEnemyCard(handIndex)}");
                        if (Deck.Hand1[handIndex] > Deck.Hand2[handIndex])
                        {
                            Console.WriteLine("--------Round won!--------");
                            Deck.Hand1.Add(Deck.Hand2[handIndex]);
                        }
                        else if (Deck.Hand1[handIndex] < Deck.Hand2[handIndex])
                        {
                            Console.WriteLine("--------Round lost--------. :( ");
                            Deck.Hand2.Add(Deck.Hand1[handIndex]);
                        }
                        else if (Deck.Hand1[handIndex] == Deck.Hand2[handIndex])
                        {
                            bool war = true;
                            while (war == true)
                            {
                                Console.WriteLine("--------WAR!!!--------");
                                handIndex += 3;
                                d.PrintWar(handIndex);
                                if (Deck.Hand1[handIndex] > Deck.Hand2[handIndex])
                                {
                                    Console.WriteLine("----YOU WON THE WAR!----");
                                    Deck.Hand1.Add(Deck.Hand2[handIndex]);
                                    Deck.Hand1.Add(Deck.Hand2[handIndex - 1]);
                                    Deck.Hand1.Add(Deck.Hand2[handIndex - 2]);
                                    war = false;
                                }
                                else if (Deck.Hand1[handIndex] < Deck.Hand2[handIndex])
                                {
                                    Console.WriteLine("----YOU LOST THE WAR!----");
                                    Deck.Hand2.Add(Deck.Hand1[handIndex]);
                                    Deck.Hand2.Add(Deck.Hand1[handIndex - 1]);
                                    Deck.Hand2.Add(Deck.Hand1[handIndex - 2]);
                                    war = false;
                                }
                            }
                        }
                    }

                    handIndex++;
                }
            }
        }