Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Grand Hotel 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")
            {
                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!");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Grand Hotel and Casino. What is your name?");
            string playerName = Console.ReadLine();

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

            Console.WriteLine("Hello, {0}. Would you like to play twenty-one?", playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "y" || answer == "yeah")
            {
                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. Goodbye!");
            Console.Read();
        }
Exemplo n.º 3
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);
                player.ID = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\Student\Desktop\log.txt", true))
                {
                    file.WriteLine(player.ID);
                }
                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();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";

            Console.WriteLine("Welcome to the {0}. Let's start by telling me your name.", casinoName);
            string playerName = Console.ReadLine();

            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)
            {
                Console.WriteLine("And how much money did you bring today?");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digist only, no decimals.");
                }
            }
            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);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\Jared\source\repos\ClassesAndObjects\logs.txt", true))
                {
                    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("Security! Kick them out.");
                        UpdateDBWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occured, please contact your system admin.");
                        UpdateDBWithException(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.ReadLine();
        }
Exemplo n.º 5
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); // {0} is a placeholder for playerName (which will be insewrted into the Console.WriteLine() content at the marked spot)
            string answer = Console.ReadLine().ToLower();                                                //use ToLower() as a means to eliminate the need for consideration of varying case input from user

            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "ya")
            {
                // creating a new player object with name and bank for the property info
                Game game = new TwentyOneGame();
                game.Players = new List <Player>();
                Player player = new Player(playerName, bank);
                // create a new game
                game += player;                  // using operation overloader to add a player to the game
                player.isActivelyPlaying = true; // to know what the game should be doing while the player is active
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    game.Play();
                }
                game -= player; // if player is not actively playing or they don't have any money to play, then remove the player from the game
                                // this is done by using the operation overloader to remove  the player from the gane ( -= )
                Console.WriteLine("Thank you for playing!");
            }
            Console.WriteLine("Feel free to look around the casino. Bye for now.");
            Console.Read();
        }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Twenty One! What's your name?");
            string playerName = Console.ReadLine();

            Console.WriteLine("How much money do you want to play with today?");
            int bank = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("{0}, would you like to begin?", playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "Yes" || answer == "yeah" || answer == "ya" || answer == "y")
            {
                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("Thanks for playing!");
            }
            Console.WriteLine("Feel free to play more! Bye bye!");
            Console.Read();
        }
        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();

            bool validAnswer = false;
            int  bank        = 0;

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

            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);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\6420 i7\Documents\GitHub\The-Tech-Academy-Basic-C-Sharp-Projects\TwentyOne\logs\logs.txt", true))
                {
                    file.WriteLine(player.Id);
                }
                Game game = new TwentyOneGame();
                game += player;
                player.isActivelyPlaying = true;
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException)
                    {
                        Console.WriteLine("Security! Kick this person out!");
                        Console.Read();
                        return;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("An error occurred. Please contact your system administrator.");
                        Console.Read();
                        return;
                    }
                }

                game -= player;
                Console.WriteLine("Thank you for playing!");
            }

            Console.WriteLine("Feel free to look around the casino. Bye for now.");
            Console.Read();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Wellcome to the casino. Tell me your name:");
            string playerName = Console.ReadLine();
            //
            bool validAnwser = false;
            int  bank        = 0;

            while (!validAnwser)
            {
                Console.WriteLine("How much money do you bring?");
                validAnwser = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnwser)
                {
                    Console.WriteLine("Please type digits only. No decimals.");
                }
            }
            //
            Console.WriteLine("Hello {0}, Would you like to join blackjack?", playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "ya")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\angel.lopez\Desktop\VSP\TTA-Basic-C-Sharp-Projects\TwentyOne\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();
                    }
                    catch (FraudException)
                    {
                        Console.WriteLine("Security! Get him!");
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("An error ocurred. Please cotact with your system administrator");
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thanks for playing.");
            }

            Console.WriteLine("Feel fre to look arround");
            Console.ReadLine();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Grand Hotel and Casino. Let's start by telling me your name");
            string playerName = Console.ReadLine();

            int bank;

            do
            {
                Console.WriteLine("And how much money did you bring today?");
            } while (!int.TryParse(Console.ReadLine(), out bank));

            //Console.WriteLine(playerName + " brought $" + bank + " and is willing to give it all out.");
            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. Bye. Bring more money and friends!");
            }
            //Game game = new TwentyOneGame();
            //Player<Card> alexei = new Player<Card> { Name = "Alexei" };
            //Player<Card> jesse = new Player<Card> { Name = "Jesse" };
            //Player<Card> bill = new Player<Card> { Name = "Bill" };
            //Player<Card> josh = new Player<Card> { Name = "Josh" };

            //game.Players = new List<Player<Card>>() { };
            ////game += josh;
            ////game += alexei;
            //game.Players.Add(alexei);
            //game.Players.Add(bill);
            //game.Players.Add(jesse);
            //game.Players.Add(josh);
            //game.ListPlayers();
            //Console.ReadLine();

            //Deck deck = new Deck();
            //deck.Shuffle(3);

            //foreach (Card card in deck.Cards)
            //{
            //    Console.WriteLine(card.Face + " of " + card.Suit);

            //}
            Console.ReadLine();
        }
