diff --git a/Airbus/Airbus/DrawningSuperAirbus.cs b/Airbus/Airbus/DrawningSuperAirbus.cs index 4d3b1ba..2658f09 100644 --- a/Airbus/Airbus/DrawningSuperAirbus.cs +++ b/Airbus/Airbus/DrawningSuperAirbus.cs @@ -45,7 +45,5 @@ namespace Airbus g.DrawEllipse(pen, _startPosX + 24, _startPosY + 22, 10, 5); } } - - } } diff --git a/Airbus/Airbus/ExtentionPlane.cs b/Airbus/Airbus/ExtentionPlane.cs index 7723c9e..0d14a3a 100644 --- a/Airbus/Airbus/ExtentionPlane.cs +++ b/Airbus/Airbus/ExtentionPlane.cs @@ -25,7 +25,7 @@ namespace Airbus } //если аэробус - if(strs.Length == 5) + if(strs.Length == 6) { return new DrawningSuperAirbus(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), Color.FromName(strs[3]), Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5])); diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs index 9c70f14..fd70732 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -72,7 +72,7 @@ this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Location = new System.Drawing.Point(843, 28); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(250, 694); + this.groupBoxTools.Size = new System.Drawing.Size(250, 769); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; @@ -145,7 +145,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.Right; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(158, 629); + this.buttonRight.Location = new System.Drawing.Point(158, 704); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(45, 45); this.buttonRight.TabIndex = 9; @@ -157,7 +157,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.Down; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(107, 629); + this.buttonDown.Location = new System.Drawing.Point(107, 704); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(45, 45); this.buttonDown.TabIndex = 8; @@ -169,7 +169,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.Left; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(56, 629); + this.buttonLeft.Location = new System.Drawing.Point(56, 704); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(45, 45); this.buttonLeft.TabIndex = 7; @@ -181,7 +181,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.Up; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(107, 578); + this.buttonUp.Location = new System.Drawing.Point(107, 653); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(45, 45); this.buttonUp.TabIndex = 6; @@ -241,7 +241,7 @@ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 28); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(843, 694); + this.pictureBox.Size = new System.Drawing.Size(843, 769); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -291,7 +291,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1093, 722); + this.ClientSize = new System.Drawing.Size(1093, 797); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.menuStrip); diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 8ea423b..14d8c07 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -230,10 +230,11 @@ namespace Airbus //обработка нажатия загрузки private void LoadToolStripMenuItem_Click(object sender, EventArgs e) { - if (saveFileDialog.ShowDialog() == DialogResult.OK) + if (openFileDialog.ShowDialog() == DialogResult.OK) { if (_mapsCollection.LoadData(openFileDialog.FileName)) { + ReloadMaps(); MessageBox.Show("Загрузка данных прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } diff --git a/Airbus/Airbus/FormMapWithSetPlanes.resx b/Airbus/Airbus/FormMapWithSetPlanes.resx index 985a3e4..77f1fe0 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.resx +++ b/Airbus/Airbus/FormMapWithSetPlanes.resx @@ -66,4 +66,7 @@ 311, 17 + + 25 + \ No newline at end of file diff --git a/Airbus/Airbus/FormPlaneConfig.Designer.cs b/Airbus/Airbus/FormPlaneConfig.Designer.cs index a1a98b6..73b124b 100644 --- a/Airbus/Airbus/FormPlaneConfig.Designer.cs +++ b/Airbus/Airbus/FormPlaneConfig.Designer.cs @@ -146,7 +146,7 @@ // // panelPurple // - this.panelPurple.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(192))))); + this.panelPurple.BackColor = System.Drawing.Color.DeepPink; this.panelPurple.Location = new System.Drawing.Point(192, 79); this.panelPurple.Name = "panelPurple"; this.panelPurple.Size = new System.Drawing.Size(40, 40); diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index 30f8c4e..c0936a0 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -38,22 +38,19 @@ namespace Airbus //добавление карты public void AddMap(string name, AbstractMap map) { - var NewElem = new MapWithSetPlanesGeneric( - _pictureWidth, _pictureHeight, map); - _mapStorage.Add(name, NewElem); + if (!_mapStorage.ContainsKey(name)) + { + _mapStorage.Add(name, new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map)); + } } //удаление карты public void DelMap(string name) { - _mapStorage.Remove(name); - } - - //метод записи информации в файл - private static void WriteToFile(string text, FileStream stream) - { - byte[] info = new UTF8Encoding(true).GetBytes(text); - stream.Write(info, 0, info.Length); + if (_mapStorage.ContainsKey(name)) + { + _mapStorage.Remove(name); + } } //сохранение информации по самолётам в ангарах в файл @@ -64,14 +61,15 @@ namespace Airbus File.Delete(filename); } - using (FileStream fs = new(filename, FileMode.Create)) + using (StreamWriter sw = new(filename)) { - WriteToFile($"MapsCollection{Environment.NewLine}", fs); + sw.Write($"MapsCollection{Environment.NewLine}"); + foreach (var storage in _mapStorage) { - WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" + - $"{Environment.NewLine}", fs); + sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" + + $"{Environment.NewLine}"); } } @@ -86,52 +84,41 @@ namespace Airbus return false; } - string bufferTextFromFile = ""; - - using (FileStream fs = new(filename, FileMode.Open)) + using (StreamReader sr = new(filename)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); + string str = sr.ReadLine(); - while (fs.Read(b, 0, b.Length) > 0) + //если не содержит такую запись + if (!str.Contains("MapsCollection")) { - bufferTextFromFile += temp.GetString(b); - } - } - - var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); - - if (!strs[0].Contains("MapsCollection")) - { - //если нет такой записи, то это не те данные - return false; - } - - //очищаем записи - _mapStorage.Clear(); - - for (int i = 1; i < strs.Length; ++i) - { - var elem = strs[i].Split(separatorDict); - AbstractMap map = null; - - switch (elem[1]) - { - case "SimpleMap": - map = new SimpleMap(); - break; - case "DesertStormMap": - map = new DesertStormMap(); - break; - case "StarWarsMap": - map = new StarWarsMap(); - break; + return false; } - _mapStorage.Add(elem[0], new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, + _mapStorage.Clear(); + + while ((str = sr.ReadLine()) != null) + { + var element = str.Split(separatorDict); + AbstractMap map = null; + + switch (element[1]) + { + case "SimpleMap": + map = new SimpleMap(); + break; + case "DesertStormMap": + map = new DesertStormMap(); + break; + case "StarWarsMap": + map = new StarWarsMap(); + break; + } + + _mapStorage.Add(element[0], new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorage[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); + _mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); + } } return true; @@ -143,7 +130,17 @@ namespace Airbus { get { - return _mapStorage[ind]; + if(ind != String.Empty) + { + MapWithSetPlanesGeneric value; + + if(_mapStorage.TryGetValue(ind, out value)) + { + return value; + } + } + + return null; } } } diff --git a/Airbus/Airbus/SaveData.txt b/Airbus/Airbus/SaveData.txt new file mode 100644 index 0000000..737d3b9 --- /dev/null +++ b/Airbus/Airbus/SaveData.txt @@ -0,0 +1,3 @@ +MapsCollection +123|StarWarsMap|1000:750:Yellow;1000:750:Lime:Red:True:True; +456|DesertStormMap|1000:750:Red;1000:750:Blue;1000:750:DeepPink:Lime:True:True;