static void Main(string[] args)
        {
            //Set Encoding to print Unicode Characters.
            Console.OutputEncoding = System.Text.Encoding.Unicode;
            // create a new deck and display
            Deck deck = new Deck();
            Console.WriteLine("New Deck:\n");
            Console.WriteLine(deck); // NEED CHECK TOSTring is made for DECK!

            // shuffle deck and display
            deck.Shuffle();
            Console.WriteLine("\n\nShuffeled Deck:\n");
            Console.WriteLine(deck);//MAKE SURE that when deck is printed it will print the current deck.

            // deal hands from testDeck and display
            deck = new Deck(TestDeck());
            Console.WriteLine("\n\nDealing hands of 5 cards from the test deck:\n");

            //This checks that current deck cards size is greater than or = to 5 so,
            // We must remove cards from LIST!! Collection!!!
            while (deck.Card.Count >= 5)
            {
                // Instance of Hand instantiated with 5 cards asked for.
                Hand hand = new Hand(deck.Deal(5));
                Console.WriteLine(hand);
            }

            Console.WriteLine();
        }
Exemple #2
0
 public Turn(PlayerTurn pt, Vector2 loc)
     : base(loc)
 {
     turn = pt;
     hand = new Hand(pt);
     deck = new Deck(pt);
 }
Exemple #3
0
        public void Suits_Should_Have_13_Cards(Suit suit)
        {
            var aDeck = new Deck();

            var i = aDeck.Cards.Count(x => x.GetCardSuit() == suit);
            Assert.AreEqual(i,13);
        }
Exemple #4
0
        public void ChangeCards(Deck deckToReturnTo, List<int> returnedCards )
        {
            for (var i = 0; i < returnedCards.Count; i++)
            {
                deckToReturnTo.TakeCard(_cards[i]);

            }
        }
Exemple #5
0
        public void deal_gives_five_Cards_to_Hand()
        {
            var aHand = new Hand();
            var aDeck = new Deck();

            aDeck.Deal(aHand);

            Assert.AreEqual(aHand.GetLength(), 5);
        }
Exemple #6
0
        public void Check_Hands_Are_Unique()
        {
            var deck = new Deck();
            var handOne = new Hand();
            var handTwo = new Hand();

            deck.Deal(handOne);
            deck.Deal(handTwo);

            Assert.That(!handOne.GetCards().SequenceEqual(handTwo.GetCards()));
        }
Exemple #7
0
 public Game(Deck deckToBePlayedWith)
 {
     _deck = deckToBePlayedWith;
 }
