почти готово

This commit is contained in:
Казначеева Елизавета 2023-11-21 16:56:40 +04:00
parent 2b46380712
commit 091db401f9
6 changed files with 305 additions and 23 deletions

View File

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Battleship.Entities;
namespace Battleship.DrawningObjects
{
public static class ExtentionDrawningShip
{
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info">Строка с данными для создания объекта</param>
/// <param name="separatorForObject">Разделитель даннных</param>
/// <param name="width">Ширина</param>
/// <param name="height">Высота</param>
/// <returns>Объект</returns>
public static DrawningShip? CreateDrawningShip(this string info, char
separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawningShip(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
if (strs.Length == 6)
{
return new DrawningBattleship(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]),
Color.FromName(strs[2]),
Color.FromName(strs[3]),
Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]), width, height);
}
return null;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawningShip">Сохраняемый объект</param>
/// <param name="separatorForObject">Разделитель даннных</param>
/// <returns>Строка с данными по объекту</returns>
public static string GetDataForSave(this DrawningShip drawningShip,
char separatorForObject)
{
var ship = drawningShip.EntityShip;
if (ship == null)
{
return string.Empty;
}
var str = $"{ship.Speed}{separatorForObject}{ship.Weight}{separatorForObject}{ship.BodyColor.Name}";
if (ship is not EntityBattleship battleship)
{
return str;
}
return $"{str}{separatorForObject}{battleship.AdditionalColor.Name}" +
$"{separatorForObject}{battleship.Tower}{separatorForObject}{battleship.Section}";
}
}
}

View File

