This commit is contained in:
VictoriaPresnyakova 2022-11-20 23:55:50 +04:00
parent ed9281b1a9
commit ac5866738a
5 changed files with 253 additions and 77 deletions

View File

@ -26,12 +26,11 @@ namespace Catamaran
} }
public void SetObject(int x, int y, int width, int height) public void SetObject(int x, int y, int width, int height)
{ {
_catamaran.SetPosition(x, y, width, height); _catamaran?.SetPosition(x, y, width, height);
} }
public void DrawingObject(Graphics g) public void DrawingObject(Graphics g)
{ {
_catamaran?.DrawTransport(g);
_catamaran.DrawTransport(g);
} }
public string GetInfo() => _catamaran?.GetDataForSave(); public string GetInfo() => _catamaran?.GetDataForSave();
public static IDrawingObject Create(string data) => new DrawingObjectBoat(data.CreateDrawingBoat()); public static IDrawingObject Create(string data) => new DrawingObjectBoat(data.CreateDrawingBoat());

View File

@ -29,25 +29,32 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxTools = new System.Windows.Forms.GroupBox(); this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonShowOnMap = new System.Windows.Forms.Button(); this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button(); this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveBoat = new System.Windows.Forms.Button(); this.buttonRemoveBoat = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddBoat = new System.Windows.Forms.Button(); this.buttonAddBoat = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox(); this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxMaps = new System.Windows.Forms.GroupBox(); this.menuStrip = new System.Windows.Forms.MenuStrip();
this.textBoxNewMapName = new System.Windows.Forms.TextBox(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonAddMap = new System.Windows.Forms.Button(); this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonDeleteMap = new System.Windows.Forms.Button(); this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.listBoxMaps = new System.Windows.Forms.ListBox(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBoxTools.SuspendLayout(); this.groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.groupBoxMaps.SuspendLayout(); this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.menuStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBoxTools // groupBoxTools
@ -63,13 +70,75 @@
this.groupBoxTools.Controls.Add(this.buttonUp); this.groupBoxTools.Controls.Add(this.buttonUp);
this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Controls.Add(this.buttonDown);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(653, 0); this.groupBoxTools.Location = new System.Drawing.Point(653, 33);
this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(303, 647); this.groupBoxTools.Size = new System.Drawing.Size(303, 614);
this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools"; this.groupBoxTools.Text = "Tools";
// //
// groupBoxMaps
//
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
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(10, 25);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Size = new System.Drawing.Size(213, 314);
this.groupBoxMaps.TabIndex = 2;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Maps";
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 20;
this.listBoxMaps.Location = new System.Drawing.Point(14, 146);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(191, 84);
this.listBoxMaps.TabIndex = 3;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(14, 233);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(191, 25);
this.buttonDeleteMap.TabIndex = 2;
this.buttonDeleteMap.Text = "DeleteMap";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(14, 112);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(191, 27);
this.buttonAddMap.TabIndex = 1;
this.buttonAddMap.Text = "AddMap";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(14, 45);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(191, 26);
this.textBoxNewMapName.TabIndex = 0;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"SimpleMap",
"SecondMap"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(14, 77);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(191, 28);
this.comboBoxSelectorMap.TabIndex = 0;
//
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(24, 490); this.buttonShowOnMap.Location = new System.Drawing.Point(24, 490);
@ -118,24 +187,12 @@
this.buttonAddBoat.UseVisualStyleBackColor = true; this.buttonAddBoat.UseVisualStyleBackColor = true;
this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click_1); this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click_1);
// //
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"SimpleMap",
"SecondMap"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(14, 77);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(191, 28);
this.comboBoxSelectorMap.TabIndex = 0;
//this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// buttonLeft // buttonLeft
// //
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Catamaran.Properties.Resources.Left; this.buttonLeft.BackgroundImage = global::Catamaran.Properties.Resources.Left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(10, 562); this.buttonLeft.Location = new System.Drawing.Point(10, 529);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4; this.buttonLeft.TabIndex = 4;
@ -147,7 +204,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Catamaran.Properties.Resources.Right; this.buttonRight.BackgroundImage = global::Catamaran.Properties.Resources.Right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(70, 562); this.buttonRight.Location = new System.Drawing.Point(70, 529);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5; this.buttonRight.TabIndex = 5;
@ -159,7 +216,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Catamaran.Properties.Resources.Up; this.buttonUp.BackgroundImage = global::Catamaran.Properties.Resources.Up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(40, 540); this.buttonUp.Location = new System.Drawing.Point(40, 507);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 2; this.buttonUp.TabIndex = 2;
@ -171,7 +228,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Catamaran.Properties.Resources.Down; this.buttonDown.BackgroundImage = global::Catamaran.Properties.Resources.Down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(40, 570); this.buttonDown.Location = new System.Drawing.Point(40, 537);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 3; this.buttonDown.TabIndex = 3;
@ -181,62 +238,50 @@
// pictureBox // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0); this.pictureBox.Location = new System.Drawing.Point(0, 33);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(653, 647); this.pictureBox.Size = new System.Drawing.Size(653, 614);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
// groupBoxMaps // menuStrip
// //
this.groupBoxMaps.Controls.Add(this.listBoxMaps); this.menuStrip.GripMargin = new System.Windows.Forms.Padding(2, 2, 0, 2);
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
this.groupBoxMaps.Controls.Add(this.buttonAddMap); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName); this.fileToolStripMenuItem});
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.groupBoxMaps.Location = new System.Drawing.Point(10, 25); this.menuStrip.Name = "menuStrip";
this.groupBoxMaps.Name = "groupBoxMaps"; this.menuStrip.Size = new System.Drawing.Size(956, 33);
this.groupBoxMaps.Size = new System.Drawing.Size(213, 314); this.menuStrip.TabIndex = 2;
this.groupBoxMaps.TabIndex = 2; this.menuStrip.Text = "menuStrip";
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Maps";
// //
// textBoxNewMapName // fileToolStripMenuItem
// //
this.textBoxNewMapName.Location = new System.Drawing.Point(14, 45); this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.textBoxNewMapName.Name = "textBoxNewMapName"; this.saveToolStripMenuItem,
this.textBoxNewMapName.Size = new System.Drawing.Size(191, 26); this.loadToolStripMenuItem});
this.textBoxNewMapName.TabIndex = 0; this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(54, 29);
this.fileToolStripMenuItem.Text = "File";
// //
// buttonAddMap // saveToolStripMenuItem
// //
this.buttonAddMap.Location = new System.Drawing.Point(14, 112); this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.buttonAddMap.Name = "buttonAddMap"; this.saveToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.buttonAddMap.Size = new System.Drawing.Size(191, 27); this.saveToolStripMenuItem.Text = "Save";
this.buttonAddMap.TabIndex = 1; this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
this.buttonAddMap.Text = "AddMap";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
// //
// buttonDeleteMap // loadToolStripMenuItem
// //
this.buttonDeleteMap.Location = new System.Drawing.Point(14, 233); this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
this.buttonDeleteMap.Name = "buttonDeleteMap"; this.loadToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.buttonDeleteMap.Size = new System.Drawing.Size(191, 25); this.loadToolStripMenuItem.Text = "Load";
this.buttonDeleteMap.TabIndex = 2; this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
this.buttonDeleteMap.Text = "DeleteMap";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
// //
// listBoxMaps // openFileDialog
// //
this.listBoxMaps.FormattingEnabled = true; this.openFileDialog.Filter = "txt file | *.txt";
this.listBoxMaps.ItemHeight = 20;
this.listBoxMaps.Location = new System.Drawing.Point(14, 146);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(191, 84);
this.listBoxMaps.TabIndex = 3;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
// //
// FormMapWithSetBoats // FormMapWithSetBoats
// //
@ -245,14 +290,19 @@
this.ClientSize = new System.Drawing.Size(956, 647); this.ClientSize = new System.Drawing.Size(956, 647);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormMapWithSetBoats"; this.Name = "FormMapWithSetBoats";
this.Text = "FormMapWithSetBoats"; this.Text = "FormMapWithSetBoats";
this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout(); this.groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.groupBoxMaps.ResumeLayout(false); this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout(); this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
@ -275,5 +325,11 @@
private System.Windows.Forms.Button buttonDeleteMap; private System.Windows.Forms.Button buttonDeleteMap;
private System.Windows.Forms.Button buttonAddMap; private System.Windows.Forms.Button buttonAddMap;
private System.Windows.Forms.TextBox textBoxNewMapName; private System.Windows.Forms.TextBox textBoxNewMapName;
private System.Windows.Forms.MenuStrip menuStrip;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem loadToolStripMenuItem;
private System.Windows.Forms.OpenFileDialog openFileDialog;
private System.Windows.Forms.SaveFileDialog saveFileDialog;
} }
} }