Exemple #8
0
        public void Run()
        {
            var aDeck = new Deck();
            var playerOne = new Hand();
            var playerTwo = new Hand();

            var poker = new GameRules();
            const int numberOfPlayers = 2;
            var gameWon = false;
            var pokerEvaluator = new Evaluator(PokerHandAnalysers.FiveCardPoker());
            aDeck.Shuffle();
            aDeck.Deal(playerOne);
            aDeck.Deal(playerTwo);

            while (!gameWon)
            {

                    for (int i = 0; i < numberOfPlayers; i++)
                    {

                        Console.WriteLine("Deck Cards:" + aDeck.Count());
                        Console.Write("Whose Turn: ");
                        if (i == 0)
                        {
                            Console.WriteLine("Player One");
                        }
                        else if (i == 1)
                        {
                            Console.WriteLine("Player Two");
                        }
                        Console.WriteLine("===Player One Hand===");

                        OutputCards(playerOne.GetCards());
                        Console.WriteLine("===Player Two Hand===");
                        OutputCards(playerTwo.GetCards());

                        var listOfHands = new List<Hand> { playerOne, playerTwo };
                        var result = pokerEvaluator.DetermineWinner(listOfHands);
                        if (result == playerOne)
                        {
                            Console.WriteLine("Player One Wins");
                        }else if (result == playerTwo)
                        {
                            Console.WriteLine("Player Two Wins");
                        }
                        else
                        {
                            Console.WriteLine("Draw");
                        }

                        Console.ReadKey();

                        //else if (//poker.CompareCards(player))

                        Console.WriteLine("D: Deal to Hand");
                        Console.WriteLine("S: Shuffle Deck");
                        Console.WriteLine("X: See Deck");
                        Console.WriteLine("R: Draw Cards");
                        Console.WriteLine("Escape: Quit");

                        var input = Console.ReadKey();

                        switch (input.Key)
                        {
                            case ConsoleKey.S:
                                aDeck.Shuffle();
                                break;
                            case ConsoleKey.D:
                                if (i == 0)
                                {

                                }
                                else if (i == 1)
                                {

                                }
                                break;
                            case ConsoleKey.R:
                                int cardsToReturn;

                                Console.WriteLine("How Many Cards?");
                                try
                                {
                                    cardsToReturn = int.Parse(Console.ReadLine());
                                }
                                finally
                                {

                                }
                                for (var j = 0; j < cardsToReturn; j++)
                                {
                                    Console.WriteLine(j);
                                }
                                Console.ReadKey();
                                if (i == 0)
                                {
                                    var cards = new List<int>();
                                    playerOne.ChangeCards(aDeck, cards);

                                }
                                else if (i == 1)
                                {
                                    var cards = new List<int>();
                                    playerTwo.ChangeCards(aDeck, cards);
                                }

                                break;

                            case ConsoleKey.Escape:
                                Environment.Exit(0);
                                break;
                            case ConsoleKey.X:

                                OutputCards(aDeck.GetCards());
                                Console.ReadKey();
                                break;
                        }
                        Console.Clear();
                    }

            }
        }
Exemple #9
0
        public void CheckDeckContains52Cards()
        {
            var deck = new Deck();

            Assert.That(deck.Count(), Is.EqualTo(52));
        }
Exemple #10
0
        public void No_Repeating_Cards()
        {
            var aDeck = new Deck();

            Assert.AreEqual(aDeck.Count(), aDeck.Cards.Distinct().Count());
        }
Exemple #11
0
 public LowGame(Deck deckToBePlayedWith)
     : base(deckToBePlayedWith)
 {
     _deck = deckToBePlayedWith;
 }
