Ejemplo n.º 1
0
        private List <Card> CreateDeck()
        {
            Console.WriteLine("start black jack!");
            var deck = new Deck();

            return(deck.CreateDeck());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Deck.CreateDeck();
            var deck = ShuffledDeck(deck);

            Deck.ShuffleDeck(deck);
            Console.WriteLine(deck[0].Value + deck[0].Suit);
            var playersCardList = Player.PlayersCardList();

            // var dealersCardList = Dealer.DealersCardList();
            // Console.WriteLine(playersCardList.Count);
            playersCardList.Add(Deck.DealSingleCard());
            // Console.WriteLine(dealersCardList.Count);
            // playersCardList.Add(Deck.DealSingleCard());
            // Console.WriteLine("player: " + playersCardList.Count);
            // Console.WriteLine("dealer: " + dealersCardList.Count);
            // Console.WriteLine(deck.Count);
            // Console.WriteLine("Hit or stay? (Hit = 1, Stay = 0");
            // var turnChoice = Interface.ProcessPlayersTurnChoice();
            // Console.WriteLine(turnChoice);
            // BlackJackEngine.SumTotalOfHand(playersCardList);
            // playersCardList.Add(Deck.DealSingleCard());
            var totalOfHand = BlackJackEngine.SumTotalOfHand(playersCardList);

            Interface.DisplayPlayersHandAndScore(playersCardList, totalOfHand);
            // BlackJackEngine.SumTotalOfHand(dealersCardList);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The main function
        /// </summary>
        /// <param name="args"> This method does not return anything</param>
        public static void Main(string[] args)
        {
            //// Creates a new game with two players, deals those players cards and then computes their
            //// current score.
            Deck deck = new Deck();

            deck.CreateDeck();

            //// Gets input from the user and checks to make sure the input is valid or not.
            //// If the input is not valid it asks the user to re enter their input.
            Console.WriteLine("How many players are playing(2-5): ");
            string userInput = Console.ReadLine();

            Console.WriteLine();
            int           numPlayers = new int();
            List <Person> players    = new List <Person>();

            bool validInput = true;

            while (validInput)
            {
                while (int.TryParse(userInput, out numPlayers) == false)
                {
                    Console.WriteLine("Your input was not valid. Please enter a number from 2-5.");
                    Console.WriteLine("How many players are playing(2-5)");
                    userInput = Console.ReadLine();
                    Console.WriteLine();
                }

                if (numPlayers > 5 || numPlayers < 2)
                {
                    Console.WriteLine("Your input was not valid. Please enter a number from 2-5.");
                    Console.WriteLine("How many players are playing(2-5)");
                    userInput = Console.ReadLine();
                    Console.WriteLine();
                }
                else
                {
                    validInput = false;
                }
            }

            players = AddPlayers(numPlayers);

            // Deals face up card to each player
            foreach (Person player in players)
            {
                player.DealCard(deck);
            }

            // Deals face down card to each player
            foreach (Person player in players)
            {
                player.DealCard(deck);
            }

            // Displays everyones face up card for everyone to see.
            foreach (Person player in players)
            {
                player.DisplayFaceUpCard();
            }

            //// Executes each function involved with a players turn for each player
            foreach (Person player in players)
            {
                player.Turn();
                player.DisplayCards();
                player.Score();
                DisplayFaceUpCards(players);
                player.HitOrStand(deck);
            }

            //// Calculates which player won and displays everyone's final scores.
            WhoWon(players);
            DisplayFinalScores(players);
            ////Creates a new game with two players, deals those players cards and then computes their
            //// current score.

            Console.ReadLine();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Utility.SetupWindow("♣♥ BlackJack ♦♠", 70, 30, false);


            while (Gameover() == false)
            {
                //New Game \ Reset
                deck.CreateDeck();
                hand.ResetHand();
                dealer.ResetHand();

                //Beginning hand
                hand.addCardtoHand(deck.DrawCard());
                hand.addCardtoHand(deck.DrawCard());
                Cards card = deck.DrawCard();
                card.Faceup = false;
                dealer.addCardtoHand(card); //Needs to be faced down
                dealer.addCardtoHand(deck.DrawCard());
                Console.Clear();
                Render();

                //Bets
                int amt;
                do
                {
                    Console.Write("Bet ammount?");
                    amt = Utility.ReadInt();
                    Console.Clear();
                    Render();
                } while (Utility.IsReadGood() && player.getMoney() < amt || amt <= 0);
                player.Bet(amt);
                Console.Clear();
                Render();

                //Draws
                while (hand.Hit() == true)
                {
                    Console.Clear();
                    hand.addCardtoHand(deck.DrawCard());
                    Render();
                    if (hand.handValue() > 21)
                    {
                        break;
                    }
                }
                Console.Clear();
                Render();

                //Final hand
                if (hand.handValue() > 21)
                {
                    Console.Write("Bust!");
                }

                Console.WriteLine("Your total is " + hand.handValue());
                Console.WriteLine("----------------------------------------------------------------------");

                while (dealer.dealerHit())
                {
                    if (hand.handValue() > 21)
                    {
                        break;
                    }
                    dealer.addCardtoHand(deck.DrawCard());
                    Render();
                }

                //Determine winner & money distribution
                if (hand.handValue() < dealer.getHandValue() && dealer.getHandValue() <= 21 || hand.handValue() > 21)
                {
                    dealer.setMoney(dealer.getMoney() + amt);
                    Console.SetCursorPosition(0, 5);
                    Console.ForegroundColor = ConsoleColor.DarkMagenta;
                    Console.WriteLine("You Lost $" + amt);
                    Console.ResetColor();
                    Console.SetCursorPosition(35, 3);
                    Console.Write("Dealer had: " + dealer.getHandValue());
                }
                else if (hand.handValue() > dealer.getHandValue() && hand.handValue() <= 21 || dealer.getHandValue() > 21)
                {
                    dealer.setMoney(dealer.getMoney() - amt);
                    player.setMoney(player.getMoney() + amt + amt);
                    Console.SetCursorPosition(0, 5);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("You won $" + amt);
                    Console.ResetColor();
                    Console.SetCursorPosition(35, 3);
                    Console.Write("Dealer had: " + dealer.getHandValue());
                }
                else
                {
                    Console.SetCursorPosition(35, 3);
                    Console.Write("Dealer had: " + dealer.getHandValue());
                    Console.SetCursorPosition(0, 5);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("A tie occured, money returned");
                    Console.ResetColor();
                    player.setMoney(player.getMoney() + amt);
                }
                if (dealer.getHandValue() > 21)
                {
                    Console.SetCursorPosition(35, 3);
                    Console.Write("The Dealer busted");
                }
                card.Faceup = true;
                Render();
                Console.SetCursorPosition(0, 6);

                /* Optional question
                 * Console.ForegroundColor = ConsoleColor.DarkGray;
                 * Console.Write("Press ENTER to play the next round...");
                 * Console.ResetColor();
                 */
                Console.Read();

                //End screen
                if (player.getMoney() == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Utility.WriteCentered("You lost to the dealer. You are now homeless");
                    break;
                }
                if (dealer.getMoney() <= 0)
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Utility.WriteCentered("You win! Now the Cassino kicks you out for \"cheating\"!");
                    break;
                }
                Console.Clear();
                Render();
            }
            Console.ResetColor();
            Console.SetCursorPosition(0, Console.WindowHeight - 1);
            Console.Write("Press ENTER to exit...");
            Console.Read();
            Console.ReadLine();
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            Card[]   deck     = Deck.CreateDeck();
            Player   player   = new Player();
            Computer computer = new Computer();

            do
            {
                Deck.ShuffleDeck(deck);
                player.Clear();
                computer.Clear();
                bool correctData = false;
                Console.WriteLine("Who plays first? (Player/Computer)");
                string command = Console.ReadLine();

                while (!correctData)
                {
                    switch (command.ToLower())
                    {
                    case "player":
                        correctData = true;
                        break;

                    case "computer":
                        correctData = true;
                        break;

                    default:
                        Console.WriteLine("Incorrect data");
                        Console.WriteLine("Who plays first? (Player/Computer)");
                        command = Console.ReadLine();
                        break;
                    }
                }

                switch (command.ToLower())
                {
                case "player":
                    Deck.UsedCards = player.GetTwoCards(deck, Deck.UsedCards);

                    if (PointsProcessor.CheckAfterFirstTurn(ref player))
                    {
                        break;
                    }

                    Deck.UsedCards = computer.GetTwoCards(deck, Deck.UsedCards);
                    Deck.UsedCards = player.GetCard(deck, Deck.UsedCards, computer, true);
                    Deck.UsedCards = computer.GetCard(deck, Deck.UsedCards, player);
                    PointsProcessor.ChooseWinner(ref player, ref computer);
                    break;

                case "computer":
                    Deck.UsedCards = computer.GetTwoCards(deck, Deck.UsedCards);

                    if (PointsProcessor.CheckAfterFirstTurn(ref computer))
                    {
                        break;
                    }

                    Deck.UsedCards = player.GetTwoCards(deck, Deck.UsedCards);
                    Deck.UsedCards = computer.GetCard(deck, Deck.UsedCards, player);
                    Deck.UsedCards = player.GetCard(deck, Deck.UsedCards, computer, false);
                    PointsProcessor.ChooseWinner(ref player, ref computer);
                    break;
                }
            }while (ContinueGame(player, computer));
            Console.ReadLine();
        }