Example #1
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!");
                }
            }
        }
Example #2
0
 public MainWindow(IMatrixAlgorithm matrixAlgorithm, IAiMove aiMove, ISerializeData serialize,
                   IDeSerializeData deserializeData, IIniParseData iniParseData, IDataBaseWriter dataBaseWriter)
 {
     this.matrixAlgorithm = matrixAlgorithm ?? throw new ArgumentNullException(nameof(matrixAlgorithm));
     this.aiMove          = aiMove ?? throw new ArgumentNullException(nameof(aiMove));
     this.serialize       = serialize ?? throw new ArgumentNullException(nameof(serialize));
     this.deserializeData = deserializeData ?? throw new ArgumentNullException(nameof(deserializeData));
     this.iniParseData    = iniParseData ?? throw new ArgumentNullException(nameof(iniParseData));
     this.dataBaseWriter  = dataBaseWriter ?? throw new ArgumentNullException(nameof(dataBaseWriter));
     this.settings        = new Settings
     {
         HistoryList = new List <History>()
     };
     this.gamePanel = new GamePanel();
     this.InitializeComponent();
     this.txtBoxTrackBar.Text = this.boardSizeTrackBar.Value.ToString();
 }