Пример #1
0
        static void Main(string[] args)
        {
            Console.Write("Welcome to the Grand Hotel and Casino.  What should I call you?");
            string playerName = Console.ReadLine();

            Console.WriteLine("How much money did you bring with you today?");
            int bank = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Hello {0}, would you like to start our blackjack game?", playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "ya" || answer == "sure")
            {
                Player player = new Player(playerName, bank);          //create new player object and initialize him with his name/how much he bought (through a constructor)
                Game   game   = new TwentyOneGame();                   //created player, now we should create a game.  (using polymorphism)
                game += player;                                        //adding player to the game
                player.isActivelyPlaying = true;                       //while the player is actively playing, continue playing the game.  Now we have a way to see if player wants to play

                while (player.isActivelyPlaying && player.Balance > 0) //checks: does the player want to keep playing, and does he have enough money to play
                {
                    game.Play();
                }

                game -= player;
                Console.WriteLine("Thank You For Playing!");
            }

            Console.WriteLine("Feel free to look around the casino, Goodbye for now.");
            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Grand Hotel and Casino. Let's start by telling me your name: ");
            string playerName = Console.ReadLine();

            Console.WriteLine("And how much money did you bring today? : ");
            int bank = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Hello, {0}.  Would you like to join a game of 21 right now?", playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "ya")
            {
                Player player = new Player(playerName, bank);
                Game   game   = new TwentyOneGame();
                game += player;
                player.isActivelyPlaying = true;
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    game.Play();
                }
                game -= player;
                Console.WriteLine("Thank you for playing!");
            }
            Console.WriteLine("Feel free to look around the casino.  Bye for now...");
            Console.Read();
        }
Пример #3
0
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel & Casino"; // Great if used several times or more and you want it to stay consistent

            Console.Write($"Welcome to {casinoName}. Let's start by telling me your name.\n>>>: ");
            string inputName = Console.ReadLine();

            if (inputName.ToLower() == "admin")
            {
                List <ExceptionEntity> Exceptions = ReadExceptions();
                foreach (var exception in Exceptions)
                {
                    Console.Write(exception.Id + " | ");
                    Console.Write(exception.ExceptionType + " | ");
                    Console.Write(exception.ExceptionMessage + " | ");
                    Console.Write(exception.TimeStamp + " | ");
                    Console.WriteLine();
                }
                Console.ReadLine();
                return;
            }

            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)
            {
                Console.Write("And how much money did you bring today?\n>>>: ");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digits only, no decimals!");
                }
            }

            TextInfo playerNameTI    = new CultureInfo("en-US", false).TextInfo;  // Creates a TextInfo based on the "en-US" culture
            string   lowerPlayerName = playerNameTI.ToLower(inputName);           // First pass normalization to lower-case all letters
            string   playerName      = playerNameTI.ToTitleCase(lowerPlayerName); // Last pass normalization to capitalize player's name

            Console.Write($"\nHello {playerName}. Would you like to join a game of 21, right now?\n>>>: ");
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "yea" || answer == "yup" || answer == "ya" || answer == "y")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\Scott\Projects\repos\TTA_Basic_CSharp\logs\blackjack_log.txt", true))
                {
                    file.WriteLine(player.Id);
                }
                Game game = new TwentyOneGame();
                game += player;
                player.isActivelyPlaying = true;
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play(); // Abstract method, contains logic for game itself
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"An error occurred- {ex.Message}! Please see your system administrator.");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("\nThank you for playing!\n");
            }
            Console.WriteLine("Feel free to look around the casino. Bye for now!");
            Console.Read();
        }
        static void Main(string[] args)
        {
            const string casinoName = "Grand hotel and Casino";

            Console.WriteLine("Welcome to the {0}! What is your name?", casinoName);
            string playerName = Console.ReadLine();

            if (playerName.ToLower() == "admin")
            {
                List <ExceptionEntity> Exceptions = ReadExceptions();
                foreach (var exception in Exceptions)
                {
                    Console.Write(exception.Id + " | ");
                    Console.Write(exception.ExceptionType + " | ");
                    Console.Write(exception.ExceptionMessage + " | ");
                    Console.Write(exception.TimeStamp + "\n");
                }
                Console.ReadKey();
                return;
            }
            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)
            {
                Console.WriteLine("How much money did you bring today?");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter integer only.");
                }
            }

            Console.WriteLine("Hello {0}, would you like to play a game of Black Jack right now?", playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "y")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@".\BlackJackLog.txt", true))//true is for 'append'
                {
                    file.WriteLine(player.Id);
                }
                Game game = new TwentyOneGame();
                game += player;
                player.isActivelyPlaying = true;
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDbWithExceptions(ex);
                        Console.ReadKey();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occured.");
                        UpdateDbWithExceptions(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for playing.");
            }
            Console.WriteLine("Feel free to look around the casino. Bye for now.");


            Console.ReadKey();
        }