diff --git a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs
index d2e3fdf..16f50af 100644
--- a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs
+++ b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs
@@ -36,5 +36,7 @@ namespace GasolineTanker
{
_gasolineTanker.DrawTransport(g);
}
+ public string GetInfo() => _gasolineTanker?.GetDataForSave();
+ public static IDrawingObject Create(string data) => new DrawingObjectGasolineTanker(data.CreateDrawingGasolineTanker());
}
}
diff --git a/GasolineTanker/GasolineTanker/ExtentionGasolineTanker.cs b/GasolineTanker/GasolineTanker/ExtentionGasolineTanker.cs
new file mode 100644
index 0000000..6ad36f6
--- /dev/null
+++ b/GasolineTanker/GasolineTanker/ExtentionGasolineTanker.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GasolineTanker
+{
+ internal static class ExtentionGasolineTanker
+ {
+ private static readonly char _separatorForObject = ':';
+
+ public static DrawingGasolineTanker CreateDrawingGasolineTanker(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+ if (strs.Length == 3)
+ {
+ return new DrawingGasolineTanker(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
+ }
+ if (strs.Length == 6)
+ {
+ return new DrawingImprovedGasolineTanker(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
+ Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
+ Convert.ToBoolean(strs[5]));
+ }
+ return null;
+ }
+ public static string GetDataForSave(this DrawingGasolineTanker drawingGasolineTanker)
+ {
+ var GasolineTanker = drawingGasolineTanker.GasolineTanker;
+ var str = $"{GasolineTanker.Speed}{_separatorForObject}{GasolineTanker.Weight}{_separatorForObject}{GasolineTanker.BodyColor.Name}";
+ if (GasolineTanker is not EntityImprovedGasolineTanker improvedGasolineTanker)
+ {
+ return str;
+ }
+ return $"{str}{_separatorForObject}{improvedGasolineTanker.DopColor.Name}{_separatorForObject}{improvedGasolineTanker.BodyKit}{_separatorForObject}{improvedGasolineTanker.OrnamentWheels}";
+ }
+ }
+}
diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs
index ac96937..fb24cb3 100644
--- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs
+++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs
@@ -45,9 +45,16 @@
this.buttonRemoveGasolineTanker = new System.Windows.Forms.Button();
this.buttonAddGasolineTanker = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.menuStrip = new System.Windows.Forms.MenuStrip();
+ this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
+ this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// groupBoxTools
@@ -63,11 +70,9 @@
this.groupBoxTools.Controls.Add(this.buttonRemoveGasolineTanker);
this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
- this.groupBoxTools.Location = new System.Drawing.Point(793, 0);
- this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.groupBoxTools.Location = new System.Drawing.Point(694, 24);
this.groupBoxTools.Name = "groupBoxTools";
- this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.groupBoxTools.Size = new System.Drawing.Size(229, 839);
+ this.groupBoxTools.Size = new System.Drawing.Size(200, 631);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools";
@@ -79,21 +84,18 @@
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
- this.groupBoxMaps.Location = new System.Drawing.Point(7, 29);
- this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.groupBoxMaps.Location = new System.Drawing.Point(6, 22);
this.groupBoxMaps.Name = "groupBoxMaps";
- this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.groupBoxMaps.Size = new System.Drawing.Size(217, 407);
+ this.groupBoxMaps.Size = new System.Drawing.Size(190, 305);
this.groupBoxMaps.TabIndex = 13;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Maps";
//
// buttonDeleteMap
//
- this.buttonDeleteMap.Location = new System.Drawing.Point(7, 321);
- this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonDeleteMap.Location = new System.Drawing.Point(6, 241);
this.buttonDeleteMap.Name = "buttonDeleteMap";
- this.buttonDeleteMap.Size = new System.Drawing.Size(200, 65);
+ this.buttonDeleteMap.Size = new System.Drawing.Size(175, 49);
this.buttonDeleteMap.TabIndex = 16;
this.buttonDeleteMap.Text = "Delete Map";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
@@ -102,20 +104,18 @@
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
- this.listBoxMaps.ItemHeight = 20;
- this.listBoxMaps.Location = new System.Drawing.Point(7, 188);
- this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.listBoxMaps.ItemHeight = 15;
+ this.listBoxMaps.Location = new System.Drawing.Point(6, 141);
this.listBoxMaps.Name = "listBoxMaps";
- this.listBoxMaps.Size = new System.Drawing.Size(201, 124);
+ this.listBoxMaps.Size = new System.Drawing.Size(176, 94);
this.listBoxMaps.TabIndex = 15;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// buttonAddMap
//
- this.buttonAddMap.Location = new System.Drawing.Point(7, 112);
- this.buttonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonAddMap.Location = new System.Drawing.Point(6, 84);
this.buttonAddMap.Name = "buttonAddMap";
- this.buttonAddMap.Size = new System.Drawing.Size(201, 68);
+ this.buttonAddMap.Size = new System.Drawing.Size(176, 51);
this.buttonAddMap.TabIndex = 14;
this.buttonAddMap.Text = "Add Map";
this.buttonAddMap.UseVisualStyleBackColor = true;
@@ -123,10 +123,9 @@
//
// textBoxNewMapName
//
- this.textBoxNewMapName.Location = new System.Drawing.Point(7, 32);
- this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.textBoxNewMapName.Location = new System.Drawing.Point(6, 24);
this.textBoxNewMapName.Name = "textBoxNewMapName";
- this.textBoxNewMapName.Size = new System.Drawing.Size(203, 27);
+ this.textBoxNewMapName.Size = new System.Drawing.Size(178, 23);
this.textBoxNewMapName.TabIndex = 13;
//
// comboBoxSelectorMap
@@ -136,20 +135,18 @@
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Simple map",
"Long map"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 71);
- this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 53);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(203, 28);
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(178, 23);
this.comboBoxSelectorMap.TabIndex = 12;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// maskedTextBoxPosition
//
- this.maskedTextBoxPosition.Location = new System.Drawing.Point(11, 521);
- this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 391);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27);
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 23);
this.maskedTextBoxPosition.TabIndex = 11;
//
// keyRight
@@ -157,10 +154,9 @@
this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight;
this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.keyRight.Location = new System.Drawing.Point(139, 783);
- this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.keyRight.Location = new System.Drawing.Point(122, 589);
this.keyRight.Name = "keyRight";
- this.keyRight.Size = new System.Drawing.Size(34, 40);
+ this.keyRight.Size = new System.Drawing.Size(30, 30);
this.keyRight.TabIndex = 10;
this.keyRight.UseVisualStyleBackColor = true;
this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click);
@@ -170,10 +166,9 @@
this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft;
this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.keyLeft.Location = new System.Drawing.Point(57, 783);
- this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.keyLeft.Location = new System.Drawing.Point(50, 589);
this.keyLeft.Name = "keyLeft";
- this.keyLeft.Size = new System.Drawing.Size(34, 40);
+ this.keyLeft.Size = new System.Drawing.Size(30, 30);
this.keyLeft.TabIndex = 9;
this.keyLeft.UseVisualStyleBackColor = true;
this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click);
@@ -183,10 +178,9 @@
this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp;
this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.keyUp.Location = new System.Drawing.Point(98, 735);
- this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.keyUp.Location = new System.Drawing.Point(86, 553);
this.keyUp.Name = "keyUp";
- this.keyUp.Size = new System.Drawing.Size(34, 40);
+ this.keyUp.Size = new System.Drawing.Size(30, 30);
this.keyUp.TabIndex = 8;
this.keyUp.UseVisualStyleBackColor = true;
this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click);
@@ -196,20 +190,18 @@
this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown;
this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.keyDown.Location = new System.Drawing.Point(98, 783);
- this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.keyDown.Location = new System.Drawing.Point(86, 589);
this.keyDown.Name = "keyDown";
- this.keyDown.Size = new System.Drawing.Size(34, 40);
+ this.keyDown.Size = new System.Drawing.Size(30, 30);
this.keyDown.TabIndex = 7;
this.keyDown.UseVisualStyleBackColor = true;
this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
- this.buttonShowOnMap.Location = new System.Drawing.Point(9, 667);
- this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowOnMap.Location = new System.Drawing.Point(8, 500);
this.buttonShowOnMap.Name = "buttonShowOnMap";
- this.buttonShowOnMap.Size = new System.Drawing.Size(213, 45);
+ this.buttonShowOnMap.Size = new System.Drawing.Size(186, 34);
this.buttonShowOnMap.TabIndex = 4;
this.buttonShowOnMap.Text = "Show on map";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
@@ -217,10 +209,9 @@
//
// buttonShowStorage
//
- this.buttonShowStorage.Location = new System.Drawing.Point(9, 613);
- this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowStorage.Location = new System.Drawing.Point(8, 460);
this.buttonShowStorage.Name = "buttonShowStorage";
- this.buttonShowStorage.Size = new System.Drawing.Size(213, 45);
+ this.buttonShowStorage.Size = new System.Drawing.Size(186, 34);
this.buttonShowStorage.TabIndex = 3;
this.buttonShowStorage.Text = "Show storage";
this.buttonShowStorage.UseVisualStyleBackColor = true;
@@ -228,10 +219,9 @@
//
// buttonRemoveGasolineTanker
//
- this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(9, 560);
- this.buttonRemoveGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(8, 420);
this.buttonRemoveGasolineTanker.Name = "buttonRemoveGasolineTanker";
- this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(213, 45);
+ this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(186, 34);
this.buttonRemoveGasolineTanker.TabIndex = 2;
this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker";
this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true;
@@ -239,10 +229,9 @@
//
// buttonAddGasolineTanker
//
- this.buttonAddGasolineTanker.Location = new System.Drawing.Point(11, 468);
- this.buttonAddGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonAddGasolineTanker.Location = new System.Drawing.Point(10, 351);
this.buttonAddGasolineTanker.Name = "buttonAddGasolineTanker";
- this.buttonAddGasolineTanker.Size = new System.Drawing.Size(213, 45);
+ this.buttonAddGasolineTanker.Size = new System.Drawing.Size(186, 34);
this.buttonAddGasolineTanker.TabIndex = 1;
this.buttonAddGasolineTanker.Text = "Add gasoline tanker";
this.buttonAddGasolineTanker.UseVisualStyleBackColor = true;
@@ -251,21 +240,61 @@
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBox.Location = new System.Drawing.Point(0, 0);
- this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.pictureBox.Location = new System.Drawing.Point(0, 24);
this.pictureBox.Name = "pictureBox";
- this.pictureBox.Size = new System.Drawing.Size(793, 839);
+ this.pictureBox.Size = new System.Drawing.Size(694, 631);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
+ // menuStrip
+ //
+ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.fileToolStripMenuItem});
+ this.menuStrip.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip.Name = "menuStrip";
+ this.menuStrip.Size = new System.Drawing.Size(894, 24);
+ this.menuStrip.TabIndex = 2;
+ //
+ // fileToolStripMenuItem
+ //
+ this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.SaveToolStripMenuItem,
+ this.LoadToolStripMenuItem});
+ this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
+ this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
+ this.fileToolStripMenuItem.Text = "File";
+ //
+ // SaveToolStripMenuItem
+ //
+ this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
+ this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.SaveToolStripMenuItem.Text = "Save";
+ this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
+ //
+ // LoadToolStripMenuItem
+ //
+ this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
+ this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.LoadToolStripMenuItem.Text = "Load";
+ this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
+ //
+ // openFileDialog
+ //
+ this.openFileDialog.Filter = "txt file | *.txt";
+ //
+ // saveFileDialog
+ //
+ this.saveFileDialog.Filter = "txt file | *.txt";
+ //
// FormMapWithSetGasolineTanker
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1022, 839);
+ this.ClientSize = new System.Drawing.Size(894, 655);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
- this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.Controls.Add(this.menuStrip);
+ this.MainMenuStrip = this.menuStrip;
this.Name = "FormMapWithSetGasolineTanker";
this.Text = "FormMapWithSetGasolineTanker";
this.groupBoxTools.ResumeLayout(false);
@@ -273,7 +302,10 @@
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.menuStrip.ResumeLayout(false);
+ this.menuStrip.PerformLayout();
this.ResumeLayout(false);
+ this.PerformLayout();
}
@@ -296,5 +328,11 @@
private TextBox textBoxNewMapName;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem fileToolStripMenuItem;
+ private ToolStripMenuItem SaveToolStripMenuItem;
+ private ToolStripMenuItem LoadToolStripMenuItem;
+ private OpenFileDialog openFileDialog;
+ private SaveFileDialog saveFileDialog;
}
}
\ No newline at end of file
diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs
index c44e29c..4026d55 100644
--- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs
+++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs
@@ -209,5 +209,36 @@ namespace GasolineTanker
MessageBox.Show("Errore delete object");
}
}
+
+ private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (saveFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_mapsCollection.SaveData(saveFileDialog.FileName))
+ {
+ MessageBox.Show("Save was successful", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show("Not preserved", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_mapsCollection.LoadData(openFileDialog.FileName))
+ {
+ MessageBox.Show("Download successful", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ ReloadMaps();
+ }
+ else
+ {
+ MessageBox.Show("Didn't load", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
}
}
diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.resx b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.resx
index f298a7b..934ed35 100644
--- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.resx
+++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.resx
@@ -57,4 +57,13 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
+
+ 125, 17
+
+
+ 265, 17
+
\ No newline at end of file
diff --git a/GasolineTanker/GasolineTanker/IDrawingObject.cs b/GasolineTanker/GasolineTanker/IDrawingObject.cs
index 43f1a65..8697e99 100644
--- a/GasolineTanker/GasolineTanker/IDrawingObject.cs
+++ b/GasolineTanker/GasolineTanker/IDrawingObject.cs
@@ -13,5 +13,6 @@ namespace GasolineTanker
void MoveObject(Direction direction);
void DrawningObject(Graphics g);
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
+ string GetInfo();
}
}
diff --git a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs
index cd44080..6db5ac2 100644
--- a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs
+++ b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs
@@ -66,7 +66,22 @@ namespace GasolineTanker
}
return new(_pictureWidth, _pictureHeight);
}
-
+ public string GetData(char separatorType, char separatorData)
+ {
+ string data = $"{_map.GetType().Name}{separatorType}";
+ foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker())
+ {
+ data += $"{gasolineTanker.GetInfo()}{separatorData}";
+ }
+ return data;
+ }
+ public void LoadData(string[] records)
+ {
+ foreach (var rec in records)
+ {
+ _setGasolineTanker.Insert(DrawingObjectGasolineTanker.Create(rec) as T);
+ }
+ }
private void Shaking()
{
int j = _setGasolineTanker.Count - 1;
diff --git a/GasolineTanker/GasolineTanker/MapsCollection.cs b/GasolineTanker/GasolineTanker/MapsCollection.cs
index 473b2bc..2c254f1 100644
--- a/GasolineTanker/GasolineTanker/MapsCollection.cs
+++ b/GasolineTanker/GasolineTanker/MapsCollection.cs
@@ -8,24 +8,26 @@ namespace GasolineTanker
{
internal class MapsCollection
{
- readonly Dictionary> _mapStorages;
+ readonly Dictionary> _mapStorages;
public List Keys => _mapStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
+ private readonly char separatorDict = '|';
+ private readonly char separatorData = ';';
public MapsCollection(int pictureWidth, int pictureHeight)
{
- _mapStorages = new Dictionary>();
+ _mapStorages = new Dictionary>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddMap(string name, AbstractMap map)
{
- if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetGasolienTankerGeneric(_pictureWidth, _pictureHeight, map));
+ if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetGasolienTankerGeneric(_pictureWidth, _pictureHeight, map));
}
public void DelMap(string name)
@@ -33,7 +35,7 @@ namespace GasolineTanker
_mapStorages.Remove(name);
}
- public MapWithSetGasolienTankerGeneric this[string ind]
+ public MapWithSetGasolienTankerGeneric this[string ind]
{
get
{
@@ -41,5 +43,55 @@ namespace GasolineTanker
return null;
}
}
+ public bool SaveData(string filename)
+ {
+ if (File.Exists(filename))
+ {
+ File.Delete(filename);
+ }
+ using (StreamWriter sw = new StreamWriter(filename))
+ {
+ sw.WriteLine($"MapsCollection");
+ foreach (var storage in _mapStorages)
+ {
+ sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}");
+ }
+ }
+ return true;
+ }
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+ using (StreamReader sr = new StreamReader(filename))
+ {
+ string str;
+ _mapStorages.Clear();
+ str = sr.ReadLine();
+ if (!str.Contains("MapsCollection"))
+ {
+ return false;
+ }
+ while ((str = sr.ReadLine()) != null)
+ {
+ var elem = str.Split(separatorDict);
+ AbstractMap map = null;
+ switch (elem[1])
+ {
+ case "Simple map":
+ map = new SimpleMap();
+ break;
+ case "Long map":
+ map = new LongMap();
+ break;
+ }
+ _mapStorages.Add(elem[0], new MapWithSetGasolienTankerGeneric(_pictureWidth, _pictureHeight, map));
+ _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
+ }
+ return true;
+ }
+ }
}
}