示例#1
0
        /// <summary>
        /// Potyogós Amőba nézetmodell példányosítása.
        /// </summary>
        /// <param name="model">A modell típusa.</param>
        public AmobaViewModel(PAmobaModel model)
        {
            _model           = model;
            _model.GameOver += new EventHandler <AmobaEvent>(Model_GameOver);
            _model.Refresh  += new EventHandler(Model_GameAdvanced);
            _model.Reset    += new EventHandler(Model_Reset);

            NewGameCommand      = new DelegateCommand(param => OnNewGame(Convert.ToInt32(param)));
            LoadGameOpenCommand = new DelegateCommand(async param =>
            {
                Games = new ObservableCollection <SaveEntry>(await _model.ListGamesAsync());
                OnLoadGameOpen();
            });
            LoadGameCloseCommand = new DelegateCommand(
                param => SelectedGame != null, // parancs végrehajthatóságának feltétele
                param => { OnLoadGameClose(SelectedGame.Name); });
            SaveGameOpenCommand = new DelegateCommand(async param =>
            {
                Games = new ObservableCollection <SaveEntry>(await _model.ListGamesAsync());
                OnSaveGameOpen();
            });
            SaveGameCloseCommand = new DelegateCommand(
                param => NewName.Length > 0, // parancs végrehajthatóságának feltétele
                param => { OnSaveGameClose(NewName); });
            ExitCommand  = new DelegateCommand(param => OnExitGame());
            PauseCommand = new DelegateCommand(param => OnGamePause());

            isPaused = false;

            ResetFields();

            RefreshTable();
        }
示例#2
0
        /// <summary>
        /// Játék mentésének eseménykezelője.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="name">Új mentés neve</param>
        private async void ViewModel_SaveGameClose(object sender, String name)
        {
            if (name != null)
            {
                try
                {
                    // felülírás ellenőrzése
                    var games = await _model.ListGamesAsync();

                    if (games.All(g => g.Name != name) ||
                        MessageBox.Show("Biztos, hogy felülírja a meglévő mentést?", "PotyogosAmoba",
                                        MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        await _model.SaveGame(name);
                    }
                }
                catch
                {
                    MessageBox.Show("Játék mentése sikertelen!", "Hiba!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            _saveWindow.Close(); // játékállapot mentő ablak bezárása
        }