Exemplo n.º 10
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();

            bool validAnswer = false;
            int  bank        = 0;

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

            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 == "ya" || answer == "y" || answer == "yea")
            {
                Player player = new Player(playerName, bank);
                Game   game   = new TwentyOneGame();
                game += player;
                player.isActivelyPlaying = true;
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine("Security! Kick this person out!");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred. Please contact your System Administrator.");
                        UpdateDbWithException(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.Read();
        }
Exemplo n.º 11
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 lok around the casino. Bye for now.");
            Console.Read();

            //Deck deck = new Deck();

            ////int count = deck.Cards.Count(x => x.Face == Face.Ace);
            ////List<Card> newList = deck.Cards.Where(X => X.Face == Face.King).ToList();

            //List<int> numberList = new List<int>() { 1, 2, 3, 535, 342, 23 };

            //int sum = numberList.Where(x => x 20).Sum();

            //Console.WriteLine(sum);

            //foreach (Card card in newList)
            // {
            //     Console.WriteLine(card.Face);
            // }
            //deck.Shuffle(3);

            //foreach (Card card in deck.Cards)
            //{
            //    Console.WriteLine(card.Face + " of " + card.Suit);
            //}
            //Console.WriteLine(deck.Cards.Count);
            /*Console.ReadLine()*/;
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.Write("Welcome to the Grand Hotel and Casino.\nLet's start by telling me your name: ");
            Console.ResetColor();
            string playerName = Console.ReadLine();

            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.Write("And how much money did you bring today? ");
            Console.ResetColor();
            int bank = Convert.ToInt32(Console.ReadLine());

            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.Write($"Hello {playerName}, would you like to join a game of 21, right now? ");
            Console.ResetColor();
            string answer = Console.ReadLine().ToLower();

            // Check if they want to play
            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "ya" || answer == "yea")
            {
                // If they want to play, create a new player object
                Player player = new Player(name: playerName, beginningBalance: bank);
                // Now that a player has been created, create a new game
                Game game = new TwentyOneGame();
                // Add player to the game
                game += player;
                player.isActivelyPlaying = true;
                // While the player still wants to play and has enough money
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    game.Play();
                    if (player.Balance == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("You do not have enough money to continue.");
                        Console.ResetColor();
                    }
                }
                // If the player exits the game, we need to remove the player from the game
                game -= player;
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine("Thank you for playing!");
                Console.ResetColor();
            }
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("Feel free to look around the casino.  Bye for now.");
            Console.ResetColor();

            Console.ReadKey();
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";

            Console.WriteLine("Welcome to the {0}. Let's start by telling me your name.", casinoName);
            string playerName = Console.ReadLine();

            bool validAnswer = false;
            int  bank        = 0;

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

            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);

                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\repos\tta_stuff\bootcamp_projects\tta_c_sharp\TwentyOne-master\log.txt", true))
                {
                    file.WriteLine(player.Id);
                }

                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.ReadLine();
        }
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";

            Console.WriteLine("Welcomes to the {0}.  Let's start by telling me your name.", casinoName);
            string playerName = Console.ReadLine();

            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 digits only, no decimals.");
                }
            }

            Console.WriteLine("Hello, {0}.  Would you like to join a game if 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();
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";

            Console.Write("Welcome to the {0}. Let's start by telling me 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 + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }
            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)
            {
                Console.Write("And how much money did you bring today: ");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter numeric value only, no decimals.");
                }
            }
            Console.Write("Hello {0}. Would you like to join a game of 21 right now: ", playerName); //{0} is a placeholder for a variable, defined after the comma
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "ya")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\GC\Logs\log.txt", true)) //using will close all memory after execution
                {
                    file.WriteLine(player.Id);
                }
                Game game = new TwentyOneGame();
                game += player;
                player.isActivelyPlaying = true; //this is what ultimately keeps the game running
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDBWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occured. Please contact your system administrator.");
                        UpdateDBWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for playing!");
            }
            Console.WriteLine("Feel free to look around the casino");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";

            Console.WriteLine("Welcome to the {0}. Let's start by telling me your name.", casinoName);
            string playerName = Console.ReadLine();

            if (playerName.ToLower() == "admin")
            {
                List <ExceptionEntity> Exceptions = ReadExceptions(); // calls this method that reads all the exceptions from the db and assigns to list
                foreach (var exception in Exceptions)
                {
                    Console.Write(exception.Id + " | ");
                    Console.Write(exception.ExceptinType + " | ");
                    Console.Write(exception.ExceptionMessage + " | ");
                    Console.Write(exception.TimeStamp + " | ");
                    Console.WriteLine();
                }

                Console.Read();
                return;
            }
            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)
            {
                Console.WriteLine("And how much money did you bring today? ");
                validAnswer = int.TryParse(Console.ReadLine(), out bank); //convernts the string rep of number to its 32 bit int and return value indicates if succeeded
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digits only, no decimals");
                }
            }

            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); //if want to play, create new player object and initalize it with name and how much brought, and instantiated
                player.Id = Guid.NewGuid();                   // right now creating a guid for every player.
                using (StreamWriter file = new StreamWriter(@"C:\Users\Student\Logs\Log.text", true))
                {
                    file.WriteLine(player.Id); //logs the guid now.
                }
                Game game = new TwentyOneGame();
                game += player;
                player.isActivelyPlaying = true;
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex) // a more specific exception
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDbWithException(ex); //update database with exception details, so know if error occurs or if kick a person out
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex) //generic exception
                    {
                        Console.WriteLine("An error occurred. Please contact your System Administrator.");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for player!");
            }
            Console.WriteLine("Feel free to  look around the casino. Bye for now");
            Console.ReadLine();
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            //string text = File.ReadAllText(@"C:\Users\Student\Logs\log.txt");
            //DateTime yearOfBirth = new DateTime(1995, 5, 23, 8, 23, 45);
            //DateTime yearOfGraduation = new DateTime(2015, 6, 6, 10, 30, 20);
            //TimeSpan ageAtGraduation = yearOfGraduation - yearOfBirth;
            //Console.WriteLine(ageAtGraduation.Days / 365);
            ////TwentyOneGame game = new TwentyOneGame();
            ////game.Players = new List<string>() { "June", "Hannah", "Molly" };
            ////game.ListPlayers();
            ////Console.ReadLine();
            ////Inheritance is one of the three pillars of Object Oriented Programming
            ////PolyMorphism is the second pillar of Object Oriented Programming
            ////TwentyOneGame game = new TwentyOneGame();
            ////List<Game> games = new List<Game>();
            //Game game = new TwentyOneGame(); //Twenty One game inherits from Game
            ////game.Players = new List<Player>() { "Matt", "Hannah", "June" };
            //game.Players = new List<Player>();
            //Player player = new Player();
            //player.Name = "Matt";
            //game += player;
            //game -= player;
            ////game.ListPlayers();
            //Deck deck = new Deck();
            //int count = deck.Cards.Count(x => x.Face == Face.Ace);
            //List<Card> newList = deck.Cards.Where(x => x.Face == Face.King).ToList();
            //List<int> numberList = new List<int>() { 1, 44, 55, 678, 93045, 342 };
            ////int sum = numberList.Sum(x => x + 5);
            //int sum = numberList.Where(x => x > 20).Sum();
            //Console.WriteLine(sum);
            //Card card1 = new Card();
            //Card card2 = card1;
            //card1.Face = Face.Eight;
            //card2.Face = Face.King;
            //Console.WriteLine(card1);
            ////Card card = new Card();
            ////card.Suit = Suit.Clubs;
            ////int underlyingvalue = (int)Suit.Diamonds;
            ////Console.WriteLine(underlyingvalue);
            ////Card card = new Card() { Face = "King", Suit = "Spades" };
            ////method above initializes values easier than card.Face = "King" & card.Suit = "Spades"
            ////You group it into one phrase.
            ////deck.Shuffle();
            //foreach (Card card in deck.Cards)
            //{
            //    Console.WriteLine(card.Face + " of " + card.Suit);
            //}
            //Console.WriteLine(deck.Cards.Count);
            //Console.ReadLine();



            ////public static Deck Shuffle(Deck deck, int times)
            ////{
            ////    for (int i = 0; i < times; i++)
            ////    {
            ////        deck = Shuffle(deck);
            ////    }
            ////    return deck;
            ///
            Guid         identifier = Guid.NewGuid();//Global Unique Identifier, value: constant data.
            const string casinoName = "KIOT's Hotel and Casino";

            Console.WriteLine("Welcome to {0}! \n " +
                              "Enter your name please: ", 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);
                    Console.WriteLine();
                    Console.ReadLine();
                }
                Console.ReadLine();
                return;
            }
            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)
            {
                Console.WriteLine("Enter your total cash:");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digits only, omit decimal points.");
                }
            }
            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" || answer == "sure")
            {
                Player player = new Player(playerName, bank);
                player.ID = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\Student\Logs\log.txt", true))
                {
                    file.WriteLine(player.ID);
                }
                Game game = new TwentyOneGame();
                game            += player;
                player.isPlaying = true;
                while (player.isPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine("A security violation has occurred.\n Remain seated while the cops come to beat yo' ass!");
                        UpdateDatabaseWithExceptions(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred.");
                        UpdateDatabaseWithExceptions(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.Read();
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            const string casinoName = "Chrispy's Casino";

            //var casinoName1 = "Casino & Hotel";


            Console.Title = "♠♥♣♦ 21 Game By Christopher Gaynor";
            Console.WriteLine("Welcome to {0}. Start by telling me 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 + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }
            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)
            {
                Console.WriteLine("And how much money did you bring today?");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digits only, no decimals.");
                }
            }
            //Console.WriteLine("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?", playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "ya")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\users\theto\source\repos\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();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occured, please contant Administrator .");
                        UpdateDbWithException(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.ReadLine();
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            //Player newPlayer = new Player("Jesse");
            //var keyword instead of player lets you implicitly define the variable
            //var newPlayer = new Player("Jesse");
            const string casinoName = "The Great Northern Hotel and Casino";//nice to have to reuse in other code so that name can't be changed

            //Guid identifier = new Guid();
            //Guid identifier = Guid.NewGuid();//creates a globally unique identifier

            //namespace is a way to organize your code


            //datetime demo
            //datetime is a struct so it is not nullable
            //DateTime yearOfBirth = new DateTime(1995, 5, 23, 8, 32, 45);//create new datetime object
            //DateTime yearOfGraduation = new DateTime(2013, 6, 1, 16, 34, 22);
            //TimeSpan ageAtGraduation = yearOfGraduation - yearOfBirth;//gives the difference in days



            //I/O demo, writing text to file
            //writing text
            //string text = "Here is some text.";
            //File.WriteAllText(@"C:\Users\RX-78\Desktop\log.txt", text);//@ symbol read string exactly as it is
            //reading text
            //string text = File.ReadAllText(@"C:\Users\RX-78\Desktop\log.txt");
            //other log code on Dealer

            //Putting it all together page 141, commented out everything and are creating a new main method, new code
            Console.WriteLine("Welcome to {0} and Casino. Let's start by telling me your name.", casinoName);
            string playerName = Console.ReadLine();

            if (playerName.ToLower() == "admin")
            {
                List <ExceptionEntity> Exceptions = ReadExceptions();//method readexceptions will assign it to this list
                foreach (var exception in Exceptions)
                {
                    Console.Write(exception.Id + " | ");
                    Console.Write(exception.ExceptionType + " | ");
                    Console.Write(exception.ExceptionMessage + " | ");
                    Console.Write(exception.TimeStamp + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }

            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)//will get hit since validAnswer is false
            {
                Console.WriteLine("And how much money did you bring today?");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);//same as Int32.TryParse(),string in is console.readline, out paramter is bank
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digits only, no decimals.");
                }
            }

            /*//replaced with code above
             * 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();                                             //makes whatever they asnwer as all lower case

            if (answer == "yes" || answer == "ya" || answer == "yeah" || answer == "y")               //|| is or
            {
                Player player = new Player(playerName, bank);                                         //sends playerName and bank to Player constructor in Player class
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\RX-78\Desktop\log.txt", true)) //takes in a path, true is yes I want to append
                {
                    file.WriteLine(player.Id);
                }
                Game game = new TwentyOneGame(); //polymorphism, exposes the overloaded operators for use
                game += player;                  //adding player to the game
                player.isActivelyPlaying = true; //isActivelyPlaying is a property of player
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex)
                    {
                        //Console.WriteLine("Security! Kick this person out.");
                        Console.WriteLine(ex.Message);
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)//Exception is a generic exception, will catch all exceptions with that
                    {
                        Console.WriteLine("An error occurred. Please contact your system administrator");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return; //return in a void method returns nothing so it ends the method
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for playing!");
            }

            Console.WriteLine("Feel free to look around the Casino. Bye for now.");
            Console.Read();


            //-------------------------------------------------------------------------old code
            //object initialization, initializes the new object with some values
            //Card card = new Card() { Face = "King", Suit = "Spades" };
            //card.Face = "King";
            //card.Suit = "Spades";

            //Game game = new Game();
            //game.Dealer = "Jesse";
            //game.Name = "TwentyOne";

            //TwentyOneGame game = new TwentyOneGame(); //since inherited from game class, has access to players property
            //game.Players = new List<string>() { "Jesse", "Bill", "Joe" };
            //game.ListPlayers();
            //game.Play();
            //Console.ReadLine(); //called the superclass method, whe you call a method from the class you're inheriting from, Game is the super class


            //Polymorphism property of classes to morph into other types of classes
            //a TwentyOneGame object can morph into a game object
            //TwentyOneGame can morph into another higher order object
            //Game game = new TwentyOneGame();

            //comes in handy when you want to make a list consisting of more than one data type
            //List<Game> games = new List<Game>();
            //TwentyOneGame game = new TwentyOneGame();
            //games.Add(game);

            //TwentyOneGame
            //PokerGame
            //SolitaireGame

            //Game game = new Game(); //if game is abstract class, you can no longer instantiate it

            /*
             * TwentyOneGame game = new TwentyOneGame();
             * game.Players = new List<string>() { "Jesse", "Bill", "Zoe" };
             * game.ListPlayers();
             * Console.ReadLine();
             */
            /*
             * Game game = new TwentyOneGame();
             * game.Players = new List<Player>();//had to add this in bc there was no list created yet to add a player into
             * Player player = new Player();
             * player.Name = "Jesse";
             * //game = game + player;
             * game += player; //easier way of writing game = game + player
             * //game = game - player;
             * game -= player;
             */

            //generics feature of language that allows you to write generic classes or functions, more generalized and less specific
            //list holds data type of whats being passed in. T generic

            //enum stuff
            //limit possible values you can receive from a user
            //DaysOfTheWeek day = DaysOfTheWeek.Monday;
            //can cast an enum to its underlying integer

            /*//enums continued
             * Card card = new Card();
             * card.Suit = Suit.Clubs;
             * int underlyingValue = Convert.ToInt32(Suit.Diamonds);
             * Console.WriteLine(underlyingValue);
             */

            //reference types are like doc on google drive, really same doc since it is the same memory location, when card 2 edits, changes card 1 also
            //any data type that stores value by reference is called a reference type, general rule of thumb, this includes all classes
            //string, List, Card are a reference type

            /*
             * Card card1 = new Card();
             * Card card2 = card1;
             * card1.Face = Face.Eight;
             * card2.Face = Face.King;
             */
            //by changing Card class to struct, Eight is displayed rather than King since it is no longer reference
            //card1 is now its own separate instance

            //value type - if a copy is sent by email rather than using google drive, that's like sending by value, separate independent instance, not pointing to storage location, sending actual value
            //value type examples - integers, booleans, enums, datetime
            //int is a public struct, Int32 could be used in place of int
            //int number = 5;
            //Int32 number = 5; same thing
            //struct is the same as a class but is a value type, struct can't be inherited
            //struct is a value type, value type can't be null because they are non-nullable
            //non-nullable data types are structs, booleans, integers
            //Console.WriteLine(card1.Face);

            //lambda functions
            //very difficult to debug since you can't step through it like a loop

            //Deck deck = new Deck();//create object deck

            /*
             * //count number of Aces in deck using lambda function
             * int count = deck.Cards.Count(x => x.Face == Face.Ace);//Cards is a List, Count is a lambda function
             * //counting all the elements (x) in the List, x is each element where x.Face is equal to Face.Ace, x can be renamed to anything
             * // => means "map this expression to each item"
             * Console.WriteLine(count);
             */

            /*
             * List<Card> newList = deck.Cards.Where(x => x.Face == Face.King).ToList();//where is lambda function that lets you filter your list for particular features
             * //doesn't produce a list so have to use ToList()
             * //take list of cards, filter where face is king, map that to a new list
             * foreach (Card card in newList)
             * {
             *  Console.WriteLine(card.Face);
             * }
             */

            /*
             * List<int> numberList = new List<int>() { 1, 2, 3, 535, 342, 23 };
             * //int sum = numberList.Sum(); //or could add more arithmetic like the line below
             * //int sum = numberList.Sum(x => x + 5);
             * //int sum = numberList.Max();
             * //int sum = numberList.Min();
             * int sum = numberList.Where(x => x > 20).Sum();//have to add Sum() since numberList.Where(x => x > 20) wouldn't do anything
             * Console.WriteLine(sum);
             */

            /*//count number of aces in deck using for loop
             * int counter = 0;
             * foreach (Card card in deck.Cards)
             * {
             *  if (card.Face == Face.Ace)
             *  {
             *      counter++;
             *  }
             * }
             * Console.WriteLine(counter);
             */

            /*
             * //int timesShuffled = 0;
             * //deck = Shuffle(deck, out timesShuffled, 3);//shuffles deck 3 times and returning the timesShuffled value, not returning it to deck, it's sending it out to the line above int timesSHuffled = 0;
             * //deck = Shuffle(deck, 3); //shuffles deck 3 times
             * deck.Shuffle(3);//call shuffle method 3 times, call method shuffle on itself
             *
             *
             * foreach (Card card in deck.Cards)
             * {
             *  Console.WriteLine(card.Face + " of " + card.Suit);
             * }
             *
             * Console.WriteLine(deck.Cards.Count);
             * //Console.WriteLine("Times shuffled: {0}", timesShuffled);
             */
            //Console.ReadLine();

            //.NET does not support multiple inheritance, one class can only inherit from one other class
            //use interfaces

            //Methods have to be part of a class

            /* //commented out to create a constructor in deck class instead
             * deck.Cards = new List<Card>();
             *
             * Card cardOne = new Card();
             * //objects of data type card assigned to variable card one, created a new card object, instantiated a new object, currently empty
             * cardOne.Face = "Queen";
             * cardOne.Suit = "Spades";
             *
             * deck.Cards.Add(cardOne);//added one card to the deck
             *
             * //Console.WriteLine(deck.Cards[0].Face + " of " + deck.Cards[0].Suit);
             */
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            // constant string variable
            const string casinoName = "Grand Hotel and Casino";

            Console.WriteLine("Welcome to the {0}. Let's start by telling me 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 + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }
            // catch input format exception (if user inputs non-integer characters)
            bool validAnswer = false;
            int  bank        = 0;

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

            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);
                player.Id = Guid.NewGuid(); // create Guid (Global User ID) each time a new player is created
                using (StreamWriter file = new StreamWriter(@"C:\Users\Jefe\logs\log.txt", true))
                {
                    file.WriteLine(player.Id); // log the Guid
                }
                Game game = new TwentyOneGame();
                game += player; // add player to game
                player.isActivelyPlaying = true;

                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred. Please contact your System Administrator.");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return; // ends program when in a void method
                    }
                }
                game -= player; // remove player from game
                Console.WriteLine("Thank you for playing!");
            }
            Console.WriteLine("Feel free to look around the casino. Bye for now");
            Console.ReadLine();
        }
