public void StandardOnePlayerMinesweeperEngineTestClosedState()
        {
            AllocConsole();
            var testInputProvider = new Mock<IConsoleInputProvider>();
            testInputProvider.Setup(o => o.ReceiveInputLine()).Returns(value: "1 a");
            testInputProvider.Setup(o => o.TransformCommandToNumbersOnly("1 a")).Returns(value: "1 a");
            var testOutputRenderer = new ConsoleRenderer();
            var testScoreboard = new Mock<IScoreboard>();
            var testBoard = new Board(new EasyBoardSettings(), new List<IBoardObserver>());
            var testEngine = new StandardOnePlayerMinesweeperEngine(
                testBoard,
                testInputProvider.Object,
                testOutputRenderer,
                new CommandOperator(testBoard, testScoreboard.Object),
                testScoreboard.Object,
                new Player(name: "Gosho"));
            testEngine.Initialize(new StandardGameInitializationStrategy(new ContentFactory()));
            testEngine.Update(new Notification(message: "test", state: BoardState.Closed));

            bool completed = this.ExecuteWithTimeLimit(
                TimeSpan.FromMilliseconds(value: 200),
                () =>
                {
                    testEngine.Run();
                });
        }
コード例 #2
0
        /// <summary>
        /// Start Game logic
        /// </summary>
        public void Start()
        {
            // Initialize the two basic objects needed for user interactions
            this.InputProvider = this.inputProvider ?? new ConsoleInputProvider();
            this.OutputRenderer = this.outputRenderer ?? new ConsoleRenderer();

            // Render initial UI
            this.OutputRenderer.RenderWelcomeScreen(string.Join(string.Empty, RenderersConstants.GameTitle));
            this.OutputRenderer.RenderNewPlayerCreationRequest();

            // Create the active player
            var player = new Player(this.InputProvider.ReceiveInputLine());

            // Render console menu handler and execute logic for requesting board settings
            // TODO: Refactor menu handler logic
            int[] cursorPosition = this.OutputRenderer.GetCursor();
            var menuItems = new List<IGameMode>()
            {
                new BeginnerMode(),
                new IntermediateMode(),
                new ExpertMode()
            };

            var menuHandler = new ConsoleMenuHandler(this.inputProvider, this.outputRenderer, menuItems, cursorPosition[0] + 1, cursorPosition[1]);

            menuHandler.ShowSelections();

            BoardSettings boardSettings = menuHandler.RequestUserSelection();
            this.OutputRenderer.ClearScreen();
            this.OutputRenderer.SetCursor(visible: true);
            //// End of menu handler logic

            var board = new Board(boardSettings, new List<IBoardObserver>());
            var scoreboard = new Scoreboard();
            var contentFactory = new ContentFactory();
            var initializationStrategy = new StandardGameInitializationStrategy(contentFactory);
            var boardOperator = new CommandOperator(board, scoreboard);
            var engine = new StandardOnePlayerMinesweeperEngine(board, this.inputProvider, this.outputRenderer, boardOperator, scoreboard, player);

            engine.Initialize(initializationStrategy);
            board.Subscribe(engine);
            engine.Run();
        }
コード例 #3
0
        /// <summary>
        /// Start Game logic
        /// </summary>
        public void Start(Grid root)
        {
            // Initialize the two basic objects needed for user interactions
            this.InputProvider = this.inputProvider ?? new WpfInputProvider();
            this.OutputRenderer = this.outputRenderer ?? new WpfRenderer(root);

            string testPlayerName = "John";

            // Create the active player
            var player = new Player(testPlayerName);

            BoardSettings testBoardSettings = new EasyBoardSettings();

            var board = new Board(testBoardSettings, new List<IBoardObserver>());
            var scoreboard = new Scoreboard();
            var contentFactory = new ContentFactory();
            var initializationStrategy = new StandardGameInitializationStrategy(contentFactory);
            var boardOperator = new CommandOperator(board, scoreboard);
            var engine = new StandardOnePlayerMinesweeperEngine(board, this.inputProvider, this.outputRenderer, boardOperator, scoreboard, player);

            engine.Initialize(initializationStrategy);
            board.Subscribe(engine);
            engine.Run();
        }