Exemple #12
0
        static void Main(string[] args)
        {
            string input = "";

            char[] delimiterChars  = { ' ', ',', '.', ':', '\t' };
            int    points          = 0;
            int    pointDifference = 0;
            int    cardCounter     = -1;
            bool   gameIsOn        = true;
            bool   won             = false;
            bool   winMessage      = false;
            string playerDesicion;

            var deck = new Deck();

            deck.Shuffle();
            List <Card> playerCards = new List <Card>();

            JacksOrBetter VideoPokerGame = new JacksOrBetter();

            while (gameIsOn)
            {
                pointDifference = points;

                Console.WriteLine("The players hand:\n");
                for (int i = 0; i < 5; i++)
                {
                    playerCards.Add(deck.GetCard());
                    Console.WriteLine($"{i + 1}:Card {playerCards[i].DisplayName}, {playerCards[i].Suit}, {playerCards[i].Value}");
                }

                Console.WriteLine("\nChoose which cards to discards: \nexample 1,5 (discards first and fifth cards from hand)\n");
                input = Console.ReadLine();
                Console.WriteLine();
                string[] discardCards = input.Split(delimiterChars);

                //put discarded cards back to deck
                foreach (var card in discardCards)
                {
                    deck.PutCard(playerCards[Int32.Parse(card) + cardCounter]);
                    playerCards.RemoveAt(Int32.Parse(card) + cardCounter);
                    cardCounter += -1;
                }

                //draw new cards
                for (int i = 0; discardCards.Length > i; i++)
                {
                    deck.Shuffle();
                    playerCards.Add(deck.GetCard());
                }

                Console.WriteLine("\nPlayers new hand:\n");

                for (int i = 0; i < playerCards.Count; i++)
                {
                    Console.WriteLine($"{i + 1}:Card {playerCards[i].DisplayName}, {playerCards[i].Suit}, {playerCards[i].Value}");
                }

                //Checking winning conditions
                points += VideoPokerGame.RoyalFlush(playerCards);
                won     = CheckPointDifference(pointDifference, points);
                if (won)
                {
                    winMessage = true;
                    Console.WriteLine("You won a RoyalFlush !!!");
                }

                if (!won)
                {
                    points += VideoPokerGame.StraightFlush(playerCards);
                    won     = CheckPointDifference(pointDifference, points);
                }
                if (won && !winMessage)
                {
                    winMessage = true;
                    Console.WriteLine("You won a StraightFlush !!!");
                }

                if (!won)
                {
                    points += VideoPokerGame.FourOfAKind(playerCards);
                    won     = CheckPointDifference(pointDifference, points);
                }
                if (won && !winMessage)
                {
                    winMessage = true;
                    Console.WriteLine("You won a Four Of A Kind !!!");
                }

                if (!won)
                {
                    points += VideoPokerGame.FullHouse(playerCards);
                    won     = CheckPointDifference(pointDifference, points);
                }
                if (won && !winMessage)
                {
                    winMessage = true;
                    Console.WriteLine("You won a FullHouse !!!");
                }

                if (!won)
                {
                    points += VideoPokerGame.Flush(playerCards);
                    won     = CheckPointDifference(pointDifference, points);
                }
                if (won && !winMessage)
                {
                    winMessage = true;
                    Console.WriteLine("You won a Flush !!!");
                }

                if (!won)
                {
                    points += VideoPokerGame.Straight(playerCards);
                    won     = CheckPointDifference(pointDifference, points);
                }
                if (won && !winMessage)
                {
                    winMessage = true;
                    Console.WriteLine("You won a Straight !!!");
                }

                if (!won)
                {
                    points += VideoPokerGame.ThreeOfAKind(playerCards);
                    won     = CheckPointDifference(pointDifference, points);
                }
                if (won && !winMessage)
                {
                    winMessage = true;
                    Console.WriteLine("You won a Three Of A Kind !!!");
                }

                if (!won)
                {
                    points += VideoPokerGame.TwoPair(playerCards);
                    won     = CheckPointDifference(pointDifference, points);
                }
                if (won && !winMessage)
                {
                    winMessage = true;
                    Console.WriteLine("You won a Two Pair !!!");
                }

                if (!won)
                {
                    points += VideoPokerGame.OnePairOfJacksOrBetter(playerCards);
                    won     = CheckPointDifference(pointDifference, points);
                }
                if (won && !winMessage)
                {
                    winMessage = true;
                    Console.WriteLine("You won a One Pair Of Jacks Or Better !!!");
                }

                Console.WriteLine($"\nCurrent player points: {points}");
                Console.WriteLine("Want to play the game again y/n");
                playerDesicion = Console.ReadLine();

                if (playerDesicion == "n")
                {
                    gameIsOn = false;
                }
                else
                {
                    //put discarded cards back to deck for a new game
                    for (int i = 0; i < playerCards.Count; i++)
                    {
                        deck.PutCard(playerCards[i]);
                    }
                    deck.Shuffle();
                    playerCards.Clear();
                    cardCounter = -1;
                }

                Console.Clear();
            }
        }
        /// <summary>
        /// This program will simulate a slightly modified version of the
        /// card game War.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Create a deck of cards and shuffle it.
            Deck deck = new Deck();
            deck.reset();
            deck.shuffle();

            // Create a stack of cards for each player and allow them
            // to hold a full deck.
            Stack playerStack1 = new Stack(deck.getSize());
            Stack playerStack2 = new Stack(deck.getSize());

            // Divide the deck between the two players.
            while (!deck.isEmpty())
            {
                Card nextCard = deck.draw();
                playerStack1.add(nextCard);

                nextCard = deck.draw();
                playerStack2.add(nextCard);
            }

            // Each player will also have a second stack of cards
            // to hold all the cards won during the round.
            Stack playerWinnings1;
            Stack playerWinnings2;

            // Create a stack of "draw cards" to hold matching cards
            // until a winner is determined.
            Stack drawCards = new Stack(playerStack1.getSize() + playerStack2.getSize());

            int roundsCompleted = 0;
            while (!playerStack1.isEmpty() && !playerStack2.isEmpty())
            {
                // Create a stack for each player's winnings.
                playerWinnings1 = new Stack(playerStack1.getSize() + playerStack2.getSize());
                playerWinnings2 = new Stack(playerStack1.getSize() + playerStack2.getSize());

                // Keep playing the round until someone is out of cards.
                while (!playerStack1.isEmpty() && !playerStack2.isEmpty())
                {
                    // Draw one card from each player's stack.
                    Card playerCard1 = playerStack1.draw();
                    Card playerCard2 = playerStack2.draw();

                    //Console.WriteLine(playerCard1.getDescription() + " vs. " + playerCard2.getDescription());

                    // Compare the ranks of the two cards.
                    int rank1 = playerCard1.getRank();
                    int rank2 = playerCard2.getRank();

                    if (rank1 > rank2)
                    {
                        // Give player 1 both cards and any draw cards.
                        playerWinnings1.add(drawCards);
                        playerWinnings1.add(playerCard1);
                        playerWinnings1.add(playerCard2);
                        //Console.WriteLine("- Player 1 wins!");
                    }
                    else
                    {
                        if (rank2 > rank1)
                        {
                            // Give player 2 both cards and any draw cards.
                            playerWinnings2.add(drawCards);
                            playerWinnings2.add(playerCard2);
                            playerWinnings2.add(playerCard1);
                            //Console.WriteLine("- Player 2 wins!");
                        }
                        else
                        {
                            // Place both players' cards in the draw stack.
                            drawCards.add(playerCard1);
                            drawCards.add(playerCard2);
                            //Console.WriteLine("- It's a draw!");
                        }
                    }

                    //Console.ReadKey();
                }

                // Add any winnings to the end of each player's stack
                // for the next round.
                playerStack1.add(playerWinnings1);
                playerStack2.add(playerWinnings2);

                Console.WriteLine("Player 1 wins " + playerStack1.getSize() + " cards.");
                Console.WriteLine("Player 2 wins " + playerStack2.getSize() + " cards.");
                //Console.ReadKey();

                roundsCompleted += 1;
            }

            Console.WriteLine(roundsCompleted);
            Console.ReadKey();
        }
