Exemplo n.º 1
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 freee to look around the casino. Bye for now.");
            Console.Read();
        }
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";

            Console.WriteLine("Welcome to the {0}. 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, " + playerName + ",would you like to join a game of 21 right now?,");
            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\Downloads\myProjects.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.ReadLine();
                        return;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("An error occurred. Please contact your System Administrator.");
                        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.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Grand West 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.WriteLine(exception.TimeStamp + " | \n");
                }
                Console.Read();
                return;
            }

            Console.WriteLine("What is your buy in 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 == "y" || answer == "yeah" || answer == "ya")
            {
                Player player = new Player(playerName, bank);
                Game   game   = new TwentyOneGame();
                game += player;
                player.isActivelyPlaying = true;

                // Game Loop
                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.Read();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Game game = new TwentyOneGame();

            Console.WriteLine("Welcome to the Blackjack table. How many players today?");
            int numberOfPlayers = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < numberOfPlayers; i++)
            {
                Console.WriteLine("Please enter your name:");
                string playerName = Console.ReadLine();

                bool validAnswer = false;
                int  bank        = 0;
                while (!validAnswer)
                {
                    Console.WriteLine("How much money would you like to put up?");
                    validAnswer = int.TryParse(Console.ReadLine(), out bank);
                    if (!validAnswer)
                    {
                        Console.WriteLine("Please enter digits only, no decimals.");
                    }
                }

                Player newPlayer = new Player(playerName, bank);
                newPlayer.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\andye\logs\cardlog.txt", true))
                {
                    file.WriteLine(newPlayer.Id);
                }
                game += newPlayer;
                newPlayer.IsActive = true;
            }

            while (game.Players.Count > 0 && game.Players.Sum(x => x.Balance) > 0)
            {
                try
                {
                    game.Play();
                }
                catch (FraudException)
                {
                    Console.WriteLine("Invalid bet entry. Security has been alerted to your activity. Please vacate the premises immediately.");
                    Console.Read();
                    return;
                }
                catch (Exception)
                {
                    Console.WriteLine("An error occurred. Please contact your system administrator.");
                    Console.Read();
                    return;
                }
            }


            Console.WriteLine("Thank you for playing. Come again soon!");
            Console.Read();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome lets play. What is your name?:");
            string playerName  = Console.ReadLine();
            bool   validAnswer = false;
            int    bank        = 0;

            while (!validAnswer)
            {
                Console.WriteLine("How much did you bring to spend:");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer || bank < 0)
                {
                    Console.WriteLine("Please Enter Valid Digits only, no loose change or negative amounts.");
                    validAnswer = false;
                }
            }


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

            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "yaeh" || answer == "yse")
            {
                Player player = new Player(playerName, bank);
                Game   game   = new TwentyOneGame();
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\rohit\source\repos\The-Tech-Academy-Basic-C-Sharp-Projects\CardGame\CardGame\Log\log.txt", true))
                {
                    file.WriteLine(player.Id);
                }
                game           += player;
                player.IsActive = true;
                while (player.IsActive && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("An error occured please contact your system Adminstrator");
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for playing!");
            }
            Console.WriteLine("Feel free to look around. Bye for now!");
            Console.ReadLine();
            //foreach (Card card in deck.Cards)
            //{
            //    Console.WriteLine(card.Face + " of " + card.Suit);
            //}
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            const string casinoName = "Grand Hotel and Casino";



            Console.WriteLine("Welcome to the {0}. Let's start by tellling 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?", 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\\Carly Lokare\\Documents\\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 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.º 7
0
        static void Main()
        {
            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 a whole number only.");
                }
            }
            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;
                using (StreamWriter logFile = new StreamWriter(@"C:\Users\Jmark\Documents\Coding Projects\Sample Logs\log.txt", true))
                {
                    logFile.Write(DateTime.Now + " ");
                    logFile.WriteLine(player.Id);
                }
                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.º 8
0
        static void Main(string[] args)
        {
            const string casinoName = "Console Casino";

            Console.WriteLine("Welcome to the {0}. Please enter 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 dough 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 dough 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" || answer == "yez")
            {
                Player player = new Player(playerName, bank); //initialize constructor
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\seatt\Desktop\C#_Projects\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 occurred. Please contact your system admin.");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thanks for playing!");
            }
            Console.WriteLine("Feel free to look around the casino {0}. Bye for now!", playerName);

            Console.ReadLine();
        }
Exemplo n.º 9
0
        /// <summary>
        /// TExst
        /// </summary>
        /// <param name="args">testing</param>
        static void Main(string[] args)
        {
            //string text = "Here is some text";
            // file will be created or overwritten.  @ means read string exactly as written.  no escape chars needed
            //File.WriteAllText(@"C:\users\andy\logs\log.txt",text);
            //string text = File.ReadAllText(@"C:\users\andy\logs\log.txt");

            //DateTime yearOfBirth = new DateTime(1995, 5, 23, 8, 32, 45);
            //DateTime yearOfGraduation = new DateTime(2013, 6, 1, 16, 34, 22);

            //TimeSpan ageAtGraduation = yearOfGraduation - yearOfBirth;

            // when not using the "using System"
            //System.Console.WriteLine("Welcome to the Grand Hotel and Casino. Let's start by telling me your name.");

            // Constructor Chain
            //Player newPlayer = new Player("Andy");  // gets def bal of 100.. making use of constructor chain

            // Using var.  Rule of thumb:  if ever the data type is in question, don't use var.  not so good for
            // readability.
            //var newPlayer = new Player("Andy"); // implicitly define variable.  Useful to avoid a lot of typing

            //Dictionary<string, string> myDictionary = new Dictionary<string, string>();
            //or
            //var myDictionary1 = new Dictionary<string, string>();  // saves typing

            // declaring constants - they can not change
            const string casinoName = "Grand Hotel and Casino";

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

            if (playerName.ToLower() == "admin")
            {
                // Create list of exceptions from the database
                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("\nAnd how much money did you bring today?\n>> ");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter only digits with no decimal");
                }
            }

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

            if (answer == "yes" || answer == "yeah" || answer == "ya" || answer == "y")
            {
                Player player = new Player(playerName, bank);                                              // use constructor to create player
                player.Id = Guid.NewGuid();                                                                // Create a GUID  and assign to player
                using (StreamWriter file = new StreamWriter(@"C:\users\andy\logs\TwentyOneLog.txt", true)) // true indicates append
                {
                    file.WriteLine(player.Id);
                }  // once this reached, memory resources are disposed of
                Game game = new TwentyOneGame();  // polymorphism happening here
                game += player; // using overloaded operators in Game to add player to the list, players
                player.IsActivelyPlaying = true;
                while (player.IsActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        // Play one hand
                        game.Play();                   // most everything will happen in the Play method to keep the main method clean
                    }
                    catch (FraudException ex)          // more specific exceptions first
                    {
                        Console.WriteLine(ex.Message); // written here instead of below.  Allows for easy change of message
                        //Console.WriteLine("\nSecurity! Kick this person out for cheating.");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex) // Generic exceptions are last
                    {
                        Console.WriteLine("\nAn error occurred. Please contact your System Administrator.");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("\nYour balance is {0}.  Thank you for playing!", player.Balance);
            }
            Console.WriteLine("\nFeel free to look around the casino.  Bye for now.");
            Console.Read();
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            //  VAR, CONST, CONSTRUCTION CHAIN PRACTICE
            //var playerNum1 = new Player();
            //const string theGreatestPlayerEver = "Number 1";
            //var newPlayer = new Player("Alex");
            //var newDictionary = new Dictionary<string, string>();



            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(); // Used to create instance of player class.

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

            // Handles Format Exception
            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer || bank <= 0)
            {
                Console.WriteLine("And how much money did you bring today?");
                validAnswer = Int32.TryParse(Console.ReadLine(), out bank); // output only happens if TryParse succeeds.
                if (!validAnswer || bank <= 0)
                {
                    Console.WriteLine("Please enter digits greater than 0 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 == "sure" || answer == "y" || answer == "ya")
            {
                Player player = new Player(playerName, bank); // Create a new Player Object using the name and money the user inputted.
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\alext\OneDrive\Documents\GitHub\The-Tech-Academy-Basic-C-Sharp-Projects\Logs\log.txt", true))
                {
                    file.WriteLine(player.Id);
                }
                Game game = new TwentyOneGame(); // polymorphism so that we can use those overloaded operation properties.
                game += player;
                player.IsActivelyPlaying = true;
                while (player.IsActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play(); // Set this to play one hand. After that, check to see if the player wants to continue playing. If so, continue While loop.
                    }
                    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();



            /* LAMBDA EXPRESSION PRACTICE */

            //int count = deck.Cards.Count(x => x.Face == Face.Ace); // .Count Lambda function.
            //Console.WriteLine(count);
            //List<Card> newList = deck.Cards.Where(x => x.Face == Face.King).ToList();
            //List<int> numberList = new List<int> { 1, 2, 3, 4365, 234, 34 };
            //int sum = numberList.Sum();
            //int y = numberList.Sum(x => x += 5);
            //int max = numberList.Max();
            //int min = numberList.Min();
            //int chain = numberList.Where(x => x > 20).Sum();

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

            //Game game = new TwentyOneGame();
            //game.Players = new List<Player>();
            //    Player player = new Player() { Name = "Alex" };
            //game += player;
            //    game -= player;


            //// Overload method
            //public static Deck Shuffle(Deck deck, int times)
            //{
            //    for (int i = 0; i < times; i++)
            //    {
            //        deck = Shuffle(deck);
            //    }
            //    return deck;
            //}

            //// DateTime Practice
            //DateTime yearOfBirth = new DateTime(1995, 5, 23, 8, 32, 45); // Multiple overloads
            //DateTime yearOfGraduation = new DateTime(2013, 6, 1, 16, 34, 22);

            //TimeSpan ageAtGraduation = yearOfGraduation - yearOfBirth;
            //Console.WriteLine(yearOfGraduation <= yearOfBirth);
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Grand Hotel and Casino.");
            Console.WriteLine("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 || bank <= 0)
            {
                Console.WriteLine("How much money are you playing with today?");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (!validAnswer || bank <= 0)
                {
                    Console.WriteLine("Please enter whole positive numbers only (no decimals).");
                }
            }

            //Console.WriteLine("How much money are you playing with 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 == "ya" || answer == "y")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"c:\Users\xterr\Desktop\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 occurred, please contact your system administrator.");
                        UpdateDBWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thanks for Playing!!");
            }
            Console.WriteLine("Feel free to look around the casino. Good Bye.");
            Console.ReadLine();
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            //string text = "Here is some text";
            //File.WriteAllText(@"C:\Users\Student\testfile.txt", text); //uses a file path
            //string text = File.ReadAllText(@"C:\Users\Student\testfile.txt"); //reads text file

            //DateTime dateTime = new DateTime(1995, 5, 23, 8, 32, 45);
            //DateTime yearOfBirth = new DateTime(1995, 5, 23, 8, 32, 45);
            //DateTime yearofGraduation = new DateTime(2013, 6, 1, 16, 34, 22);

            //TimeSpan ageAtGraduation = yearofGraduation - yearOfBirth; //result in days


            //Player newPlayer = new Player("Jesse"); //utiiling constructor chain
            //var newPlary = new Player("Jesse"); //using var


            const string casinoName = "Gran hotel and Casino"; //creating and using constant (see below on first line of code "welcome..")


            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)
            {
                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("And how much money did you bring today?"); //removed to create above exception handling
            //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); //constructor (see Player.cs) and initialized it with above inputs
                player.Id = Guid.NewGuid();                   //identifer for all new users. globally unique
                using (StreamWriter file = new StreamWriter(@"C:\Users\Student\testfile.txt", true))
                {
                    file.WriteLine(player.Id);   //logging
                }
                Game game = new TwentyOneGame(); //polymorph to expose overload opperators we made
                game += player;
                player.isActivielyPlaying = true;
                while (player.isActivielyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudExceptions 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.º 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 == "sure" || answer == "ya")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                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 ocurred. 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.Read();
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the game of Twenty One!");
            Console.WriteLine("Please type 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.ReadLine();
                return;
            }
            bool validAnswer = false;
            int  bank        = 0;

            while (!validAnswer)
            {
                Console.WriteLine("How much money did you bring to the table?");
                validAnswer = int.TryParse(Console.ReadLine(), out bank);
                if (bank < 0)
                {
                    throw new FraudException();
                }
                if (!validAnswer)
                {
                    Console.WriteLine("Please enter digits only, no decimals.");
                }
            }
            Console.WriteLine("Would you like to play a game of Twenty One?");
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "yea" || answer == "ya" || answer == "y")
            {
                Player player = new TwentyOnePlayer(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(ex.Message);
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("There was an error. Please contact your system support specialist.");
                        UpdateDbWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for playing!");
            }
            Console.WriteLine("Come back soon!");
            Console.ReadLine();
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Gumbo and Marleau's Seaside Casino.  Let's start by getting 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 Black Jack?", 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\HP\OneDrive\Documents\C#-Projects\TTA-Basic-C-Sharp-Projects\blackJack\playerGUIDLog.txt", true))
                {
                    file.WriteLine(player.Name + " " + player.ID);
                }
                Game game = new TwentyOneGame();
                game += player;
                player.isActivelyPlaying = true;
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        updateDbWithExceptions(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An Error occurred.  Please contact system administrator.");
                        updateDbWithExceptions(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for playing");
            }
            Console.WriteLine("Feel free to look around the casino! Bye Felicia");
            Console.Read();
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            //Player newPlayer = new Player("Jordan"); Constructor Chain
            const string casinoName = "dotOrbital 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)
            {
                Console.WriteLine("And how much money did you bring with you 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 our featured Blackjack table?", playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "ya" || answer == "y" || answer == "yea")
            {
                Player player = new Player(playerName, bank);  //constructor
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\jadan\Desktop\COMPUTER\C# Projects\LOGGING TESTS\Player Guids.txt", true))
                {
                    file.WriteLine("New Player: " + player.Id);
                }

                Game game = new TwentyOneGame();
                game += player;
                player.isActivelyPlaying = true; //will be used for a while loop
                while (player.isActivelyPlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (Fraud_Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        UpdateDBWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An Error Occurred.");
                        UpdateDBWithException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player; //take player out of game if while loop parameters not met
                Console.Write("Thank you for playing, {0}. Please come visit us again soon.", playerName);
            }

            Console.WriteLine("Feel free to look around the casino. Bye for now."); //jump here if player answers 'no' to playing
            Console.Read();
        }