public ConsoleUI(GameFlow gameFlow, IConsoleIO console, IStorage storage, RulesEngine rulesEngine) { if (gameFlow is null) { throw new ArgumentNullException(nameof(gameFlow)); } if (console is null) { throw new ArgumentNullException(nameof(console)); } if (storage is null) { throw new ArgumentNullException(nameof(storage)); } if (rulesEngine is null) { throw new ArgumentNullException(nameof(rulesEngine)); } GameCmdHandler = new GameCmdHandler(gameFlow, storage, console); TurnCmdHandler = new TurnCmdHandler(rulesEngine); BoardPrinter = new BoardPrinter(console, gameFlow); CommandParser = new CommandParser(); CommandCycle = new CommandCycle(console, GameCmdHandler, TurnCmdHandler, BoardPrinter, CommandParser); }
public ConsoleUI(GameFlow gameFlow, IConsoleIO console, IStorage storage, RulesEngine rulesEngine) { CheckArg.NotNull(gameFlow); CheckArg.NotNull(console); CheckArg.NotNull(storage); CheckArg.NotNull(rulesEngine); GameCmdHandler = new GameCmdHandler(gameFlow, storage, console); TurnCmdHandler = new TurnCmdHandler(rulesEngine); BoardPrinter = new BoardPrinter(console, gameFlow); CommandParser = new CommandParser(); CommandCycle = new CommandCycle(console, GameCmdHandler, TurnCmdHandler, BoardPrinter, CommandParser); }
public CommandCycle( IConsoleIO consoleIO, GameCmdHandler gameCmdHandler, TurnCmdHandler turnCmdHandler, BoardPrinter boardPrinter, CommandParser commandParser) { Console = consoleIO; GameCmdHandler = gameCmdHandler; TurnCmdHandler = turnCmdHandler; BoardPrinter = boardPrinter; CommandParser = commandParser; }
public ChessApp(IConsoleIO console, IFileIO fileIO) { Console = console ?? throw new ArgumentNullException(nameof(console)); FileIO = fileIO ?? throw new ArgumentNullException(nameof(fileIO)); RulesEngine = new RulesEngine(); AiPlayer = new AiPlayer(RulesEngine); FileStorage = new FileStorage(FileIO); var lazyConsolePlayer = new LateBindingPlayerAdapter(); GameFlow = new GameFlow(lazyConsolePlayer, AiPlayer, RulesEngine); ConsoleUI = new ConsoleUI(GameFlow, Console, FileStorage, RulesEngine); lazyConsolePlayer.Bind(ConsoleUI); }
public ChessApp(IConsoleIO console, IFileIO fileIO) { // TODO: How to replace this boilerplate code with auto-generated? // Maybe, classical DI infrastructure could be used here in a local scope? Console = console ?? throw new ArgumentNullException(nameof(console)); FileIO = fileIO ?? throw new ArgumentNullException(nameof(fileIO)); RulesEngine = new RulesEngine(); AiPlayer = new AiPlayer(RulesEngine); FileStorage = new FileStorage(FileIO); var lazyConsolePlayer = new LateBindingPlayerAdapter(); GameFlow = new GameFlow(lazyConsolePlayer, AiPlayer, RulesEngine); ConsoleUI = new ConsoleUI(GameFlow, Console, FileStorage, RulesEngine); lazyConsolePlayer.Bind(ConsoleUI); }
//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 GameCmdHandler(GameFlow gameFlow, IStorage storage, IConsoleIO consoleIO) { GameFlow = gameFlow ?? throw new ArgumentNullException(nameof(gameFlow)); Storage = storage ?? throw new ArgumentNullException(nameof(storage)); Console = consoleIO ?? throw new ArgumentNullException(nameof(consoleIO)); }
public BlackjackGame() { _io = Dependencies.consoleIO.make(); ops = new BlackjackOperations(_io); // pass in dependencies?? }
public BoardPrinter(IConsoleIO consoleIO, GameFlow gameFlow) { Console = consoleIO; GameFlow = gameFlow; }
public BlackjackOperations(IConsoleIO io) // what needs to be passed in?? { _io = io; }
public HumanPlayer(IConsoleIO io) { _name = DEFAULT_NAME; _hand = new Hand(); _io = io; }
public HumanPlayer(string name, IConsoleIO io) : this(io) { _name = name; }
public Dealer(IConsoleIO io) { _name = DEFAULT_NAME; _hand = new Hand(); _io = io; }
public HumanPlayer() { _name = DEFAULT_NAME; _hand = new Hand(); _io = Dependencies.consoleIO.make(); }
public Dealer(string name, IConsoleIO io) : this(io) { _name = name; }
public BlackjackGame(IConsoleIO io) { _io = io; ops = new BlackjackOperations(_io); // pass in dependencies?? }
public ComputerPlayer(IConsoleIO io) { _name = DEFAULT_NAME; _hand = new Hand(); _io = io; }
public GameCmdHandler(GameFlow gameFlow, IStorage storage, IConsoleIO consoleIO) { GameFlow = CheckArg.NotNull(gameFlow); Storage = CheckArg.NotNull(storage); Console = CheckArg.NotNull(consoleIO); }
public ComputerPlayer(string name, IConsoleIO io) : this(io) { _name = name; }