Exemplo n.º 1
0
        public GameViewModel(String filepath)
        {
            Options = new ObservableCollection <Fields.OptionField>();

            NewCommand  = new DelegateCommand(x => OnNew());
            SaveCommand = new DelegateCommand(x =>
            {
                FileHandler.FileHandler.Write(filepath,
                                              _player,
                                              typeof(Model.MapRelated.Map));
                OnShowMessage("Save successfully completed!");
            });
            LoadCommand = new DelegateCommand(x => OnLoad());
            QuitCommand = new DelegateCommand(x => OnQuit());

            StatsCommand     = new DelegateCommand(x => OnShowStats());
            InventoryCommand = new DelegateCommand(x => OnShowInventory());

            //Set up map & player
            try
            {
                _player = FileHandler.FileHandler.Read <Model.CharacterRelated.Character>(
                    filepath,
                    typeof(Model.MapRelated.Map));
            }
            catch (FileHandler.Exceptions.ReadException ex)
            {
                throw new Exceptions.LoadException(ex.Message);
            }

            try
            {
                _map = Model.MapRelated.RegionManager.getMap(_player.Location.Region);
                _map.SetUp(_player.Location.SubRegion);
            }
            catch
            {
                throw new Exceptions.LoadException("The selected map file is missing or corrupted. Cannot load character.");
            }

            _map.Battle         += new EventHandler(Map_Battle);
            _map.VariableSet    += new EventHandler(Map_VariableSet);
            _map.ExperienceGain += new EventHandler(Map_ExperienceGain);
            _map.ItemGain       += new EventHandler(Map_ItemGain);
            _map.ChangeRegion   += new EventHandler(Map_ChangeRegion);

            RefreshView();
        }
Exemplo n.º 2
0
 private void Map_ChangeRegion(object sender, EventArgs e)
 {
     _map = Model.MapRelated.RegionManager.getMap(_map.Current.Special.NewRegionName);
     RefreshView();
 }