示例#1
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;
        }
示例#2
0
 public Options()
 {
     _gameOptions = GameOptions.Create();
     DataContext  = _gameOptions;
     InitializeComponent();
 }
 //添加一个新的默认构造函数
 public GameViewModel()
 {
     _players     = new List <Player>();
     _gameOptions = GameOptions.Create();
 }