Esempio n. 1
0
        //static ConsoleIO io = new ConsoleIO(true);

        static void Main(string[] args)
        {
            IConsoleIO io         = Dependencies.consoleIO.make();
            int        gamesWon   = 0;
            int        totalGames = 0;

            //Process proc1 = Process.Start("cmd.exe");
            //proc1.StandardInput.WriteLine("Hello");

            //Process proc = new Process();
            //proc.StartInfo.FileName = "cmd.exe";
            //proc.Start();

            string playerName = io.PromptForString("Enter you name:");

            bool playAgain = true;

            do
            {
                BlackjackGame game = new BlackjackGame();
                totalGames++;
                Dealer  dealer = new Dealer();
                IPlayer player = new HumanPlayer(playerName);
                IDeck   deck   = BlackjackOperations.GetAndShuffleNewDeck();

                GameResult result = game.play(deck, dealer, player);
                if (result == GameResult.PlayerWin || result == GameResult.PlayerBlackjack)
                {
                    gamesWon++;
                }

                string askPlayAgain = io.PromptForString("Play again?");
                playAgain = askPlayAgain.Length > 0 && (askPlayAgain.ToUpper().First() == 'Y');
            } while (playAgain);
            io.WriteLine("Thanks for playing!");
            io.WriteLine($"You won {gamesWon} out of {totalGames} games");

            // use when debugging to keep window open
            io.Read();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Common.typedPrintln("Welcome to my house.**");
            string name = Prompt.GetString("Who are you?");

            // Admin feature - List all logged exceptions (which are probably problem patrons)
            if (name.ToLower() == "admin")
            {
                Console.Clear();
                List <ExceptionEntity> Exceptions = ReadExceptions();
                foreach (var e in Exceptions)
                {
                    Console.WriteLine(String.Format("{0} | {1} | {2} | {3}",
                                                    e.id, e.ExceptionType, e.ExceptionMessage, e.TimeStamp));
                }
                Console.Read();
                Common.typedPrintln("Thank you for your service.**");
                return; // Exit the prog early
            }

            // Lockout feature - prevent banned patrons from re-entering
            if (CheckDBForBannedPatron(name))
            {
                Common.typedPrintln("Hey!* Get outta here, rat!***");
                return; // Exit the prog early
            }

            int money = Prompt.GetInt("How much money do you have?** just curious.");

            Prompt.GetString("And what's your social security number?** j*u*s*t* c*u*r*i*o*u*s.");
            Common.WaitEllipses("Inserting you into gambling", 2000);
            Console.Clear();

            Common.typedPrint("Hello there, chubby!** I've heard you have fresh money for me to take--*I mean,* " +
                              "for you to play with.**\nWe're gonna have a lotta fun, boy!* Just you wait.");
            Common.Wait(2000);
            Console.Clear();

            // Init Game
            Player player = new Player(name, money);
            Game   game   = new BlackjackGame();

            game          += player;
            player.playing = true;

            // Game Loop
            game.init();
            while (player.playing && player.funds > 0)
            {
                game.preRound();

                // It's either this or move preRound() after postRound(). Which is fine.
                // It creates a bug, though; you can start out with less than the table limit and get stuck in a betting loop.
                if (!player.playing)
                {
                    continue;
                }

                game.round();
                game.postRound();
            }

            Common.typedPrintln("Goodbye, young man.***");
        }