コード例 #1
0
 /// <summary>
 /// User clicked to button Load game configuration
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void BLoad_Click(object sender, EventArgs e)
 {
     ODForFileSelect.Filter   = "File with game configuration|*.tdgc";
     ODForFileSelect.FileName = "*.tdgc";
     if (ODForFileSelect.ShowDialog() == DialogResult.OK)
     {
         if (ODForFileSelect.FileName.LastIndexOf(".tdgc", StringComparison.Ordinal) == -1)
         {
             MessageBox.Show("Wrong file selected");
             return;
         }
         int levelsCount;
         try//Loading main configuration
         {
             BinaryReader loadMainConf = new BinaryReader(new FileStream(ODForFileSelect.FileName, FileMode.Open, FileAccess.Read));
             object[]     tmp;
             SaveNLoad.LoadMainGameConf(loadMainConf, out _numberOfMonstersAtLevel, out _goldForSuccessfulLevelFinish, out _goldForKillMonster, out tmp);
             string mapName = (string)tmp[0]; //0-Map name
             if (!ShowMapByFileName(mapName)) //If map file doesn't exists at path from configuration file, try to get it from folder with configuration
             {
                 ShowMapByFileName(ODForFileSelect.FileName.Substring(0, ODForFileSelect.FileName.LastIndexOf("\\", StringComparison.Ordinal) + 1) + mapName.Substring(mapName.LastIndexOf("\\", StringComparison.Ordinal)));
             }
             TBTowerFolder.Text    = (string)tmp[1];                                                 //1-Nam of the folder with towers configurations
             levelsCount           = (int)tmp[2];                                                    //2-Number of levels
             mTBGoldAtStart.Text   = Convert.ToInt32(tmp[4]).ToString(CultureInfo.InvariantCulture); //4-Money
             mTBNumberOfLives.Text = Convert.ToInt32(tmp[5]).ToString(CultureInfo.InvariantCulture); //5-Lives
             loadMainConf.Close();
         }
         catch (Exception exc)
         {
             MessageBox.Show(Resources.Load_error + exc.Message);
             return;
         }
         try//Loading configurations of levels
         {
             string     levelFileName   = ODForFileSelect.FileName.Substring(0, ODForFileSelect.FileName.LastIndexOf('.')) + ".tdlc";
             FileStream levelLoadStream = new FileStream(levelFileName, FileMode.Open, FileAccess.Read);
             IFormatter formatter       = new BinaryFormatter();
             _levelsConfig.Clear();
             for (int i = 0; i < levelsCount; i++)
             {
                 _levelsConfig.Add((MonsterParam)(formatter.Deserialize(levelLoadStream)));
             }
             levelLoadStream.Close();//All loaded, stream closing
             _currentLevel = 1;
             ShowLevelSettings(1);
             BRemoveLevel.Enabled = true;
             if (_levelsConfig.Count() > 1)
             {
                 BLoadMonsterPict.Enabled     = true;
                 GBNumberOfDirections.Enabled = true;
             }
         }
         catch (Exception exc)
         {
             MessageBox.Show(Resources.Load_error + exc.Message);
             return;
         }
     }
     BNewGameConfig.Tag    = 2;
     GBLevelConfig.Enabled = true;
     GBMapManage.Enabled   = true;
     if (_levelsConfig.Count != 0)
     {
         CBLevelInvisible.Enabled = true;
     }
     if (_levelsConfig.Count > 1)
     {
         BPrevLevel.Enabled = true;
         BNextLevel.Enabled = true;
     }
     BSave.Enabled = true;
 }