Пример #1
0
 // Parameterised Constructor
 public GameUI(Player player, Dealer dealer)
 {
     _player = player;
     _dealer = dealer;
 }
Пример #2
0
        static void Main(string[] args)
        {
            var player = new Player();
            var dealer = new Dealer();


            bool gameOver = false;

            Console.WriteLine("Welcome to Black Jack card game. What is your name: ");
            player.Name = Console.ReadLine();
            Console.WriteLine("Hi " + player.Name);



            Random rnd  = new Random();
            Random rnd2 = new Random();

            Console.WriteLine("Your Hand: ");
            player.Hand.Add(DealHand.DealCard());
            player.Hand.Add(DealHand.DealCard());
            Console.WriteLine("Dealer Hand: ");
            dealer.MyHand.Add(DealHand.DealCard());
            dealer.MyHand.Add(DealHand.DealCard());

            //while (dealer.Score > 17)
            //{
            //    dealer.MyHand.Add(DealHand.DealCard());
            //    continue;
            //}

            player.KeepScore();
            dealer.KeepScore();
            Console.WriteLine("your Score: " + player.Score);
            Console.WriteLine("Dealer Score: " + dealer.Score);
            gameOver = DealHand.CheckIfGameOver(dealer, player, "");
            //if (gameOver == true)
            //{
            //    break;
            //}

            while (gameOver == false)
            {
                Console.WriteLine("Would you like to HIT or STAND?");
                string playerPlay = Console.ReadLine().ToUpper();
                gameOver = DealHand.CheckIfGameOver(dealer, player, playerPlay);
                if (playerPlay == "HIT")

                {
                    Console.WriteLine("You Drew: ");
                    player.Hand.Add(DealHand.DealCard());
                    Console.WriteLine("Dealer Drew: ");
                    dealer.MyHand.Add(DealHand.DealCard());

                    player.KeepScore();
                    dealer.KeepScore();


                    Console.WriteLine("Your Score: " + player.Score);
                    Console.WriteLine("Dealer Score: " + dealer.Score);
                    gameOver = DealHand.CheckIfGameOver(dealer, player, playerPlay);
                }
            }



            // keep program open
            Console.ReadLine();
        }
Пример #3
0
 public void DisplayDealerInfo(Dealer dl)
 {
     Console.WriteLine(dl.Name);
 }
Пример #4
0
 public void Hit(Dealer dl)
 {
     AddCard(dl.DealCard());
 }
Пример #5
0
        /// <summary>
        /// Main Method
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //declare the start time
            DateTime start = DateTime.Now;

            //declare variables
            bool   gameLoop = true;
            bool   gameHit  = true;
            bool   gameWin  = false;
            Card   card     = new Card(null, null);// declare an empty card
            string userResponse;
            string userHit;
            int    playerHandValue = 0;
            int    dealerHandValue = 0;
            int    gameCount       = 0;
            int    winCount        = 0;
            Dictionary <string, int> gameDictionary = new Dictionary <string, int>(); //winning hand, # of times achieved
            string   key;
            SaveData dataProcess = new SaveData();

            //Explain the program to the user
            ExplainToUser();
            //Create a dealer
            Dealer dealer = new Dealer();
            //Ask the player for their name
            Player player = new Player();

            player.GetName();//Ask the player for their name
            //Loop until the user desides to quit the game
            while (gameLoop == true)
            {
                //Call the shoe of cards
                Shoe shoeOfCards = new Shoe();

                //shuffle the shoe of cards
                shoeOfCards.Shuffle();

                //clean the hand before using it
                player.DiscardHand(); //check here
                dealer.DiscardHand();
                gameHit = true;       //clear the game hit parameter
                gameWin = false;      //Game Win value is reset


                //Dealer hand is produced
                dealer.PlayHand(shoeOfCards);
                dealer.PopulateHandValueArray();

                //pay the hand give the shoe of cards to the user
                player.PlayHand(shoeOfCards);
                player.PopulateHandValueArray();

                //Peek Dealer Hand
                dealer.PeekHand();

                //show player hand
                player.ShowHand();
                playerHandValue = player.CalculateHandValue();
                Console.WriteLine(" The Player Hand Value is: " + playerHandValue);

                // Do you want to hit?
                while (gameHit == true)
                {
                    Console.WriteLine("");
                    Console.Write("Do You Want To Hit? Y / N > ");
                    userHit = Console.ReadLine();
                    Console.WriteLine();

                    //The User Has Hit
                    if (userHit.ToUpperInvariant() == "Y" || userHit.ToUpperInvariant() == "YES")
                    {
                        player.AddCardToHand(shoeOfCards.Deal()); //add a card to the hand
                        player.ShowHand();                        //show the hand
                        player.PopulateHandValueArray();
                        playerHandValue = player.CalculateHandValue();
                        Console.WriteLine(" The hand Value is: " + playerHandValue);
                    }
                    //The User Has Not Hit
                    else
                    {
                        dealer.DealerPlay(shoeOfCards, playerHandValue);
                        dealer.ShowHand();
                        dealerHandValue = dealer.CalculateHandValue();
                        Console.WriteLine(" The Dealer hand Value is: " + dealerHandValue);

                        //Determine the outcome of the game
                        gameWin = GameResult(playerHandValue, dealerHandValue);

                        // increase the win counts if the player wins
                        if (gameWin)
                        {
                            winCount  += 1;
                            gameCount += 1;

                            //if the value exist in the dictionary then update the value
                            if (gameDictionary.ContainsKey(dealerHandValue.ToString() + " =>"))
                            {
                                key = (dealerHandValue.ToString() + " =>");
                                gameDictionary[key] += 1;
                            }
                            //if the value does not exist then add to the game dictionary
                            else
                            {
                                gameDictionary.Add(dealerHandValue.ToString() + " =>", 1);
                            }
                        }

                        gameHit = false;
                    }
                }

                Console.WriteLine("");
                Console.Write("Do You Want To Play Another Hand? Y / N > ");
                userResponse = Console.ReadLine();
                Console.WriteLine();

                //determine if the game must stop or continue
                if (userResponse.ToUpperInvariant() == "Y" || userResponse.ToUpperInvariant() == "YES")
                {
                    gameLoop = true;
                    Console.WriteLine("");
                    Console.Clear();
                }
                else
                {
                    //generate the time stamp
                    TimeSpan timeTaken = DateTime.Now - start;

                    //save the results
                    dataProcess.Save(gameCount, winCount, gameDictionary, timeTaken);
                    //stop the game from running
                    gameLoop = false;
                    Environment.Exit(0);
                }
            }
        }