예제 #1
0
        private void MainWindow_FormClosing(Object sender, FormClosingEventArgs e)
        {
            //DataBaseWriter dataBaseWrite = new DataBaseWriter();
            this.mapper         = new BoardDataMapper();
            this.savedGameState = new SavedGameState
            {
                BoardSize        = this.matrixAlgorithm.BoardSize,
                CurrentTurn      = this.matrixAlgorithm.CurrentTurn,
                CurrentTurnCount = this.matrixAlgorithm.CurrentTurnCount,
                BoardData        = this.mapper.WriteCurrentBoardToString(this.matrixAlgorithm),
            };
            Data data = new Data
            {
                CurrentGame = this.savedGameState,
                Round       = this.settings.RoundCount,
                HistoryList = this.settings.HistoryList,
                Difficulty  = this.ChooseDifficulty()
            };
            HistoryData historyData = new HistoryData
            {
                HistoryList = this.settings.HistoryList,
            };

            dataBaseWriter.WriteDatabaseFile(historyData);
            this.serialize = (ISerializeData)SerDesFactory.Create(typeof(ISerializeData));
            this.serialize.SerializeJson(Application.StartupPath + "/settings/autosave.json", data);
            this.serialize.SerializeXml(Application.StartupPath + "/settings/autosave.xml", data);
        }
예제 #2
0
        private void BtnLoad_Click(Object sender, EventArgs e)
        {
            using (OpenFileDialog loadFileDialog = new OpenFileDialog())
            {
                loadFileDialog.Filter = "Configuration Files(*.json; *.xml; *.ini;)|*.json; *.xml; *.ini;";
                loadFileDialog.ShowDialog();

                this.iniParseData    = (IIniParseData)SerDesFactory.Create(typeof(IIniParseData));
                this.deserializeData = (IDeSerializeData)SerDesFactory.Create(typeof(IDeSerializeData));

                //try
                //{
                //    Data data = this.deserializeData.DeserializeJson(loadFileDialog.FileName);

                //    if (data is null)
                //    {
                //        return;
                //    }


                //    //data.CurrentGame => nix

                //}
                //catch (ArgumentOutOfRangeException arg)
                //{
                //    MessageBox.Show("Ein Fehler " + arg.Message);
                //    return;
                //}



                if (loadFileDialog.FileName.EndsWith(".json", StringComparison.InvariantCultureIgnoreCase))
                {
                    Data data = this.deserializeData.DeserializeJson(loadFileDialog.FileName);
                    this.RecoverData(data);
                    MessageBox.Show(Path.GetFileName(loadFileDialog.FileName) + " sucessfully loaded!");
                }
                else if (loadFileDialog.FileName.Contains(".xml"))
                {
                    Data data = this.deserializeData.DeserializeXml(loadFileDialog.FileName);
                    this.settings.XmlIsUsed = true;
                    this.RecoverData(data);
                    this.settings.XmlIsUsed = false;
                    MessageBox.Show(Path.GetFileName(loadFileDialog.FileName) + " sucessfully loaded!");
                }
                else if (loadFileDialog.FileName.EndsWith(".ini", StringComparison.InvariantCultureIgnoreCase))
                {
                    Data data = this.iniParseData.ReadIni(loadFileDialog.FileName);
                    this.RecoverData(data);
                    MessageBox.Show(Path.GetFileName(loadFileDialog.FileName) + " sucessfully loaded!");
                }
                else
                {
                    MessageBox.Show("Unable to load your progress!");
                }
            }
        }
예제 #3
0
        private void MainWindow_Load(Object sender, EventArgs e)
        {
            if (!Directory.Exists(Application.StartupPath + "/settings/"))
            {
                Directory.CreateDirectory(Application.StartupPath + "/settings/");
            }

            if (File.Exists(Application.StartupPath + "/settings/autosave.json"))
            {
                this.deserializeData = (IDeSerializeData)SerDesFactory.Create(typeof(IDeSerializeData));
                Data data = this.deserializeData.DeserializeJson(Application.StartupPath + "/settings/autosave.json");
                this.RecoverData(data);
            }
        }