Exemple #14
0
        static void Main(string[] args)
        {
            bool   Game = true;
            string Boop = "1";

            while (Game)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.White;
                Deck GameDeck = new Deck();
                System.Console.WriteLine("       ************************************       ");
                System.Console.WriteLine("   ********************************************   ");
                System.Console.WriteLine(" **********************************************  ");
                System.Console.WriteLine("*************************************************");
                System.Console.WriteLine("***             *******************           ***");
                System.Console.WriteLine("***             WELCOME TO WAR 2018           ***");
                System.Console.WriteLine("***             *******************           ***");
                System.Console.WriteLine("*************************************************");
                System.Console.WriteLine("*********************          ******************");
                System.Console.WriteLine("*********************          ******************");
                System.Console.WriteLine(" ************************************************");
                System.Console.WriteLine("  **********  ****  ****  ****  ****  **********  ");
                System.Console.WriteLine("   *********  ****  ****  ****  ****  *********  ");
                System.Console.WriteLine("    ********  ****  ****  ****  ****  ********  ");
                System.Console.WriteLine("    ********  ****  ****  ****  ****  *******  ");
                System.Console.WriteLine("_______________________________________________");
                System.Console.WriteLine("***   Select 1-2 Players");
                int cardsNeeded = 0;
                int Players     = 0;

                Player player1 = new Player("Temp");
                Player player2 = player1;
                Player EO      = player1;

                while (Players == 0)
                {
                    Boop    = Console.ReadLine();
                    Players = Int32.Parse(Boop);
                    if (Players == 1)
                    {
                        System.Console.WriteLine("*************************************************");
                        System.Console.WriteLine("Enter Your Name: ");
                        Boop        = Console.ReadLine();
                        player1     = new Player(Boop);
                        cardsNeeded = 4;
                        EO          = new Player("Evil Overlord", 100);
                    }
                    else if (Players == 2)
                    {
                        System.Console.WriteLine("*************************************************");
                        System.Console.WriteLine("***   Enter Player 1's Name: ");
                        Boop    = Console.ReadLine();
                        player1 = new Player(Boop);
                        System.Console.WriteLine("*************************************************");
                        System.Console.WriteLine("***   Enter Player 2's Name: ");
                        Boop        = Console.ReadLine();
                        player2     = new Player(Boop);
                        EO          = new Player("Evil Overlord", 200);
                        cardsNeeded = 6;
                    }
                    else
                    {
                        Players = 0;
                        System.Console.WriteLine("Please type 1 or 2.");
                    }
                }

                int PlayersAlive = Players;

                //game loop
                while (PlayersAlive > 0 && EO.health > 0)//and boss health
                {
                    System.Console.WriteLine("Ready?");
                    Boop = Console.ReadLine();
                    Console.Clear();
                    System.Console.WriteLine("*************************************************");
                    System.Console.WriteLine("***   {0} health is: {1}", player1.name, player1.health);
                    if (Players > 1)
                    {
                        System.Console.WriteLine("***   {0} health is: {1}", player2.name, player2.health);
                    }
                    System.Console.WriteLine("***   Boss's health is: {0}", EO.health);
                    System.Console.WriteLine("*************************************************");

                    EO.Draw(GameDeck);
                    EO.Draw(GameDeck);

                    if ((Players > 1 && player1.health >= 0) || Players == 1)
                    {
                        player1.Draw(GameDeck);
                        player1.Draw(GameDeck);
                        System.Console.WriteLine("***      {0}'s Turn", player1.name);
                        System.Console.WriteLine("*************************************************");
                        player1.DisplayHand();
                        System.Console.WriteLine("************************************************");
                        System.Console.WriteLine("***   Would you like to play the first card or the second card?");
                        System.Console.WriteLine("***   Type 'A' for the first card and 'B' for the second card.");

                        bool errorCheck = true;
                        while (errorCheck == true)
                        {
                            Boop = Console.ReadLine();
                            // System.Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
                            // System.Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
                            // System.Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");

                            if (Boop == "A" || Boop == "a")
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                player1.Attack(player1.Discard(0), EO);
                                Console.ResetColor();
                                errorCheck = false;
                            }
                            else if (Boop == "B" || Boop == "b")
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                player1.Attack(player1.Discard(1), EO);
                                Console.ResetColor();
                                errorCheck = false;
                            }
                            else
                            {
                                System.Console.WriteLine("Try writing 'a' or 'b' please.");
                            }
                            if (EO.health <= 0 && Players > 1)
                            {
                                System.Console.WriteLine("You would win now but we need to work on that so just keep going.");
                            }
                        }

                        System.Console.WriteLine("*************************************************");
                    }

                    System.Console.WriteLine("*************************************************");

                    // pick a player
                    if (EO.health > 0)
                    {
                        Player chosenPlayer = player1;
                        if (Players > 1)
                        {
                            Random rand = new Random();
                            int    x    = rand.Next(1, 3);
                            if (x == 2)
                            {
                                chosenPlayer = player2;
                            }
                        }
                        Console.ForegroundColor = ConsoleColor.Red;
                        EO.Attack(EO.Discard(0), chosenPlayer);
                        Console.ResetColor();
                    }


