This commit is contained in:
KirillFilippow 2023-12-22 13:40:17 +04:00
parent 689ec4a5ce
commit 3e6e60a533
17 changed files with 370 additions and 101 deletions

View File

@ -7,8 +7,7 @@ using static ProjectContainerShip.Direction;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ProjectContainerShip.MovementStrategy
{
/// <summary>
{/// <summary>
/// Класс-стратегия перемещения объекта
/// </summary>
public abstract class AbstractStrategy

View File

@ -4,7 +4,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectContainerShip.DrawningObjects;
using ProjectContainerShip.Generics;
using ProjectContainerShip.MovementStrategy;
namespace ProjectContainerShip.Generics
@ -18,6 +17,10 @@ namespace ProjectContainerShip.Generics
where T : DrawningShip
where U : IMoveableObject
{
/// <summary>
/// Получение объектов коллекции
/// </summary>
public IEnumerable<T?> GetShip => _collection.GetShip();
/// <summary>
/// Ширина окна прорисовки
/// </summary>
@ -57,14 +60,14 @@ namespace ProjectContainerShip.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(ContainerGenericCollection<T, U> collect, T?
public static int? operator +(ContainerGenericCollection<T, U> collect, T?
obj)
{
if (obj == null)
{
return false;
return -1;
}
return collect?._collection.Insert(obj) ?? false;
return collect?._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
@ -72,14 +75,15 @@ namespace ProjectContainerShip.Generics
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(ContainerGenericCollection<T, U> collect, int pos)
public static bool operator -(ContainerGenericCollection<T, U> collect, int
pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
return collect._collection.Remove(pos);
}
return obj;
return false;
}
/// <summary>
/// Получение объекта IMoveableObject

View File

@ -32,6 +32,18 @@ namespace ProjectContainerShip
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Разделитель для записи ключа и значения элемента словаря
/// </summary>
private static readonly char _separatorForKeyValue = '|';
/// <summary>
/// Разделитель для записей коллекции данных в файл
/// </summary>
private readonly char _separatorRecords = ';';
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly char _separatorForObject = ':';
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
@ -51,8 +63,8 @@ namespace ProjectContainerShip
{
if (!_shipStorages.ContainsKey(name))
{
ContainerGenericCollection<DrawningShip, DrawningObjectShip> newSet = new ContainerGenericCollection<DrawningShip, DrawningObjectShip>(_pictureWidth, _pictureHeight);
_shipStorages.Add(name, newSet);
var shipCollection = new ContainerGenericCollection<DrawningShip, DrawningObjectShip>(_pictureWidth, _pictureHeight);
_shipStorages.Add(name, shipCollection);
}
}
/// <summary>
@ -82,6 +94,95 @@ namespace ProjectContainerShip
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,
ContainerGenericCollection<DrawningShip, DrawningObjectShip>> record in _shipStorages)
{
StringBuilder records = new();
foreach (DrawningShip? elem in record.Value.GetShip)
{
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
}
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
}
if (data.Length == 0)
{
return false;
}
using (StreamWriter writer = new StreamWriter(filename))
{
writer.WriteLine("shipStorages");
writer.Write(data.ToString());
return true;
}
}
/// <summary>
/// Загрузка информации в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
using (StreamReader reader = new StreamReader(filename))
{
string cheker = reader.ReadLine();
if (cheker == null)
{
return false;
}
if (!cheker.StartsWith("shipStorages"))
{
return false;
}
_shipStorages.Clear();
string strs;
bool firstinit = true;
while ((strs = reader.ReadLine()) != null)
{
if (strs == null && firstinit)
{
return false;
}
if (strs == null)
{
return false;
}
firstinit = false;
string name = strs.Split(_separatorForKeyValue)[0];
ContainerGenericCollection<DrawningShip, DrawningObjectShip> collection = new(_pictureWidth, _pictureHeight);
foreach (string data in strs.Split(_separatorForKeyValue)[1].Split(_separatorRecords))
{
DrawningShip? ship =
data?.CreateDrawningShip(_separatorForObject, _pictureWidth, _pictureHeight);
if (ship != null)
{
int? result = collection + ship;
if (result == null || result.Value == -1)
{
return false;
}
}
}
_shipStorages.Add(name, collection);
}
return true;
}
}
}
}

View File

@ -23,4 +23,8 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
</Project>

View File