View File

@ -234,5 +234,40 @@ namespace Catamaran
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
} }
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
// TODO продумать логику
if(openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Открытие прошло успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadMaps();
}
else
{
MessageBox.Show("Не удалось открыть", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
} }
} }

View File

@ -117,7 +117,13 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>163, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>357, 17</value>
</metadata>
</root> </root>

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -11,7 +12,7 @@ namespace Catamaran
/// <summary> /// <summary>
/// Словарь (хранилище) с картами /// Словарь (хранилище) с картами
/// </summary> /// </summary>
readonly Dictionary<string, MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap>> _mapStorages; readonly Dictionary<string, MapWithSetBoatsGeneric<IDrawingObject, AbstractMap>> _mapStorages;
/// <summary> /// <summary>
/// Возвращение списка названий карт /// Возвращение списка названий карт
@ -30,9 +31,13 @@ namespace Catamaran
/// </summary> /// </summary>
/// <param name="pictureWidth"></param> /// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param> /// <param name="pictureHeight"></param>
///
private readonly char separatorDict = '|';
private readonly char separatorData = ';';
public MapsCollection(int pictureWidth, int pictureHeight) public MapsCollection(int pictureWidth, int pictureHeight)
{ {
_mapStorages = new Dictionary<string, MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap>>(); _mapStorages = new Dictionary<string, MapWithSetBoatsGeneric<IDrawingObject, AbstractMap>>();
_pictureWidth = pictureWidth; _pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; _pictureHeight = pictureHeight;
} }
@ -45,7 +50,7 @@ namespace Catamaran
{ {
if (!_mapStorages.ContainsKey(name)) if (!_mapStorages.ContainsKey(name))
{ {
_mapStorages.Add(name, new MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap>(_pictureWidth, _pictureHeight, map)); _mapStorages.Add(name, new MapWithSetBoatsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
} }
} }
/// <summary> /// <summary>
@ -61,7 +66,7 @@ namespace Catamaran
/// </summary> /// </summary>
/// <param name="ind"></param> /// <param name="ind"></param>
/// <returns></returns> /// <returns></returns>
public MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap> this[string ind] public MapWithSetBoatsGeneric<IDrawingObject, AbstractMap> this[string ind]
{ {
get get
{ {
@ -70,5 +75,80 @@ namespace Catamaran
} }
} }
/// <summary>
/// Метод записи информации в файл
/// </summary>
/// <param name="text">Строка, которую следует записать</param>
/// <param name="stream">Поток для записи</param>
private static void WriteToFile(string text, FileStream stream)
{
byte[] info = new UTF8Encoding(true).GetBytes(text);
stream.Write(info, 0, info.Length);
}
/// <summary>
/// Сохранение информации про лодки м в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns></returns>
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;
}
/// <summary>
/// Загрузка нформации про лодки в гавани из файла
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
using (StreamReader sr = new StreamReader(filename))
{
string str = "";
if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
return false;
}
//очищаем записи
_mapStorages.Clear();
while ((str = sr.ReadLine()) != null)
{
var elem = str.Split(separatorDict);
AbstractMap map = null;
switch (elem[1])
{
case "SimpleMap":
map = new SimpleMap();
break;
case "SecondMap":
map = new SecondMap();
break;
}
_mapStorages.Add(elem[0], new MapWithSetBoatsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, (char)StringSplitOptions.RemoveEmptyEntries));
}
}
return true;
}
} }
} }