/// <summary>
        ///     Initializes a new instance of the <see cref="MainWindow" /> class.
        /// </summary>
        public MainWindow()
        {
            this.InitializeComponent();

            if (File.Exists(MinesweeperGameController.PlayersFilename))
            {
                this.players =
                    MinesweeperGameData.Load<List<MinesweeperPlayer>>(MinesweeperGameController.PlayersFilename);
            }
            else
            {
                this.players = new List<MinesweeperPlayer>();
            }

            this.view = new WpfView(this.WinesweeperGrid);
            this.Width = 240;
            this.Height = 340;
            this.gameController =
                new MinesweeperGameController(
                    MinesweeperGridFactory.CreateNewTable(MinesweeperDifficultyType.Easy),
                    this.view,
                    new WpfTimer(new DispatcherTimer(), new TimeSpan(0, 0, 1)),
                    this.players,
                    MinesweeperDifficultyType.Easy);
        }
        /// <summary>
        /// The start game menu.
        /// </summary>
        /// <param name="output">
        /// The output.
        /// </param>
        /// <param name="view">
        /// The console view.
        /// </param>
        /// <param name="timer">
        /// The console timer.
        /// </param>
        public static void StartGameMenu(
            IConsoleWrapper<ConsoleColor, ConsoleKeyInfo> output, 
            IConsoleView view, 
            ConsoleTimer timer)
        {
            EventHandler ev1 =
                (sender, args) =>
                    {
                        gameController =
                            new MinesweeperGameController(
                                MinesweeperGridFactory.CreateNewTable(MinesweeperDifficultyType.Easy),
                                view,
                                timer,
                                LoadPlayers(),
                                MinesweeperDifficultyType.Easy);
                    };

            EventHandler ev2 =
                (sender, args) =>
                    {
                        gameController =
                            new MinesweeperGameController(
                                MinesweeperGridFactory.CreateNewTable(MinesweeperDifficultyType.Medium),
                                view,
                                timer,
                                LoadPlayers(),
                                MinesweeperDifficultyType.Medium);
                    };

            EventHandler ev3 =
                (sender, args) =>
                    {
                        gameController =
                            new MinesweeperGameController(
                                MinesweeperGridFactory.CreateNewTable(MinesweeperDifficultyType.Hard),
                                view,
                                timer,
                                LoadPlayers(),
                                MinesweeperDifficultyType.Hard);
                    };

            EventHandler ev4 = (sender, args) => { StartMainMenu(output); };

            DisplayFourItemsMenu("Easy", "Medium", "Hard", "Back", ev1, ev2, ev3, ev4, output);
        }
        public void TestControllerAddPlayerShouldExecuteCorrectly()
        {
            var grid = this.GridMock();
            var view = this.ViewMock();
            var timer = this.TimerMock();
            var players = new List<MinesweeperPlayer>();
            var controller = new MinesweeperGameController(
                grid.Object,
                view.Object,
                timer.Object,
                players,
                MinesweeperDifficultyType.Easy);
            var args = new MinesweeperAddPlayerEventArgs { PlayerName = "test" };

            this.isScoreBoardDisplayed = false;
            view.Raise(e => e.AddPlayerEvent += null, args);

            Assert.AreEqual(players[0].Name, "test", "Player not added!");
        }
        public void TestControllerDisplayScoreBoardShouldExecuteCorrectly()
        {
            var grid = this.GridMock();
            var view = this.ViewMock();
            var timer = this.TimerMock();
            var controller = new MinesweeperGameController(
                grid.Object,
                view.Object,
                timer.Object,
                new List<MinesweeperPlayer>(),
                MinesweeperDifficultyType.Easy);

            this.isScoreBoardDisplayed = false;
            view.Raise(e => e.ShowScoreBoardEvent += null, EventArgs.Empty);

            Assert.AreEqual(this.isScoreBoardDisplayed, true, "Score board is not displayed!");
        }
 public void TestNullViewShouldThrow()
 {
     var controller = new MinesweeperGameController(
         this.GridMock().Object,
         null,
         this.TimerMock().Object,
         new List<MinesweeperPlayer>(),
         MinesweeperDifficultyType.Easy);
 }
        public void TestControllerOnTickEventShouldDisplayGrid()
        {
            var grid = this.GridMock();
            var view = this.ViewMock();
            var timer = this.TimerMock();
            var players = new List<MinesweeperPlayer>();
            var controller = new MinesweeperGameController(
                grid.Object,
                view.Object,
                timer.Object,
                players,
                MinesweeperDifficultyType.Easy);
            var args = new MinesweeperCellClickEventArgs { Row = 1, Col = 1 };
            this.isGridDisplayed = false;

            this.isScoreBoardDisplayed = false;
            view.Raise(e => e.OpenCellEvent += null, args);
            view.Raise(e => e.ProtectCellEvent += null, args);
            timer.Raise(e => e.TickEvent += null, EventArgs.Empty);

            Assert.AreEqual(this.isGridDisplayed, true, "Grid not displayed!");
        }
 /// <summary>
 /// The menu item_ new medium game_ click.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The click event.
 /// </param>
 private void MenuItemNewMediumGameClick(object sender, RoutedEventArgs e)
 {
     this.Width = 380;
     this.Height = 480;
     this.view = new WpfView(this.WinesweeperGrid);
     this.gameController =
         new MinesweeperGameController(
             MinesweeperGridFactory.CreateNewTable(MinesweeperDifficultyType.Medium),
             this.view,
             new WpfTimer(new DispatcherTimer(), new TimeSpan(0, 0, 1)),
             this.players,
             MinesweeperDifficultyType.Medium);
 }