@ -32,5 +32,19 @@ namespace ProjectContainerShip.MovementStrategy
public int GetStep => (int)(_drawningShip?.EntityShip?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) => _drawningShip?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) => _drawningShip?.MoveTransport(direction);
public void SetPosition(int x, int y)
{
if (_drawningShip != null)
{
_drawningShip.SetPosition(x, y);
}
}
public void Draw(Graphics g)
{
if (_drawningShip != null)
{
_drawningShip.DrawTransport(g);
}
}
}
}

View File

@ -56,14 +56,11 @@ namespace ProjectContainerShip.DrawningObjects
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawningShip(int speed, double weight, Color bodyColor, int width, int height)
{
if (width > _shipWidth && height > _shipHeight)
{
_pictureWidth = width;
_pictureHeight = height;
EntityShip = new EntityShip(speed, weight, bodyColor);
}
}
/// <summary>
/// Конструктор
/// </summary>
@ -97,7 +94,6 @@ namespace ProjectContainerShip.DrawningObjects
else _startPosX = 0;
if ((y > 0) && (y < _pictureHeight))
_startPosY = y;
else _startPosY = 0;
_startPosX = x;
_startPosY = y;
@ -118,7 +114,6 @@ namespace ProjectContainerShip.DrawningObjects
/// Высота объекта
/// </summary>
public int GetHeight => _shipHeight;
public object GetObjectPosition { get; internal set; }
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>

View File

@ -21,7 +21,6 @@ namespace ProjectContainerShip.Entities
/// Признак (опция) наличия дополнительных контейнеров
/// </summary>
public bool Container { get; private set; }
/// <summary>
/// Инициализация полей объекта-класса контейнеровоза
/// </summary>
@ -29,8 +28,8 @@ namespace ProjectContainerShip.Entities
/// <param name="weight">Вес </param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="crane">Признак наличия труб</param>
/// <param name="container">Признак наличия топлива</param>
/// <param name="crane">Признак наличия крана</param>
/// <param name="container">Признак наличия контейнеров</param>
public EntityContainerShip(int speed, double weight, Color bodyColor, Color additionalColor, bool crane, bool container) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectContainerShip.Entities;
namespace ProjectContainerShip.DrawningObjects
{
/// <summary>
/// Расширение для класса EntityShip
/// </summary>
public static class ExtentionDrawningContainer
{
/// <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);
}
else if (strs.Length == 6)
{
return new DrawningContainerShip(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 EntityContainerShip dopShip)
{
return str;
}
return $"{str}{separatorForObject}{dopShip.AdditionalColor.Name}{separatorForObject}{dopShip.Crane}{separatorForObject}{dopShip.Container}";
}
}
}

View File

