public NewGamePresenterImpl(NewGameView view, IAirplanesRepository airplanesRepository, IEnvironmentRepository environmentRepository, IGamePlayRepository gamePlayRepository)
 {
     this.view = view;
     this.airplanesRepository   = airplanesRepository;
     this.environmentRepository = environmentRepository;
     this.gamePlayRepository    = gamePlayRepository;
 }
        public void NewGame()
        {
            // delete cache of last game
            if (File.Exists(SESSION_CACHE_FILE))
            {
                File.Delete(SESSION_CACHE_FILE);
            }

            // show new game dialog
            var dlg        = new NewGameView();
            var dlgContext = new NewGameViewModel(dlg);

            dlg.DataContext = dlgContext;
            var result = dlg.ShowDialog();

            if (result == true)
            {
                // init new game session with user inputs from dialog
                var humanPlayer      = new UIChessPlayer(dlgContext.DrawingSide);
                var artificialPlayer = new ArtificialChessPlayer(dlgContext.DrawingSide.Opponent(), dlgContext.Difficulty);

                _session = dlgContext.DrawingSide == ChessColor.White ? new ChessGameSession(humanPlayer, artificialPlayer) : new ChessGameSession(artificialPlayer, humanPlayer);
                _player  = humanPlayer;
                _session.BoardChanged += boardChanged;
                Board.UpdatePieces(ChessBitboard.StartFormation);

                // tell the player which side he draws if he choose random side
                if (dlgContext.SelectedDrawingSideMode == DrawingSideMode.Random)
                {
                    MessageBox.Show($"You draw the { dlgContext.DrawingSide.ToString() } pieces!", "Random Side Selection", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                // update status bar
                Status.InitNewGame();

                // start the game session in a background thread (async)
                Task.Run(() => {
                    // play game (until one player loses)
                    var final = _session.ExecuteGame();

                    // update status bar
                    var finalStatus = ChessDrawSimulator.Instance.GetCheckGameStatus(_session.Board, _session.Game.LastDraw);
                    Status.FinishGame(finalStatus);

                    // reset game session
                    Board.UpdateIsEnabled(false);
                });
            }

            // make the chess board inactive unless a game session is active
            updateIsBoardActive();
        }
        private void OnNewGameMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var view = new NewGameView();
            var b    = view.ShowDialog();

            if (b.Value)
            {
                var rows  = view.Rows;
                var cols  = view.Columns;
                var mines = view.Mines;

                var game = this.Service.NewGame(this.UserName, rows, cols, mines);
                this.LoadNewGame(game);
            }
        }
 public static NewGamePresenter injectNewGamePresenter(NewGameView view)
 {
     return(new NewGamePresenterImpl(view, injectAirplanesRepository(), injectEnvironmentRepository(), injectGamePlayRepository()));
 }