@ -38,9 +38,16 @@
this.buttonRefreshCollection = new System.Windows.Forms.Button(); this.buttonRefreshCollection = new System.Windows.Forms.Button();
this.buttonRemoveShip = new System.Windows.Forms.Button(); this.buttonRemoveShip = new System.Windows.Forms.Button();
this.buttonAddShip = new System.Windows.Forms.Button(); this.buttonAddShip = new System.Windows.Forms.Button();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.сохранениеToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.загрузкаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBoxBattleShip.SuspendLayout(); this.groupBoxBattleShip.SuspendLayout();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -53,6 +60,7 @@
this.groupBoxBattleShip.Controls.Add(this.buttonRefreshCollection); this.groupBoxBattleShip.Controls.Add(this.buttonRefreshCollection);
this.groupBoxBattleShip.Controls.Add(this.buttonRemoveShip); this.groupBoxBattleShip.Controls.Add(this.buttonRemoveShip);
this.groupBoxBattleShip.Controls.Add(this.buttonAddShip); this.groupBoxBattleShip.Controls.Add(this.buttonAddShip);
this.groupBoxBattleShip.Controls.Add(this.menuStrip1);
this.groupBoxBattleShip.Location = new System.Drawing.Point(618, 1); this.groupBoxBattleShip.Location = new System.Drawing.Point(618, 1);
this.groupBoxBattleShip.Name = "groupBoxBattleShip"; this.groupBoxBattleShip.Name = "groupBoxBattleShip";
this.groupBoxBattleShip.Size = new System.Drawing.Size(183, 450); this.groupBoxBattleShip.Size = new System.Drawing.Size(183, 450);
@ -66,16 +74,16 @@
this.groupBox1.Controls.Add(this.listBoxStorages); this.groupBox1.Controls.Add(this.listBoxStorages);
this.groupBox1.Controls.Add(this.buttonAddObject); this.groupBox1.Controls.Add(this.buttonAddObject);
this.groupBox1.Controls.Add(this.buttonDelObject); this.groupBox1.Controls.Add(this.buttonDelObject);
this.groupBox1.Location = new System.Drawing.Point(6, 22); this.groupBox1.Location = new System.Drawing.Point(6, 61);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(171, 253); this.groupBox1.Size = new System.Drawing.Size(174, 223);
this.groupBox1.TabIndex = 1; this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "Набор"; this.groupBox1.Text = "Набор";
// //
// textBoxStorageName // textBoxStorageName
// //
this.textBoxStorageName.Location = new System.Drawing.Point(17, 40); this.textBoxStorageName.Location = new System.Drawing.Point(17, 22);
this.textBoxStorageName.Name = "textBoxStorageName"; this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(147, 23); this.textBoxStorageName.Size = new System.Drawing.Size(147, 23);
this.textBoxStorageName.TabIndex = 4; this.textBoxStorageName.TabIndex = 4;
@ -84,15 +92,15 @@
// //
this.listBoxStorages.FormattingEnabled = true; this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 15; this.listBoxStorages.ItemHeight = 15;
this.listBoxStorages.Location = new System.Drawing.Point(17, 124); this.listBoxStorages.Location = new System.Drawing.Point(18, 95);
this.listBoxStorages.Name = "listBoxStorages"; this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(147, 94); this.listBoxStorages.Size = new System.Drawing.Size(147, 79);
this.listBoxStorages.TabIndex = 3; this.listBoxStorages.TabIndex = 3;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged); this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
// //
// buttonAddObject // buttonAddObject
// //
this.buttonAddObject.Location = new System.Drawing.Point(18, 81); this.buttonAddObject.Location = new System.Drawing.Point(17, 51);
this.buttonAddObject.Name = "buttonAddObject"; this.buttonAddObject.Name = "buttonAddObject";
this.buttonAddObject.Size = new System.Drawing.Size(147, 23); this.buttonAddObject.Size = new System.Drawing.Size(147, 23);
this.buttonAddObject.TabIndex = 2; this.buttonAddObject.TabIndex = 2;
@ -102,7 +110,7 @@
// //
// buttonDelObject // buttonDelObject
// //
this.buttonDelObject.Location = new System.Drawing.Point(17, 224); this.buttonDelObject.Location = new System.Drawing.Point(18, 181);
this.buttonDelObject.Name = "buttonDelObject"; this.buttonDelObject.Name = "buttonDelObject";
this.buttonDelObject.Size = new System.Drawing.Size(147, 23); this.buttonDelObject.Size = new System.Drawing.Size(147, 23);
this.buttonDelObject.TabIndex = 1; this.buttonDelObject.TabIndex = 1;
@ -112,16 +120,16 @@
// //
// maskedTextBoxNumber // maskedTextBoxNumber
// //
this.maskedTextBoxNumber.Location = new System.Drawing.Point(23, 330); this.maskedTextBoxNumber.Location = new System.Drawing.Point(24, 335);
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(147, 23); this.maskedTextBoxNumber.Size = new System.Drawing.Size(147, 23);
this.maskedTextBoxNumber.TabIndex = 3; this.maskedTextBoxNumber.TabIndex = 3;
// //
// buttonRefreshCollection // buttonRefreshCollection
// //
this.buttonRefreshCollection.Location = new System.Drawing.Point(23, 411); this.buttonRefreshCollection.Location = new System.Drawing.Point(23, 406);
this.buttonRefreshCollection.Name = "buttonRefreshCollection"; this.buttonRefreshCollection.Name = "buttonRefreshCollection";
this.buttonRefreshCollection.Size = new System.Drawing.Size(147, 33); this.buttonRefreshCollection.Size = new System.Drawing.Size(147, 31);
this.buttonRefreshCollection.TabIndex = 2; this.buttonRefreshCollection.TabIndex = 2;
this.buttonRefreshCollection.Text = "Обновить коллекцию"; this.buttonRefreshCollection.Text = "Обновить коллекцию";
this.buttonRefreshCollection.UseVisualStyleBackColor = true; this.buttonRefreshCollection.UseVisualStyleBackColor = true;
@ -129,9 +137,9 @@
// //
// buttonRemoveShip // buttonRemoveShip
// //
this.buttonRemoveShip.Location = new System.Drawing.Point(23, 359); this.buttonRemoveShip.Location = new System.Drawing.Point(23, 364);
this.buttonRemoveShip.Name = "buttonRemoveShip"; this.buttonRemoveShip.Name = "buttonRemoveShip";
this.buttonRemoveShip.Size = new System.Drawing.Size(147, 33); this.buttonRemoveShip.Size = new System.Drawing.Size(147, 36);
this.buttonRemoveShip.TabIndex = 1; this.buttonRemoveShip.TabIndex = 1;
this.buttonRemoveShip.Text = "Удалить корабль"; this.buttonRemoveShip.Text = "Удалить корабль";
this.buttonRemoveShip.UseVisualStyleBackColor = true; this.buttonRemoveShip.UseVisualStyleBackColor = true;
@ -139,14 +147,47 @@
// //
// buttonAddShip // buttonAddShip
// //
this.buttonAddShip.Location = new System.Drawing.Point(23, 281); this.buttonAddShip.Location = new System.Drawing.Point(23, 290);
this.buttonAddShip.Name = "buttonAddShip"; this.buttonAddShip.Name = "buttonAddShip";
this.buttonAddShip.Size = new System.Drawing.Size(147, 33); this.buttonAddShip.Size = new System.Drawing.Size(147, 30);
this.buttonAddShip.TabIndex = 0; this.buttonAddShip.TabIndex = 0;
this.buttonAddShip.Text = "Добавить корабль"; this.buttonAddShip.Text = "Добавить корабль";
this.buttonAddShip.UseVisualStyleBackColor = true; this.buttonAddShip.UseVisualStyleBackColor = true;
this.buttonAddShip.Click += new System.EventHandler(this.buttonAddShip_Click); this.buttonAddShip.Click += new System.EventHandler(this.buttonAddShip_Click);
// //
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.файлToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(3, 19);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(177, 24);
this.menuStrip1.TabIndex = 4;
this.menuStrip1.Text = "menuStrip1";
//
// файлToolStripMenuItem
//
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.сохранениеToolStripMenuItem,
this.загрузкаToolStripMenuItem});
this.файлToolStripMenuItem.Name = айлToolStripMenuItem";
this.файлToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
this.файлToolStripMenuItem.Text = "Файл";
//
// сохранениеToolStripMenuItem
//
this.сохранениеToolStripMenuItem.Name = "сохранениеToolStripMenuItem";
this.сохранениеToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.сохранениеToolStripMenuItem.Text = "Сохранение";
this.сохранениеToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// загрузкаToolStripMenuItem
//
this.загрузкаToolStripMenuItem.Name = агрузкаToolStripMenuItem";
this.загрузкаToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.загрузкаToolStripMenuItem.Text = "Загрузка";
this.загрузкаToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
// pictureBoxCollection // pictureBoxCollection
// //
this.pictureBoxCollection.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.pictureBoxCollection.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -158,6 +199,14 @@
this.pictureBoxCollection.TabIndex = 0; this.pictureBoxCollection.TabIndex = 0;
this.pictureBoxCollection.TabStop = false; this.pictureBoxCollection.TabStop = false;
// //
// openFileDialog
//
this.openFileDialog.Filter = "txt file | *.txt";
//
// saveFileDialog
//
this.saveFileDialog.Filter = "txt file | *.txt";
//
// FormShipCollection // FormShipCollection
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -165,12 +214,15 @@
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.pictureBoxCollection); this.Controls.Add(this.pictureBoxCollection);
this.Controls.Add(this.groupBoxBattleShip); this.Controls.Add(this.groupBoxBattleShip);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormShipCollection"; this.Name = "FormShipCollection";
this.Text = "FormShipCollection"; this.Text = "FormShipCollection";
this.groupBoxBattleShip.ResumeLayout(false); this.groupBoxBattleShip.ResumeLayout(false);
this.groupBoxBattleShip.PerformLayout(); this.groupBoxBattleShip.PerformLayout();
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -189,5 +241,11 @@
private ListBox listBoxStorages; private ListBox listBoxStorages;
private Button buttonAddObject; private Button buttonAddObject;
private Button buttonDelObject; private Button buttonDelObject;
private MenuStrip menuStrip1;
private ToolStripMenuItem файлToolStripMenuItem;
private ToolStripMenuItem сохранениеToolStripMenuItem;
private ToolStripMenuItem загрузкаToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
} }
} }