@ -34,13 +34,20 @@
buttonRemoveEx = new Button();
buttonRefreshCollection = new Button();
groupBox1 = new GroupBox();
menuStrip = new MenuStrip();
fileToolStripMenuItem = new ToolStripMenuItem();
SaveToolStripMenuItem = new ToolStripMenuItem();
LoadToolStripMenuItem = new ToolStripMenuItem();
groupBox2 = new GroupBox();
textBoxStorageName = new TextBox();
buttonDelObject = new Button();
listBoxStorages = new ListBox();
buttonAddObject = new Button();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
groupBox1.SuspendLayout();
menuStrip.SuspendLayout();
groupBox2.SuspendLayout();
SuspendLayout();
//
@ -55,14 +62,14 @@
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(21, 326);
maskedTextBoxNumber.Location = new Point(19, 404);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(95, 27);
maskedTextBoxNumber.TabIndex = 1;
//
// buttonAddEx
//
buttonAddEx.Location = new Point(21, 282);
buttonAddEx.Location = new Point(19, 371);
buttonAddEx.Name = "buttonAddEx";
buttonAddEx.Size = new Size(95, 27);
buttonAddEx.TabIndex = 2;
@ -72,7 +79,7 @@
//
// buttonRemoveEx
//
buttonRemoveEx.Location = new Point(19, 359);
buttonRemoveEx.Location = new Point(19, 437);
buttonRemoveEx.Name = "buttonRemoveEx";
buttonRemoveEx.Size = new Size(95, 27);
buttonRemoveEx.TabIndex = 3;
@ -82,7 +89,7 @@
//
// buttonRefreshCollection
//
buttonRefreshCollection.Location = new Point(21, 405);
buttonRefreshCollection.Location = new Point(19, 470);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(95, 27);
buttonRefreshCollection.TabIndex = 4;
@ -92,6 +99,7 @@
//
// groupBox1
//
groupBox1.Controls.Add(menuStrip);
groupBox1.Controls.Add(groupBox2);
groupBox1.Controls.Add(buttonAddEx);
groupBox1.Controls.Add(buttonRefreshCollection);
@ -99,18 +107,50 @@
groupBox1.Controls.Add(buttonRemoveEx);
groupBox1.Location = new Point(812, 0);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(120, 461);
groupBox1.Size = new Size(120, 503);
groupBox1.TabIndex = 5;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
//
// menuStrip
//
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
menuStrip.Location = new Point(3, 23);
menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(7, 3, 0, 3);
menuStrip.Size = new Size(114, 30);
menuStrip.TabIndex = 8;
menuStrip.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
fileToolStripMenuItem.Name = "fileToolStripMenuItem";
fileToolStripMenuItem.Size = new Size(59, 24);
fileToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
SaveToolStripMenuItem.Size = new Size(224, 26);
SaveToolStripMenuItem.Text = "Сохранение";
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click_1;
//
// LoadToolStripMenuItem
//
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
LoadToolStripMenuItem.Size = new Size(224, 26);
LoadToolStripMenuItem.Text = "Загрузка";
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
//
// groupBox2
//
groupBox2.Controls.Add(textBoxStorageName);
groupBox2.Controls.Add(buttonDelObject);
groupBox2.Controls.Add(listBoxStorages);
groupBox2.Controls.Add(buttonAddObject);
groupBox2.Location = new Point(13, 28);
groupBox2.Location = new Point(6, 151);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(116, 214);
groupBox2.TabIndex = 5;
@ -119,15 +159,14 @@
//
// textBoxStorageName
//
textBoxStorageName.Location = new Point(8, 26);
textBoxStorageName.Location = new Point(13, 26);
textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new Size(95, 27);
textBoxStorageName.TabIndex = 6;
textBoxStorageName.TextChanged += textBoxStorageName_TextChanged;
//
// buttonDelObject
//
buttonDelObject.Location = new Point(8, 162);
buttonDelObject.Location = new Point(13, 162);
buttonDelObject.Name = "buttonDelObject";
buttonDelObject.Size = new Size(95, 27);
buttonDelObject.TabIndex = 8;
@ -139,7 +178,7 @@
//
listBoxStorages.FormattingEnabled = true;
listBoxStorages.ItemHeight = 20;
listBoxStorages.Location = new Point(8, 92);
listBoxStorages.Location = new Point(13, 92);
listBoxStorages.Name = "listBoxStorages";
listBoxStorages.Size = new Size(95, 64);
listBoxStorages.TabIndex = 6;
@ -147,7 +186,7 @@
//
// buttonAddObject
//
buttonAddObject.Location = new Point(8, 59);
buttonAddObject.Location = new Point(13, 59);
buttonAddObject.Name = "buttonAddObject";
buttonAddObject.Size = new Size(95, 27);
buttonAddObject.TabIndex = 7;
@ -155,6 +194,17 @@
buttonAddObject.UseVisualStyleBackColor = true;
buttonAddObject.Click += ButtonAddObject_Click;
//
// saveFileDialog
//
saveFileDialog.Filter = "txt file | *.txt";
saveFileDialog.Title = "Выберите текстовый файл";
//
// openFileDialog
//
openFileDialog.FileName = "openFileDialog1";
openFileDialog.Filter = "txt file | *.txt";
openFileDialog.Title = "Сохранить текстовый файл";
//
// FormContainerCollection
//
ClientSize = new Size(932, 503);
@ -164,6 +214,8 @@
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
ResumeLayout(false);
@ -182,5 +234,11 @@
private Button buttonDelObject;
private ListBox listBoxStorages;
private Button buttonAddObject;
private MenuStrip menuStrip;
private ToolStripMenuItem fileToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
}
}

View File