//player 2
                    if (Players > 1 && player2.health >= 0)
                    {
                        System.Console.WriteLine("Ready?");
                        Boop = Console.ReadLine();
                        Console.Clear();
                        System.Console.WriteLine("***   {0} health is: {1}", player1.name, player1.health);
                        if (Players > 1)
                        {
                            System.Console.WriteLine("***   {0} health is: {1}", player2.name, player2.health);
                        }
                        System.Console.WriteLine("***   Boss's health is: {0}", EO.health);
                        System.Console.WriteLine("*************************************************");
                        player2.Draw(GameDeck);
                        player2.Draw(GameDeck);
                        // System.Console.WriteLine("You drew two cards.");
                        System.Console.WriteLine("***      {0}'s Turn", player2.name);
                        System.Console.WriteLine("*************************************************");
                        player2.DisplayHand();
                        System.Console.WriteLine("*************************************************");
                        System.Console.WriteLine("***   Would you like to play the first card or the second card?");
                        System.Console.WriteLine("***   Type 'A' for the first card and 'B' for the second card.");

                        bool errorCheck3 = true;
                        while (errorCheck3 == true)
                        {
                            Boop = Console.ReadLine();

                            if (Boop == "A" || Boop == "a")
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                player2.Attack(player2.Discard(0), EO);
                                Console.ResetColor();
                                errorCheck3 = false;
                            }
                            else if (Boop == "B" || Boop == "b")
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                player2.Attack(player2.Discard(1), EO);
                                Console.ResetColor();
                                errorCheck3 = false;
                            }
                            else
                            {
                                System.Console.WriteLine("Try writing 'a' or 'b' please.");
                            }
                        }
                        System.Console.WriteLine("*************************************************");

                        // pick a player
                        if (EO.health > 0)
                        {
                            Player chosenPlayer = player1;
                            if (Players > 1)
                            {
                                Random rand = new Random();
                                int    x    = rand.Next(1, 3);
                                if (x == 2)
                                {
                                    chosenPlayer = player2;
                                }
                            }
                            Console.ForegroundColor = ConsoleColor.Red;
                            EO.Draw(GameDeck);
                            EO.Draw(GameDeck);
                            EO.Attack(EO.Discard(0), chosenPlayer);
                            Console.ResetColor();
                        }
                    }

                    // System.Console.WriteLine("*************************************************");

                    // // pick a player
                    // if (EO.health > 0)
                    // {
                    // Player chosenPlayer = player1;
                    // if (Players > 1)
                    // {
                    // Random rand = new Random();
                    // int x = rand.Next(1,3);
                    // if (x == 2)
                    // {
                    //     chosenPlayer = player2;
                    // }
                    // }

                    // Console.ForegroundColor = ConsoleColor.Red;
                    // EO.Attack(EO.Discard(0), chosenPlayer);
                    // Console.ResetColor();
                    // }

                    System.Console.WriteLine("*************************************************");

                    if (GameDeck.cards.Count < cardsNeeded)
                    {
                        System.Console.WriteLine("Re-Shuffling Deck");
                        GameDeck.Reset();
                    }

                    if (player1.health <= 0)
                    {
                        System.Console.WriteLine("{0} has died", player1.name);
                        PlayersAlive--;
                    }
                    else if (player2.health <= 0)
                    {
                        System.Console.WriteLine("{0} has died", player2.name);
                        PlayersAlive--;
                    }
                }

                // if someone won say who won
                if (EO.health <= 0)
                {
                    Console.ForegroundColor = ConsoleColor.Green;

                    System.Console.WriteLine("***********************************");
                    System.Console.WriteLine("*    The Evil Overlord Is Dead    *");
                    System.Console.WriteLine("*     You Are The New Overlord    *");
                    System.Console.WriteLine("*         Destroy It All          *");
                    System.Console.WriteLine("***********************************");

                    Console.ResetColor();
                }
                else if (PlayersAlive <= 0)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    System.Console.WriteLine("********************************************");
                    System.Console.WriteLine("*   You died. Very dead. Evil Wins Again.  *");
                    System.Console.WriteLine("********************************************");
                    Console.ResetColor();
                }
                else
                {
                    System.Console.WriteLine("How the hell?");
                }

                System.Console.WriteLine("Type 'C' to play again and 'Q' to quit.");
                bool errorCheck1 = true;
                while (errorCheck1)
                {
                    Boop = Console.ReadLine();
                    if (Boop == "q" || Boop == "Q")
                    {
                        Game        = false;
                        errorCheck1 = false;
                    }
                    else if (Boop == "c" || Boop == "C")
                    {
                        errorCheck1 = false;
                    }
                    else
                    {
                        System.Console.WriteLine("Type 'C' to play again and 'Q' to quit.");
                    }
                }
                Console.Clear();
            }
        }