public void Setup() { mockConsoleIO = new ConsoleIOMock(); Dependencies.consoleIO.ConstantValue = mockConsoleIO; mockConsoleIO.ResetConsole(); ops = new BlackjackOperations(mockConsoleIO); }
public void play_a_simulated_game_dealer_wins() { //Dependencies.randomSeeds.ConstantValue = 1235; Dependencies.randomInstance.ConstantValue = new Random(1235); Dependencies.consoleIO.ConstantValue = mockConsoleIO; mockConsoleIO.ResetConsole(); mockConsoleIO.LoadReadValue("H"); mockConsoleIO.LoadReadValue("S"); BlackjackGame game = new BlackjackGame(); string playerName = "Billy Joel"; Dealer dealer = new Dealer(); IPlayer player = new HumanPlayer(playerName); IDeck deck = BlackjackOperations.GetAndShuffleNewDeck(); game.play(deck, dealer, player); int i = 0; Assert.AreEqual($"Player {playerName}, Score=14", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Jack of Spades,Four of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer Score Showing=4", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"{Hand.FACEDOWN},Four of Clubs", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Enter Action H)it, S)tand, B)ust:", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName} Action=Hit", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName}, Score=20", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Jack of Spades,Four of Hearts,Six of Spades", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Enter Action H)it, S)tand, B)ust:", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName} Action=Stand", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer Action=Hit", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"{Hand.FACEDOWN},Four of Clubs,Seven of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer Action=Stand", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer wins!", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName}, Score=20", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Jack of Spades,Four of Hearts,Six of Spades", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer Score Showing=21", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"King of Clubs,Four of Clubs,Seven of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Dependencies.consoleIO.reset(); Dependencies.randomSeeds.reset(); Dependencies.randomInstance.reset(); }
//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 void play_a_simulated_game_player_busts() { //Dependencies.randomSeeds.ConstantValue = 1236; Dependencies.randomInstance.ConstantValue = new Random(1236); Dependencies.consoleIO.ConstantValue = mockConsoleIO; mockConsoleIO.ResetConsole(); mockConsoleIO.LoadReadValue("H"); BlackjackGame game = new BlackjackGame(); string playerName = "Mickey"; Dealer dealer = new Dealer(); IPlayer player = new HumanPlayer(playerName); IDeck deck = BlackjackOperations.GetAndShuffleNewDeck(); game.play(deck, dealer, player); int i = 0; Assert.AreEqual($"Player {playerName}, Score=14", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Jack of Hearts,Four of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer Score Showing=10", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"{Hand.FACEDOWN},Queen of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Enter Action H)it, S)tand, B)ust:", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName} Action=Hit", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName} Action=Busted", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName}, Score=24", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Jack of Hearts,Four of Hearts,Ten of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer wins!", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Player {playerName}, Score=24", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Jack of Hearts,Four of Hearts,Ten of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Dealer Score Showing=16", mockConsoleIO.GetConsoleWrites()[i++]); Assert.AreEqual($"Six of Hearts,Queen of Hearts", mockConsoleIO.GetConsoleWrites()[i++]); Dependencies.consoleIO.reset(); //Dependencies.randomSeeds.reset(); Dependencies.randomInstance.reset(); }