@ -108,17 +108,15 @@ namespace ProjectContainerShip
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
var form = new FormContainerConfig();
form.AddEvent(deleg =>
form.AddEvent(ship =>
{
bool SelectedShip = (obj + deleg);
if (SelectedShip)
if (listBoxStorages.SelectedIndex != -1)
{
var obj = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty];
if (obj != null)
{
if (obj + ship != 1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowContainer();
@ -127,6 +125,8 @@ namespace ProjectContainerShip
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
});
form.Show();
}
@ -182,8 +182,59 @@ namespace ProjectContainerShip
}
pictureBoxCollection.Image = obj.ShowContainer();
}
private void textBoxStorageName_TextChanged(object sender, EventArgs e)
/// <summary>
/// Обработка нажатия "Сохранение"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveToolStripMenuItem_Click_1(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();
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowContainer();
}
else
{
MessageBox.Show("Не загрузилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

View File

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

View File

@ -89,7 +89,6 @@
labelModifiedObject.TabIndex = 8;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.Click += labelModifiedObject_Click;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
//
// labelSimpleObject
@ -212,7 +211,6 @@
checkBoxContainer.TabIndex = 5;
checkBoxContainer.Text = "Признак наличия крана";
checkBoxContainer.UseVisualStyleBackColor = true;
checkBoxContainer.CheckedChanged += checkBoxBodyKit_CheckedChanged;
//
// checkBoxCrane
//
@ -224,7 +222,6 @@
checkBoxCrane.TabIndex = 4;
checkBoxCrane.Text = "Признак наличия котнейнеров";
checkBoxCrane.UseVisualStyleBackColor = true;
checkBoxCrane.CheckedChanged += checkBoxCrane_CheckedChanged;
//
// numericUpDownWeight
//
@ -236,7 +233,6 @@
numericUpDownWeight.Size = new Size(83, 27);
numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownWeight.ValueChanged += numericUpDownWeight_ValueChanged;
//
// numericUpDownSpeed
//
@ -248,7 +244,6 @@
numericUpDownSpeed.Size = new Size(83, 27);
numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownSpeed.ValueChanged += numericUpDownSpeed_ValueChanged;
//
// label2
//

View File

@ -32,6 +32,7 @@ namespace ProjectContainerShip
panelWhite.MouseDown += panelColor_MouseDown;
panelYellow.MouseDown += panelColor_MouseDown;
panelBlue.MouseDown += panelColor_MouseDown;
// TODO buttonCancel.Click with lambda
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
@ -123,7 +124,6 @@ namespace ProjectContainerShip
if (e.Data.GetDataPresent(typeof(Color)))
{
_ship.EntityShip.BodyColor = (Color)e.Data.GetData(typeof(Color));
}
DrawShip();
}
@ -136,7 +136,6 @@ namespace ProjectContainerShip
}
else
labelDopColor.AllowDrop = false;
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
@ -167,25 +166,5 @@ namespace ProjectContainerShip
EventAddShip?.Invoke(_ship);
Close();
}
private void checkBoxBodyKit_CheckedChanged(object sender, EventArgs e)
{
}
private void labelModifiedObject_Click(object sender, EventArgs e)
{
}
private void numericUpDownSpeed_ValueChanged(object sender, EventArgs e)
{
}
private void numericUpDownWeight_ValueChanged(object sender, EventArgs e)
{
}
private void checkBoxCrane_CheckedChanged(object sender, EventArgs e)
{
}
}
}

View File

@ -13,6 +13,7 @@ namespace ProjectContainerShip
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawningShip? _drawingContainerShip;
/// <summary>
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
/// </summary>
@ -162,6 +163,7 @@ namespace ProjectContainerShip
}
private void FormContainerShip_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -14,7 +14,6 @@ namespace ProjectContainerShip
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormContainerCollection());
}
}
}

View File

@ -39,14 +39,18 @@ namespace ProjectContainerShip.Generics
/// </summary>
/// <param name="ship">Добавляемый контейнеровоз</param>
/// <returns></returns>
public bool Insert(T ship)
public int Insert(T ship)
{
if (_places.Count >= _maxCount)
{
return false;
return Insert(ship, 0);
}
_places.Insert(0, ship);
return true;
public int Insert(T ship, int position)
{
if (position < 0 || position >= _maxCount)
return -1;
if (Count >= _maxCount)
return -1;
_places.Insert(position, ship);
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
@ -71,23 +75,15 @@ namespace ProjectContainerShip.Generics
{
get
{
if (position < 0 || position >= _places.Count)
{
if (position < 0 || position > _maxCount)
return null;
}
return _places[position];
}
set
{
if (position < 0 || position >= _places.Count)
{
if (position < 0 || position > _maxCount)
return;
}
if (_places.Count >= _maxCount)
{
return;
}
_places.Insert(position, value);
_places[position] = value;
}
}
/// <summary>