View File

@ -27,6 +27,49 @@ namespace Battleship
InitializeComponent(); InitializeComponent();
_storage = new ShipsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); _storage = new ShipsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
} }
/// <summary>
/// Обработка нажатия "Сохранение"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Обработка нажатия "Загрузка"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if(openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadObjects();
}
else
{
MessageBox.Show("Не загрузилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ReloadObjects() private void ReloadObjects()
{ {
int index = listBoxStorages.SelectedIndex; int index = listBoxStorages.SelectedIndex;

View File

@ -57,4 +57,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="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>272, 17</value>
</metadata>
</root> </root>

View File

@ -17,6 +17,10 @@ namespace Battleship.Generics
private readonly int _placeSizeWidth = 185; private readonly int _placeSizeWidth = 185;
private readonly int _placeSizeHeight = 90; private readonly int _placeSizeHeight = 90;
private readonly SetGeneric<T> _collection; private readonly SetGeneric<T> _collection;
/// <summary>
/// Получение объектов коллекции
/// </summary>
public IEnumerable<T?> GetShips => _collection.GetShips();
public ShipGenericCollection(int picWidth, int picHeight) public ShipGenericCollection(int picWidth, int picHeight)
{ {
int width = picWidth / _placeSizeWidth; int width = picWidth / _placeSizeWidth;

View File

@ -12,13 +12,25 @@ namespace Battleship.Generics
{ {
readonly Dictionary<string, ShipGenericCollection<DrawningShip, readonly Dictionary<string, ShipGenericCollection<DrawningShip,
DrawningObjectShip>> _shipStorages; DrawningObjectShip>> _shipStorages;
public List<string> Keys => _shipStorages.Keys.ToList(); public List<string> Keys => _shipStorages.Keys.ToList();
private readonly int _pictureWidth; private readonly int _pictureWidth;
private readonly int _pictureHeight; private readonly int _pictureHeight;
/// <summary>
/// Разделитель для записи ключа и значения элемента словаря
/// </summary>
private static readonly char _separatorForKeyValue = '|';
/// <summary>
/// Разделитель для записей коллекции данных в файл
/// </summary>
private readonly char _separatorRecords = ';';
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly char _separatorForObject = ':';
public ShipsGenericStorage(int pictureWidth, int pictureHeight) public ShipsGenericStorage(int pictureWidth, int pictureHeight)
{ {
_shipStorages = new Dictionary<string, _shipStorages = new Dictionary<string,
@ -26,31 +38,122 @@ namespace Battleship.Generics
_pictureWidth = pictureWidth; _pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; _pictureHeight = pictureHeight;
} }
public void AddSet(string name) public void AddSet(string name)
{ {
if (_shipStorages.ContainsKey(name)) if (_shipStorages.ContainsKey(name))
return; return;
_shipStorages[name] = new ShipGenericCollection<DrawningShip, DrawningObjectShip>(_pictureWidth,_pictureHeight); _shipStorages[name] = new ShipGenericCollection<DrawningShip, DrawningObjectShip>(_pictureWidth, _pictureHeight);
} }
public void DelSet(string name) public void DelSet(string name)
{ {
if (!_shipStorages.ContainsKey(name)) if (!_shipStorages.ContainsKey(name))
return; return;
_shipStorages.Remove(name); _shipStorages.Remove(name);
} }
public ShipGenericCollection<DrawningShip, DrawningObjectShip>? public ShipGenericCollection<DrawningShip, DrawningObjectShip>?
this[string ind] this[string ind]
{ {
get get
{ {
if(_shipStorages.ContainsKey(ind)) if (_shipStorages.ContainsKey(ind))
return _shipStorages[ind]; return _shipStorages[ind];
return null; return null;
} }
} }
/// <summary>
/// Сохранение информации по автомобилям в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
public bool SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
StringBuilder data = new();
foreach (KeyValuePair<string,
ShipGenericCollection<DrawningShip, DrawningObjectShip>> record in _shipStorages)
{
StringBuilder records = new();
foreach (DrawningShip? elem in record.Value.GetShips)
{
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
}
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
}
if (data.Length == 0)
{
return false;
}
using FileStream fs = new(filename, FileMode.Create);
byte[] info = new
UTF8Encoding(true).GetBytes($"ShipStorage{Environment.NewLine}{data}");
fs.Write(info, 0, info.Length);
return true;
}
/// <summary>
/// Загрузка информации по кораблям в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
{
byte[] b = new byte[fs.Length];
UTF8Encoding temp = new(true);
while (fs.Read(b, 0, b.Length) > 0)
{
bufferTextFromFile += temp.GetString(b);
}
}
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
return false;
}
if (!strs[0].StartsWith("ShipsStorage"))
{
//если нет такой записи, то это не те данные
return false;
}
_shipStorages.Clear();
foreach (string data in strs)
{
string[] record = data.Split(_separatorForKeyValue,
StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{
continue;
}
ShipGenericCollection<DrawningShip, DrawningObjectShip> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords,
StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawningShip? ship =
elem?.CreateDrawningShip(_separatorForObject, _pictureWidth, _pictureHeight);
if (ship != null)
{
if (!(collection + ship))
{
return false;
}
}
}
_shipStorages.Add(record[0], collection);
}
return true;
}
} }
} }