示例#1
0
        public Options()
        {
            // The GameOptions class has a static method that handles loading the options and
            // creating an instance of itself.
            _gameOptions = GameOptions.Create();

            // This allows controls to bind to an instance of this object just by specifying the
            // property to use in the binding.
            DataContext = _gameOptions;

            InitializeComponent();
        }
示例#2
0
        /// <summary>
        /// Method used for the Executed part of the command bindings defined in the window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Close)
            {
                this.Close();
            }
            if (e.Command == GameViewModel.StartGameCommand)
            {
                var model = new GameViewModel();

                // Instantiate the start game dialog.
                StartGame startGameDialog = new StartGame();

                // Load the game options, and set them as the data context for the start game window.
                var options = GameOptions.Create();
                startGameDialog.DataContext = options;

                // Display the start game dialog.
                var result = startGameDialog.ShowDialog();
                if (result.HasValue && result.Value == true)
                {
                    // The user clicked OK on the start game dialog, so save the options, tell the
                    // model to start a new game, and set the model as the data context for the game
                    // client window.
                    options.Save();
                    model.StartNewGame();
                    DataContext = model;
                }
            }
            if (e.Command == GameOptions.OptionsCommand)
            {
                // Instantiate and display the options window.
                var dialog = new Options();
                var result = dialog.ShowDialog();

                // If the user clicked OK in the options dialog, clear the current game.
                if (result.HasValue && result.Value == true)
                {
                    DataContext = new GameViewModel();
                }
            }
            if (e.Command == GameViewModel.ShowAboutCommand)
            {
                // Instantiate and display the about dialog.
                var dialog = new About();
                dialog.ShowDialog();
            }
            e.Handled = true;
        }
示例#3
0
 private void CommandExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     if (e.Command == ApplicationCommands.Close)
     {
         this.Close();
     }
     if (e.Command == GameViewModel.StartGameCommand)
     {
         var       model           = new GameViewModel();
         StartGame startGameDialog = new StartGame();
         var       options         = GameOptions.Create();
         startGameDialog.DataContext = options;
         var result = startGameDialog.ShowDialog();
         if (result.HasValue && result.Value == true)
         {
             options.Save();
             model.StartNewGame();
             DataContext = model;
         }
     }
     if (e.Command == GameOptions.OptionsCommand)
     {
         var dialog = new Options();
         var result = dialog.ShowDialog();
         if (result.HasValue && result.Value == true)
         {
             DataContext = new GameViewModel(); // Clear current game
         }
     }
     if (e.Command == GameViewModel.ShowAboutCommand)
     {
         var dialog = new About();
         dialog.ShowDialog();
     }
     e.Handled = true;
 }
示例#4
0
 public Options()
 {
     _gameOptions = GameOptions.Create();
     DataContext  = _gameOptions;
     InitializeComponent();
 }
 public GameViewModel()
 {
     _players     = new List <Player>();
     _gameOptions = GameOptions.Create();
 }