Exemplo n.º 21
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();

            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 + "  |  ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }
            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)
            {
                Console.WriteLine("And how much money did you bring today?");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digits only, no decimals");
                }
            }
            try // Added this myself
            {
                if (bank < 0)
                {
                    throw new FraudException();
                }
            }
            catch (FraudException)
            {
                Console.WriteLine("Security! Kick this person out.");
                Console.ReadLine();
                return;
            } // Stop personal addition
            Console.WriteLine("Great, {0}, you have ${1} to bet with. Would you like to join a game of 21 right now?", playerName, bank);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "ya" || answer == "yea" || answer == "y" || answer == "ok" || answer == "okay" || answer == "sure")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"D:\log\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();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occured, please contact your System Administrator.");
                        UpdateDbWithException(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.Read();
        }
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";

            Console.BackgroundColor = ConsoleColor.Yellow;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.WriteLine("Welcome to the {0}!\n\n", casinoName);
            Console.BackgroundColor = ConsoleColor.Red;
            Console.WriteLine("Let's start by telling me your name.");
            string playerName = Console.ReadLine();

            if (playerName.ToLower() == "admin")
            {
                List <ExceptionEntity> Exceptions = ReadException();
                foreach (var exception in Exceptions) // Looping through the list
                {
                    Console.Write(exception.Id + " | ");
                    Console.Write(exception.ExceptionType + " | ");
                    Console.Write(exception.ExceptionMessage + " | ");
                    Console.Write(exception.TimeStamp + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }



            Console.WriteLine("\nHello, {0}. Would you like to join a game of 21 right now?", playerName);
            // Converted to lower to assist in user input match.
            string answer = Console.ReadLine().ToLower();

            // Relocated this chunk, thought it made more logical sense that you'd first agree to a game? It was originall just above the "Hello fjdklj, would you....."

            // This is designed to prevent errors and to handle them appropriately when needed.
            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)
            {
                Console.WriteLine("How much money did you bring today?");
                validAnswer = int.TryParse(Console.ReadLine(), out bank); // This extracts the value inputted by user, attempts to convert it, logs a bool for comp. in "validAnswer", if successful outputs the converted int to "bank", otherwise continues below.
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter whole dollars only, no change!.");                // This is an alternate method, but is not as adaptive for error handling - int bank = Convert.ToInt32(Console.ReadLine());
                }
            }

            // Providing different possible user input matches to ease runability.
            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "ya")
            {
                // Abstantiated Contstructor from "Player" Class.
                Player player = new Player(playerName, bank);
                // Special "guid" identifier.
                player.Id = Guid.NewGuid();

                using (StreamWriter file = new StreamWriter(@"C:\Users\New\Desktop\TwentyOneLog.txt", true))
                {
                    file.WriteLine(player.Name.ToUpper()); // Added myself, thought it made sense?
                    file.WriteLine(player.Id);
                }

                //Abstantiated Constructor & the use of Polymorphism to expose overloaded operators.
                Game game = new TwentyOneGame();
                // Adding player to "Game", += is the same as doing the whole equation written out c = a + b, for example a += b.
                game += player;
                player.isActivelyPlaying = true;


                // Told to use while loops with caution, even though we'll have multiple in this program, but for demonstation purposes I suppose!

                // While loop to check the status of "isActivelyPlaying & Balance variables to verify if program should be running or not.
                // While both are "true" the program will fire.
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message); // Passes through custom exception message.
                        UpdateDbWithException(ex);     // Updates database with exception message.
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred. Please contact your System Administrator.");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return; // While in a void method, return will kill the program. That can come in handy.
                    }
                }
                // Operates just after exiting the loop
                game -= player;
                Console.WriteLine("\nThank you for playing!");
            }
            // If user were to type something besides "yes, yah, etc", this will fire, I think generally this would be an "else" statement.
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\nFeel free to look around the casino. Bye for now!");
            Console.Read();
            // All other operations happen outside of this main method in other classes.
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Grand Hotel and Casino. Lets start by telling me your name.");
            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 + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }
            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer) //exception handling for how much money they brought. we want only an int
            {
                Console.WriteLine("And how much money did you bring today?");
                //tryparse will convert the readline string to an integer and return it as var bank. If it succeeds valid answer is true if nto its false.
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digits only, no decimals.");
                }
            }

            //Console.WriteLine("How much money did you bring today");
            //int bank = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Hello, {0}. Would you like to play a game of 21?", playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yea" || answer == "yeah" || answer == "yep")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid(); //assigning a globally unique ID for our player
                using (StreamWriter file = new StreamWriter(@"C:\Users\ericm\OneDrive\Documents\users.txt", true))
                {                           //this will log our players ID to a file.
                    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)                                  //exception for that especific error, this is used in bet.
                    {
                        Console.WriteLine("Security!! Kick this person out!"); //this runs if you try to put a neg number which is cheating
                        UpdateDBWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex) //an exception for any general error
                    {
                        Console.WriteLine("An error occured please contact your system admin.");
                        UpdateDBWithException(ex);
                        Console.ReadLine();
                        return; //we end the program with this
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for playing!");
            }
            Console.WriteLine("Feel free to look around the casino. Bye for now!");
            Console.ReadLine();
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            //with new constructor
            //Player newPlayer = new Player("Austin");
            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.TimStamp + " | ");
                    Console.WriteLine();
                }

                Console.Read();
                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 digits only, no decimals");
                }
            }



            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")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\arigg\Logs\log.text", true))
                {
                    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);
                        UpdateDbWithExpception(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("an error occurred, please contact your system administrator");
                        UpdateDbWithExpception(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thanks for playing");
            }
            Console.WriteLine("Feel free to look around casino. Thanks for playing");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";

            Console.WriteLine("Welcome to the {0}. Let's start by telling me your name.", casinoName);
            string playerName = Console.ReadLine();

            //NOTE: For learning and texting purposes, if the user types admin as a name, do this.
            if (playerName.ToLower() == "admin")
            {
                //NOTE: We are calling a local private method, 'ReadExceptions' which returns a list of 'ExceptionEntity' objects
                //      and we are referencing it in variable 'Exceptions'.
                List <ExceptionEntity> Exceptions = ReadExceptions();

                //NOTE: Here we are iterating through each properties in each ExceptionEntity object created, and printing it
                //      as a representation of each record in the 'Exceptions' table in the 'TwentyOneGame' database.
                foreach (var exception in Exceptions)
                {
                    Console.Write(exception.Id + " | ");
                    Console.Write(exception.ExceptionType + " | ");
                    Console.Write(exception.ExceptionMessage + " | ");
                    Console.Write(exception.TimeStamp + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }

            //NOTE: Here instead of reciving the information with out it being handled,
            //      eg. 'int bank = Convert.ToInt32(Console.ReadLine());', we created a
            //      validator that uses the 'int.TryParse' method wich returns a boolean
            //      based on whether the first string parameter is an int32. The method
            //      also includes an 'out parameter' of the int result in the case that
            //      it is a valid int. This is a quick way to validate user input without
            //      having to use exception handling.
            bool validAnswer = false;
            int  bank        = 0;

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

            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")
            {
                //NOTE: When the user answers yes, it will create a new player.
                //      In the 'Player' class we will create a constructoe that will
                //      create that player with how much money they are bringing to the game.
                Player player = new Player(playerName, bank);

                //NOTE: Here we are logging a player 'Guid' so we can uniquely identify that player,
                //      and the cards that player has dealt with.
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\log\log.txt", true))
                {
                    file.WriteLine(player.Id);
                }

                //NOTE: Here we are using Polymorphism, while creating a 'TwentyOneGame' as also its
                //      parent class, 'Game' so that it exposes those overloaded operators we
                //      made in the 'Player' class, which returns a 'Game' object, and to a
                //      specified game object such as 'TwentyOneGame'.
                Game game = new TwentyOneGame();

                //NOTE: Here we are adding players into a game.
                game += player;

                player.isActivelyPlaying = true;

                //NOTE: 'isActivelyPlaying' and 'player.balabnce' are used as a way to track
                //      wether the player is playing the game or isn't/can't play the game.
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    //NOTE: This try-cath will catch any errors in the 'Play()' method.
                    try
                    {
                        game.Play();
                    }
                    //NOTE: This is an exception we created which inherits the integrated 'Exception' class.
                    //      It is a great way of 'throwing' a custom exception by when a condition is in
                    //      our program is met.
                    catch (FraudException ex)
                    {
                        //NOTE: In our 'TwentyOneGame' class, we 'throw new FraudException("Security! Kick this person out.");'
                        //      If a player bet is lower then 0 (a negative number).
                        Console.WriteLine(ex.Message);

                        //NOTE: Here we are calling the method that we created outside of the main method which takes in an exception.
                        UpdateDbWithException(ex);

                        Console.ReadLine();
                        return;
                    }
                    //NOTE: This is the 'Exception' class that will catch any exception if not covered in the
                    //      TwentyOneGame 'Play()' method.
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occured. Please contact your System Administrator.");

                        //NOTE: Here we are calling the method that we created outside of the main method which takes in an exception.
                        UpdateDbWithException(ex);

                        Console.ReadLine();
                        return;
                    }
                }
                //NOTE: Outside of the while loop we will subtract the  player form the game.
                game -= player;
                Console.WriteLine("Thank You for playing!");
            }
            //NOTE: We won't do an else statement, if they say anything other than 'yes' 'yeah' 'y' & 'ya',
            //      then it will jump to this line.
            Console.WriteLine("Feel free to look around the casino. Bye for now.");
            Console.ReadLine();

            //NOTE: This is all that the main method is going to have.
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            //Player newPlayer = new Player("Dan");
            //string text = "Some text.";
            //File.WriteAllText(@"C:\Users\danie\Logs\log.txt", text);
            //string text = File.ReadAllText(@"C:\Users\danie\Logs\log.txt");

            const string casinoName = "Grand Hotel and Casino";

            Console.WriteLine("Welcome to the " + casinoName + ". Let's start by telling me your name.");
            string playerName = Console.ReadLine();

            if (playerName.ToLower() == "admin")
            {
                //write retrieved ada to the console
                List <ExceptionEntity> Exceptions = ReadExceptions();
                foreach (var exceptions in Exceptions)
                {
                    Console.Write(exceptions.Id + " | ");
                    Console.Write(exceptions.ExceptionType + " |");
                    Console.Write(exceptions.ExceptionMessage + " | ");
                    Console.Write(exceptions.TimeStamp + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                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 only enter a positive integer.");
                }
            }

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

            if (answer == "yes" || answer == "yeah" || answer == "yup" || answer == "y" || answer == "ya")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\danie\Logs\log.txt", true))
                {
                    file.WriteLine(player.Id + "\n");
                }
                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);
                        UpdateDBWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occured please contact your system administrator.");
                        UpdateDBWithException(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.Read();
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";

            Guid identifier = Guid.NewGuid();

            Console.WriteLine("Welcome to the {0}. Lets start by telling me 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 + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }
            bool validAnswer = false;
            int  bank        = 0;

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


            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);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\kilgo\Logs\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();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occured. Please contact your System Administer. ");
                        UpdateDbWithException(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.ReadLine();
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";


            Console.WriteLine("Welcome to the {0}. Let's start by telling me 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 + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }

            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer) //one way of error handling
            {
                Console.WriteLine("And how much money did you bring today?");
                validAnswer = int.TryParse(Console.ReadLine(), out bank); //this casts the response from string to int, if it doesn't succeed, bank = 0
                //when it succeeds, valid answer will become true
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digits only, no decimals");
                }
            }

            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); //passing the two parameters we have already into the constructor
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\lenni\Desktop\logs\log.txt", true))
                {
                    file.WriteLine(player.Id);
                }
                Game game = new TwentyOneGame(); //polymorphism!
                game += player;                  //add the new player to the game
                player.IsActivelyPlaying = true; //we'll use this for a while loop to make sure the game is still being played
                while (player.IsActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred. Please contact your System Administrator.");
                        UpdateDbWithException(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.Read();
        }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";



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

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

            while (!validAnswer)
            {
                Console.WriteLine("Great to have you, {0}. How much money would you like to add to your account?", playerName);
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digits only, no decimals.");
                }
            }
            Console.WriteLine("Would you like to join a game of 21, {0}", playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "ya")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\Student\Desktop\Projects\Logs\log.txt", true))
                {
                    file.WriteLine("Player ID: {0}", 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);
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred. Please contact your System Administrator.");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for playing!");
            }
            Console.WriteLine("Feel free to look around the casino. And, don't forget to check out the buffet! Bye for now.");
            Console.ReadLine();
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the game 21! Please enter your name.");
            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 + " | ");
                    Console.WriteLine();
                }
                Console.Read();
                return;
            }

            bool validAnswer = false;
            int  bank        = 0;

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

            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 == "ya" || answer == "y")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\Colej\source\repos\CSharpProjects\TwentyOne\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();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occured. Please contact your System Administrator.");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for playing!");
            }
            Console.WriteLine("Bye for now.");
            Console.Read();
        }