コード例 #1
0
ファイル: ConsoleUI.cs プロジェクト: iamhere2/HLCD-Researches
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public CommandCycle(
     IConsoleIO consoleIO,
     GameCmdHandler gameCmdHandler,
     TurnCmdHandler turnCmdHandler,
     BoardPrinter boardPrinter,
     CommandParser commandParser)
 {
     Console        = consoleIO;
     GameCmdHandler = gameCmdHandler;
     TurnCmdHandler = turnCmdHandler;
     BoardPrinter   = boardPrinter;
     CommandParser  = commandParser;
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
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();
        }
コード例 #7
0
 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));
 }
コード例 #8
0
 public BlackjackGame()
 {
     _io = Dependencies.consoleIO.make();
     ops = new BlackjackOperations(_io); // pass in dependencies??
 }
コード例 #9
0
 public BoardPrinter(IConsoleIO consoleIO, GameFlow gameFlow)
 {
     Console  = consoleIO;
     GameFlow = gameFlow;
 }
コード例 #10
0
 public BlackjackOperations(IConsoleIO io) // what needs to be passed in??
 {
     _io = io;
 }
コード例 #11
0
 public HumanPlayer(IConsoleIO io)
 {
     _name = DEFAULT_NAME;
     _hand = new Hand();
     _io   = io;
 }
コード例 #12
0
 public HumanPlayer(string name, IConsoleIO io) : this(io)
 {
     _name = name;
 }
コード例 #13
0
 public Dealer(IConsoleIO io)
 {
     _name = DEFAULT_NAME;
     _hand = new Hand();
     _io   = io;
 }
コード例 #14
0
 public HumanPlayer()
 {
     _name = DEFAULT_NAME;
     _hand = new Hand();
     _io   = Dependencies.consoleIO.make();
 }
コード例 #15
0
 public Dealer(string name, IConsoleIO io) : this(io)
 {
     _name = name;
 }
コード例 #16
0
 public BlackjackGame(IConsoleIO io)
 {
     _io = io;
     ops = new BlackjackOperations(_io); // pass in dependencies??
 }
コード例 #17
0
 public ComputerPlayer(IConsoleIO io)
 {
     _name = DEFAULT_NAME;
     _hand = new Hand();
     _io   = io;
 }
コード例 #18
0
 public GameCmdHandler(GameFlow gameFlow, IStorage storage, IConsoleIO consoleIO)
 {
     GameFlow = CheckArg.NotNull(gameFlow);
     Storage  = CheckArg.NotNull(storage);
     Console  = CheckArg.NotNull(consoleIO);
 }
コード例 #19
0
 public ComputerPlayer(string name, IConsoleIO io) : this(io)
 {
     _name = name;
 }