Пример #1
0
        static void Main(string[] args)
        {
            // initialize the deck of cards
            Deck d = new Deck();

            // Runs isEmpty
            Console.WriteLine(d.IsEmpty());
            // Runs shuffle method
            d.Shuffle();

            // Runs the deal method 52 times.
            for (int i = 0; i < 52; i++)
            {
                d.Deal();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Card myCard = new Card();

            myCard.Suit  = "H";
            myCard.Value = "Q";

            Card myCard2 = new Card("A", "S");

            Console.WriteLine(myCard);
            Console.WriteLine(myCard2);


            Deck myDeck = new Deck();

            Console.WriteLine(myDeck.Deal());

            Console.ReadLine();
        }
Пример #3
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("---------------------------------");
                }
            }
        }
Пример #4
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
        }
Пример #5
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++;
                }
            }
        }