//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(); }
public PlayerAction NextAction(IHand otherHand) { // This needs to prompt the user for their choice of action PlayerAction nextAction = PlayerAction.Invalid; int i = 0; do { string actionEntered = _io.PromptForString("Enter Action H)it, S)tand, B)ust:"); nextAction = ParseAction(actionEntered); if (nextAction == PlayerAction.Invalid) { _io.WriteLine("Invalid action entered"); i++; } } while (nextAction == PlayerAction.Invalid && i < MAXRETRIES); return(nextAction); }
public void DisplayResults(Dealer dealer, IPlayer player, GameResult result) { string displayResults = GetGameResultsDisplay(dealer, player, result); _io.WriteLine(displayResults); }