Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            string continuePlay;

            do
            {
                Console.WriteLine("Start/Continue Black Jack Game? (Y/N)");
                continuePlay = Console.ReadLine();
                Console.Clear();
                Console.WriteLine("New Game:.....\r\n");

                if (continuePlay.ToUpper() != "Y" && continuePlay.ToUpper() != "N")
                {
                    Console.WriteLine("!Wrong option, please type Y (yes) or N (no)...try again!");
                    continuePlay = "Y";
                }

                else if (continuePlay.ToUpper() == "Y")
                {
                    var ComputerPlayer = new CardPlayer()
                    {
                        Name = "Computer"
                    };
                    var UserPlayer = new CardPlayer()
                    {
                        Name = "User"
                    };
                    var currentGame = new BlackJackGame();
                    var winnerIs    = "NoWinner";

                    currentGame.InitPlayer(ComputerPlayer);
                    //For the production version do not to show the Computer cards.
                    //Console.WriteLine("Cards For: " + ComputerPlayer.Name + ComputerPlayer.showCards());
                    currentGame.InitPlayer(UserPlayer);
                    Console.WriteLine("\r\nCards For: " + UserPlayer.Name + "\r\n" +
                                      UserPlayer.showCards());
                    winnerIs = currentGame.CheckWinner(ComputerPlayer, UserPlayer);

                    var resp = "H";

                    while (resp.ToUpper() == "H" && winnerIs == "NoWinner")
                    {
                        Console.WriteLine("\r\nHit or Stand? ");
                        resp = Console.ReadLine();

                        if (resp.ToUpper() == "H")
                        {
                            //Provide more cards to the user Player
                            UserPlayer.RequestCard(currentGame.DeckBlackJack);
                            Console.WriteLine("\r\nCards For: " + UserPlayer.Name + "\r\n" +
                                              UserPlayer.showCards());
                            winnerIs = currentGame.CheckWinner(ComputerPlayer, UserPlayer);
                        }
                        else if (resp.ToUpper() == "S")
                        {
                            winnerIs = currentGame.CheckWinnerFinal(ComputerPlayer, UserPlayer);
                        }
                        else
                        {
                            Console.WriteLine("Wrong Choice, please use H (hit) or S (stand)...try again");
                            resp = "H";
                        }
                    }

                    if (winnerIs != "NoWinner")
                    {
                        Console.WriteLine("\r\n" + winnerIs);
                    }
                }
            } while (continuePlay.ToUpper() == "Y");

            Console.Clear();
            Console.WriteLine("\r\nThanks...Bye!,...hit Enter key for to close the window");
            Console.Read();
        }