From 0e2ce081300a7a3d88a921f6819b53c9c934fb8e Mon Sep 17 00:00:00 2001
From: Sharosh322 <132645197+Sharosh322@users.noreply.github.com>
Date: Sat, 9 Dec 2023 22:36:48 +0400
Subject: [PATCH] Done
---
.../ProjStormtrooper/AbstractStrategy.cs | 65 +++++++++-
.../ProjStormtrooper/Direction.cs | 12 ++
.../ProjStormtrooper/DrawingObjectPlane.cs | 3 +
.../ProjStormtrooper/DrawingPlane.cs | 107 +++++++++++++---
.../ProjStormtrooper/DrawingStormtrooper.cs | 22 +++-
.../ProjStormtrooper/EntityPlane.cs | 21 ++++
.../ProjStormtrooper/EntityStormtrooper.cs | 6 +
.../ProjStormtrooper/IMoveableObject.cs | 18 +++
.../ProjStormtrooper/MoveToCenter.cs | 3 +
.../ProjStormtrooper/ObjectParameters.cs | 28 +++++
.../PlaneCollection.Designer.cs | 103 ++++++++++++---
.../ProjStormtrooper/PlaneCollection.cs | 113 +++++++++++++++--
.../ProjStormtrooper/PlaneCollection.resx | 2 +-
.../PlanesGenericCollection.cs | 96 +++++++++++---
.../ProjStormtrooper/PlanesGenericStorage.cs | 70 +++++++++++
ProjStormtrooper/ProjStormtrooper/Program.cs | 3 +
.../ProjStormtrooper/SetGeneric.cs | 118 ++++++++++++------
ProjStormtrooper/ProjStormtrooper/Status.cs | 3 +
.../ProjStormtrooper/Stormtrooper.cs | 48 ++++++-
19 files changed, 735 insertions(+), 106 deletions(-)
create mode 100644 ProjStormtrooper/ProjStormtrooper/PlanesGenericStorage.cs
diff --git a/ProjStormtrooper/ProjStormtrooper/AbstractStrategy.cs b/ProjStormtrooper/ProjStormtrooper/AbstractStrategy.cs
index c2cfd00..9bd454d 100644
--- a/ProjStormtrooper/ProjStormtrooper/AbstractStrategy.cs
+++ b/ProjStormtrooper/ProjStormtrooper/AbstractStrategy.cs
@@ -6,14 +6,37 @@ using System.Threading.Tasks;
namespace ProjStormtrooper
{
+ ///
+ /// Класс-стратегия перемещения объекта
+ ///
public abstract class AbstractStrategy
{
+ ///
+ /// Перемещаемый объект
+ ///
private IMoveableObject? _moveableObject;
+ ///
+ /// Статус перемещения
+ ///
private Status _state = Status.NotInit;
+ ///
+ /// Ширина поля
+ ///
protected int FieldWidth { get; private set; }
+ ///
+ /// Высота поля
+ ///
protected int FieldHeight { get; private set; }
+ ///
+ /// Статус перемещения
+ ///
public Status GetStatus() { return _state; }
-
+ ///
+ /// Установка данных
+ ///
+ /// Перемещаемый объект
+ /// Ширина поля
+ /// Высота поля
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
@@ -26,7 +49,9 @@ namespace ProjStormtrooper
FieldWidth = width;
FieldHeight = height;
}
-
+ ///
+ /// Шаг перемещения
+ ///
public void MakeStep()
{
if (_state != Status.InProgress)
@@ -40,12 +65,34 @@ namespace ProjStormtrooper
}
MoveToTarget();
}
-
+ ///
+ /// Перемещение влево
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
protected bool MoveLeft() => MoveTo(Direction.Left);
+ ///
+ /// Перемещение вправо
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
protected bool MoveRight() => MoveTo(Direction.Right);
+ ///
+ /// Перемещение вверх
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
protected bool MoveUp() => MoveTo(Direction.Up);
+ ///
+ /// Перемещение вниз
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
protected bool MoveDown() => MoveTo(Direction.Down);
+ ///
+ /// Параметры объекта
+ ///
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
+ ///
+ /// Шаг объекта
+ ///
+ ///
protected int? GetStep()
{
if (_state != Status.InProgress)
@@ -54,8 +101,20 @@ namespace ProjStormtrooper
}
return _moveableObject?.GetStep;
}
+ ///
+ /// Перемещение к цели
+ ///
protected abstract void MoveToTarget();
+ ///
+ /// Достигнута ли цель
+ ///
+ ///
protected abstract bool IsTargetDestinaion();
+ ///
+ /// Попытка перемещения в требуемом направлении
+ ///
+ /// Направление
+ /// Результат попытки (true - удалось переместиться, false - неудача)
private bool MoveTo(Direction directionType)
{
if (_state != Status.InProgress)
diff --git a/ProjStormtrooper/ProjStormtrooper/Direction.cs b/ProjStormtrooper/ProjStormtrooper/Direction.cs
index 93ba617..3d6be52 100644
--- a/ProjStormtrooper/ProjStormtrooper/Direction.cs
+++ b/ProjStormtrooper/ProjStormtrooper/Direction.cs
@@ -8,9 +8,21 @@ namespace ProjStormtrooper
{
public enum Direction
{
+ ///
+ /// Вверх
+ ///
Up = 1,
+ ///
+ /// Вниз
+ ///
Down = 2,
+ ///
+ /// Влево
+ ///
Left = 3,
+ ///
+ /// Вправо
+ ///
Right = 4
}
}
diff --git a/ProjStormtrooper/ProjStormtrooper/DrawingObjectPlane.cs b/ProjStormtrooper/ProjStormtrooper/DrawingObjectPlane.cs
index 1381404..a9b50cd 100644
--- a/ProjStormtrooper/ProjStormtrooper/DrawingObjectPlane.cs
+++ b/ProjStormtrooper/ProjStormtrooper/DrawingObjectPlane.cs
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
namespace ProjStormtrooper
{
+ ///
+ /// Реализация интерфейса IDrawningObject для работы с объектом DrawningPlane (паттерн Adapter)
+ ///
public class DrawingObjectPlane : IMoveableObject
{
private readonly DrawingPlane? _drawingPlane = null;
diff --git a/ProjStormtrooper/ProjStormtrooper/DrawingPlane.cs b/ProjStormtrooper/ProjStormtrooper/DrawingPlane.cs
index be86612..8d8b0c9 100644
--- a/ProjStormtrooper/ProjStormtrooper/DrawingPlane.cs
+++ b/ProjStormtrooper/ProjStormtrooper/DrawingPlane.cs
@@ -6,20 +6,63 @@ using System.Threading.Tasks;
namespace ProjStormtrooper
{
+ ///
+ /// Класс отвечающий за прорисовку и перемещение объекта-сущности
+ ///
public class DrawingPlane
{
+ ///
+ /// Класс-сущность
+ ///
public EntityPlane? EntityPlane { get; protected set; }
+ ///
+ /// Ширина окна
+ ///
private int _pictureWidth;
+ ///
+ /// Высота окна
+ ///
private int _pictureHeight;
+ ///
+ /// Левая координата начала прорисовки
+ ///
protected int _startPosX;
+ ///
+ /// Верхняя координата начала прорисовки
+ ///
protected int _startPosY;
+ ///
+ /// Ширина прорисовки
+ ///
protected readonly int _planeWidth = 110;
+ ///
+ /// Высота прорисовки
+ ///
protected readonly int _planeHeight = 110;
+ ///
+ /// Координата X объекта
+ ///
public int GetPosX => _startPosX;
+ ///
+ /// Координата Y объекта
+ ///
public int GetPosY => _startPosY;
+ ///
+ /// Ширина объекта
+ ///
public int GetWidth => _planeWidth;
+ ///
+ /// Высота объекта
+ ///
public int GetHeight => _planeHeight;
-
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Ширина картинки
+ /// Высота картинки
public DrawingPlane(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _planeWidth && height < _planeHeight)
@@ -30,7 +73,16 @@ namespace ProjStormtrooper
_pictureHeight = height;
EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
-
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Ширина окна
+ /// Высота окна
+ /// Ширина объекта
+ /// Высота объекта
protected DrawingPlane(int speed, double weight, Color bodyColor,
int width, int height, int planeWidth, int planeHeight)
{
@@ -44,7 +96,11 @@ namespace ProjStormtrooper
_planeHeight = planeHeight;
EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
-
+ ///
+ /// Проверка, что объект может переместится по указанному направлению
+ ///
+ /// Направление
+ /// true - можно переместится по указанному направлению
public bool CanMove(Direction direction)
{
if (EntityPlane == null)
@@ -53,18 +109,22 @@ namespace ProjStormtrooper
}
return direction switch
{
-
+ //вверх
Direction.Up => _startPosY - EntityPlane.Step > 0,
-
+ //вниз
Direction.Down => _startPosY + _planeHeight + EntityPlane.Step < _pictureHeight,
-
+ //влево
Direction.Left => _startPosX - EntityPlane.Step > 0,
-
+ //вправо
Direction.Right => _startPosX + _planeWidth + EntityPlane.Step < _pictureWidth,
_ => false,
};
}
-
+ ///
+ /// Установка позиции
+ ///
+ /// Координата X
+ /// Координата Y
public void SetPosition(int x, int y)
{
if (x < 0)
@@ -87,7 +147,10 @@ namespace ProjStormtrooper
}
_startPosY = y;
}
-
+ ///
+ /// Перемещение объекта
+ ///
+ /// Направление перемещения
public void MoveTransport(Direction direction)
{
if (!CanMove(direction) || EntityPlane == null)
@@ -96,25 +159,28 @@ namespace ProjStormtrooper
}
switch (direction)
{
-
+ // Вверх
case Direction.Up:
_startPosY -= (int)EntityPlane.Step;
break;
-
+ // Вниз
case Direction.Down:
_startPosY += (int)EntityPlane.Step;
break;
-
+ // Влево
case Direction.Left:
_startPosX -= (int)EntityPlane.Step;
break;
-
+ // Вправо
case Direction.Right:
_startPosX += (int)EntityPlane.Step;
break;
}
}
-
+ ///
+ /// Прорисовка объекта
+ ///
+ ///
public virtual void DrawTransport(Graphics g)
{
if (EntityPlane == null)
@@ -125,10 +191,10 @@ namespace ProjStormtrooper
Brush brushBlack = new SolidBrush(Color.Black);
Brush brushBodyColor = new SolidBrush(EntityPlane.BodyColor);
-
+ // Высота фюзеляжа
int bodyHeight = _planeHeight / 9;
-
+ // Рисуем нос
Point[] pointsCockPit = {
new Point(_startPosX, _startPosY + _planeHeight / 2),
@@ -138,7 +204,7 @@ namespace ProjStormtrooper
g.FillPolygon(brushBlack, pointsCockPit);
-
+ // Рисуем крылья
Point[] pointsWings = {
new Point(_startPosX + _planeWidth / 2, _startPosY),
@@ -151,6 +217,7 @@ namespace ProjStormtrooper
g.FillPolygon(brushBodyColor, pointsWings);
g.DrawPolygon(penBlack, pointsWings);
+ // Рисуем хвост
Point[] pointsTail = {
new Point(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 - _planeHeight / 3),
@@ -161,12 +228,16 @@ namespace ProjStormtrooper
};
g.FillPolygon(brushBodyColor, pointsTail);
-
g.DrawPolygon(penBlack, pointsTail);
+ // Рисуем фюзеляж
+
g.FillRectangle(brushBodyColor, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight);
g.DrawRectangle(penBlack, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight);
}
+ ///
+ /// Получение объекта IMoveableObject из объекта DrawingPlane
+ ///
public IMoveableObject GetMoveableObject => new DrawingObjectPlane(this);
}
}
diff --git a/ProjStormtrooper/ProjStormtrooper/DrawingStormtrooper.cs b/ProjStormtrooper/ProjStormtrooper/DrawingStormtrooper.cs
index a26f354..30263bb 100644
--- a/ProjStormtrooper/ProjStormtrooper/DrawingStormtrooper.cs
+++ b/ProjStormtrooper/ProjStormtrooper/DrawingStormtrooper.cs
@@ -8,6 +8,17 @@ namespace ProjStormtrooper
{
public class DrawingStormtrooper : DrawingPlane
{
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия ракет
+ /// Признак наличия бомб
+ /// Ширина картинки
+ /// Высота картинки
public DrawingStormtrooper(int speed, double weight, Color bodyColor,
Color additionalColor, bool rockets, bool bombs,
int width, int height) : base(speed, weight, bodyColor, width, height, 140, 90)
@@ -17,7 +28,10 @@ namespace ProjStormtrooper
EntityPlane = new EntityStormtrooper(speed, weight, bodyColor, additionalColor, rockets, bombs);
}
}
-
+ ///
+ /// Прорисовка объекта
+ ///
+ ///
public override void DrawTransport(Graphics g)
{
if (EntityPlane is not EntityStormtrooper stormtrooper)
@@ -28,10 +42,10 @@ namespace ProjStormtrooper
Brush brushBlack = new SolidBrush(Color.Black);
Brush brushAdditionalColor = new SolidBrush(stormtrooper.AdditionalColor);
-
+ // Высота фюзеляжа
int bodyHeight = _planeHeight / 9;
-
+ // Рисуем бомбы
if (stormtrooper.Bombs)
{
Point[] pointsBombTail = {
@@ -81,7 +95,7 @@ namespace ProjStormtrooper
bodyHeight);
}
-
+ // Рисуем ракеты
if (stormtrooper.Rockets)
{
int rocketWidth = bodyHeight * 4;
diff --git a/ProjStormtrooper/ProjStormtrooper/EntityPlane.cs b/ProjStormtrooper/ProjStormtrooper/EntityPlane.cs
index b459567..b1175e8 100644
--- a/ProjStormtrooper/ProjStormtrooper/EntityPlane.cs
+++ b/ProjStormtrooper/ProjStormtrooper/EntityPlane.cs
@@ -8,12 +8,33 @@ using static System.Reflection.Metadata.BlobBuilder;
namespace ProjStormtrooper
{
+ ///
+ /// Класс-сущность "Самолет"
+ ///
public class EntityPlane
{
+ ///
+ /// Скорость
+ ///
public int Speed { get; private set; }
+ ///
+ /// Вес
+ ///
public double Weight { get; private set; }
+ ///
+ /// Основной цвет
+ ///
public Color BodyColor { get; private set; }
+ ///
+ /// Шаг перемещения
+ ///
public double Step => (double)Speed * 250 / Weight;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
public EntityPlane(int speed, double weight, Color bodyColor)
{
Speed = speed;
diff --git a/ProjStormtrooper/ProjStormtrooper/EntityStormtrooper.cs b/ProjStormtrooper/ProjStormtrooper/EntityStormtrooper.cs
index 8a1edd3..02e3e59 100644
--- a/ProjStormtrooper/ProjStormtrooper/EntityStormtrooper.cs
+++ b/ProjStormtrooper/ProjStormtrooper/EntityStormtrooper.cs
@@ -9,7 +9,13 @@ namespace ProjStormtrooper
public class EntityStormtrooper : EntityPlane
{
public Color AdditionalColor { get; private set; }
+ ///
+ /// Признак (опция) наличия ракет
+ ///
public bool Rockets { get; private set; }
+ ///
+ /// Признак (опция) наличия бомб
+ ///
public bool Bombs { get; private set; }
public EntityStormtrooper(int speed, double weight, Color bodyColor,
Color additionalColor, bool rockets, bool bombs) : base(speed, weight, bodyColor)
diff --git a/ProjStormtrooper/ProjStormtrooper/IMoveableObject.cs b/ProjStormtrooper/ProjStormtrooper/IMoveableObject.cs
index f7f162f..398c118 100644
--- a/ProjStormtrooper/ProjStormtrooper/IMoveableObject.cs
+++ b/ProjStormtrooper/ProjStormtrooper/IMoveableObject.cs
@@ -6,11 +6,29 @@ using System.Threading.Tasks;
namespace ProjStormtrooper
{
+ ///
+ /// Интерфейс для работы с перемещаемым объектом
+ ///
public interface IMoveableObject
{
+ ///
+ /// Получение координаты X объекта
+ ///
ObjectParameters? GetObjectPosition { get; }
+ ///
+ /// Шаг объекта
+ ///
int GetStep { get; }
+ ///
+ /// Проверка, можно ли переместиться по нужному направлению
+ ///
+ ///
+ ///
bool CheckCanMove(Direction direction);
+ ///
+ /// Изменение направления перемещения объекта
+ ///
+ /// Направление
void MoveObject(Direction direction);
}
}
diff --git a/ProjStormtrooper/ProjStormtrooper/MoveToCenter.cs b/ProjStormtrooper/ProjStormtrooper/MoveToCenter.cs
index f226105..2ffc394 100644
--- a/ProjStormtrooper/ProjStormtrooper/MoveToCenter.cs
+++ b/ProjStormtrooper/ProjStormtrooper/MoveToCenter.cs
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
namespace ProjStormtrooper
{
+ ///
+ /// Стратегия перемещения объекта в центр экрана
+ ///
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
diff --git a/ProjStormtrooper/ProjStormtrooper/ObjectParameters.cs b/ProjStormtrooper/ProjStormtrooper/ObjectParameters.cs
index 99a7340..61b8314 100644
--- a/ProjStormtrooper/ProjStormtrooper/ObjectParameters.cs
+++ b/ProjStormtrooper/ProjStormtrooper/ObjectParameters.cs
@@ -6,18 +6,46 @@ using System.Threading.Tasks;
namespace ProjStormtrooper
{
+ ///
+ /// Параметры-координаты объекта
+ ///
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
+ ///
+ /// Левая граница
+ ///
public int LeftBorder => _x;
+ ///
+ /// Верхняя граница
+ ///
public int TopBorder => _y;
+ ///
+ /// Правая граница
+ ///
public int RightBorder => _x + _width;
+ ///
+ /// Нижняя граница
+ ///
public int DownBorder => _y + _height;
+ ///
+ /// Середина объекта
+ ///
public int ObjectMiddleHorizontal => _x + _width / 2;
+ ///
+ /// Середина объекта
+ ///
public int ObjectMiddleVertical => _y + _height / 2;
+ ///
+ /// Конструктор
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина
+ /// Высота
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
diff --git a/ProjStormtrooper/ProjStormtrooper/PlaneCollection.Designer.cs b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.Designer.cs
index 2273a56..1ba4064 100644
--- a/ProjStormtrooper/ProjStormtrooper/PlaneCollection.Designer.cs
+++ b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.Designer.cs
@@ -29,44 +29,106 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
+ groupBoxStorages = new GroupBox();
+ buttonRemoveStorage = new Button();
+ buttonAddStorage = new Button();
+ textBoxStorageName = new TextBox();
+ listBoxStorages = new ListBox();
maskedTextBoxNumber = new MaskedTextBox();
buttonRefreshCollection = new Button();
buttonRemovePlane = new Button();
buttonAddPlane = new Button();
pictureBoxCollection = new PictureBox();
groupBoxTools.SuspendLayout();
+ groupBoxStorages.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
+ groupBoxTools.Controls.Add(groupBoxStorages);
groupBoxTools.Controls.Add(maskedTextBoxNumber);
groupBoxTools.Controls.Add(buttonRefreshCollection);
groupBoxTools.Controls.Add(buttonRemovePlane);
groupBoxTools.Controls.Add(buttonAddPlane);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(787, 0);
+ groupBoxTools.Location = new Point(689, 0);
+ groupBoxTools.Margin = new Padding(3, 2, 3, 2);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(230, 538);
+ groupBoxTools.Padding = new Padding(3, 2, 3, 2);
+ groupBoxTools.Size = new Size(201, 404);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // groupBoxStorages
+ //
+ groupBoxStorages.Controls.Add(buttonRemoveStorage);
+ groupBoxStorages.Controls.Add(buttonAddStorage);
+ groupBoxStorages.Controls.Add(textBoxStorageName);
+ groupBoxStorages.Controls.Add(listBoxStorages);
+ groupBoxStorages.Location = new Point(6, 21);
+ groupBoxStorages.Name = "groupBoxStorages";
+ groupBoxStorages.Size = new Size(189, 204);
+ groupBoxStorages.TabIndex = 6;
+ groupBoxStorages.TabStop = false;
+ groupBoxStorages.Text = "Наборы";
+ //
+ // buttonRemoveStorage
+ //
+ buttonRemoveStorage.Location = new Point(6, 175);
+ buttonRemoveStorage.Name = "buttonRemoveStorage";
+ buttonRemoveStorage.Size = new Size(177, 23);
+ buttonRemoveStorage.TabIndex = 8;
+ buttonRemoveStorage.Text = "Удалить набор";
+ buttonRemoveStorage.UseVisualStyleBackColor = true;
+ buttonRemoveStorage.Click += buttonRemoveStorage_Click;
+ //
+ // buttonAddStorage
+ //
+ buttonAddStorage.Location = new Point(6, 51);
+ buttonAddStorage.Name = "buttonAddStorage";
+ buttonAddStorage.Size = new Size(177, 23);
+ buttonAddStorage.TabIndex = 7;
+ buttonAddStorage.Text = "Добавить набор";
+ buttonAddStorage.UseVisualStyleBackColor = true;
+ buttonAddStorage.Click += buttonAddStorage_Click;
+ //
+ // textBoxStorageName
+ //
+ textBoxStorageName.Location = new Point(6, 22);
+ textBoxStorageName.Name = "textBoxStorageName";
+ textBoxStorageName.Size = new Size(177, 23);
+ textBoxStorageName.TabIndex = 6;
+ textBoxStorageName.TextChanged += textBoxStorageName_TextChanged;
+ //
+ // listBoxStorages
+ //
+ listBoxStorages.FormattingEnabled = true;
+ listBoxStorages.ItemHeight = 15;
+ listBoxStorages.Location = new Point(6, 79);
+ listBoxStorages.Name = "listBoxStorages";
+ listBoxStorages.Size = new Size(177, 94);
+ listBoxStorages.TabIndex = 5;
+ listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
+ //
// maskedTextBoxNumber
//
- maskedTextBoxNumber.Location = new Point(6, 87);
+ maskedTextBoxNumber.Location = new Point(5, 318);
+ maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
maskedTextBoxNumber.Mask = "00";
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
- maskedTextBoxNumber.Size = new Size(218, 27);
+ maskedTextBoxNumber.Size = new Size(191, 23);
maskedTextBoxNumber.TabIndex = 4;
maskedTextBoxNumber.TextAlign = HorizontalAlignment.Center;
maskedTextBoxNumber.ValidatingType = typeof(int);
//
// buttonRefreshCollection
//
- buttonRefreshCollection.Location = new Point(6, 180);
+ buttonRefreshCollection.Location = new Point(5, 371);
+ buttonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
buttonRefreshCollection.Name = "buttonRefreshCollection";
- buttonRefreshCollection.Size = new Size(218, 29);
+ buttonRefreshCollection.Size = new Size(191, 22);
buttonRefreshCollection.TabIndex = 3;
buttonRefreshCollection.Text = "Обновить коллекцию";
buttonRefreshCollection.UseVisualStyleBackColor = true;
@@ -74,9 +136,10 @@
//
// buttonRemovePlane
//
- buttonRemovePlane.Location = new Point(6, 120);
+ buttonRemovePlane.Location = new Point(5, 345);
+ buttonRemovePlane.Margin = new Padding(3, 2, 3, 2);
buttonRemovePlane.Name = "buttonRemovePlane";
- buttonRemovePlane.Size = new Size(218, 29);
+ buttonRemovePlane.Size = new Size(191, 22);
buttonRemovePlane.TabIndex = 2;
buttonRemovePlane.Text = "Удалить самолет";
buttonRemovePlane.UseVisualStyleBackColor = true;
@@ -84,9 +147,10 @@
//
// buttonAddPlane
//
- buttonAddPlane.Location = new Point(6, 26);
+ buttonAddPlane.Location = new Point(4, 292);
+ buttonAddPlane.Margin = new Padding(3, 2, 3, 2);
buttonAddPlane.Name = "buttonAddPlane";
- buttonAddPlane.Size = new Size(218, 29);
+ buttonAddPlane.Size = new Size(191, 22);
buttonAddPlane.TabIndex = 0;
buttonAddPlane.Text = "Добавить самолет";
buttonAddPlane.UseVisualStyleBackColor = true;
@@ -96,22 +160,26 @@
//
pictureBoxCollection.Dock = DockStyle.Fill;
pictureBoxCollection.Location = new Point(0, 0);
+ pictureBoxCollection.Margin = new Padding(3, 2, 3, 2);
pictureBoxCollection.Name = "pictureBoxCollection";
- pictureBoxCollection.Size = new Size(787, 538);
+ pictureBoxCollection.Size = new Size(689, 404);
pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false;
//
- // FormPlaneCollection
+ // PlaneCollection
//
- AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1017, 538);
+ ClientSize = new Size(890, 404);
Controls.Add(pictureBoxCollection);
Controls.Add(groupBoxTools);
- Name = "FormPlaneCollection";
+ Margin = new Padding(3, 2, 3, 2);
+ Name = "PlaneCollection";
Text = "Набор самолетов";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
+ groupBoxStorages.ResumeLayout(false);
+ groupBoxStorages.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
}
@@ -124,5 +192,10 @@
private Button buttonAddPlane;
private MaskedTextBox maskedTextBoxNumber;
private PictureBox pictureBoxCollection;
+ private GroupBox groupBoxStorages;
+ private TextBox textBoxStorageName;
+ private ListBox listBoxStorages;
+ private Button buttonAddStorage;
+ private Button buttonRemoveStorage;
}
}
\ No newline at end of file
diff --git a/ProjStormtrooper/ProjStormtrooper/PlaneCollection.cs b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.cs
index bc204c6..d59905f 100644
--- a/ProjStormtrooper/ProjStormtrooper/PlaneCollection.cs
+++ b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.cs
@@ -10,23 +10,65 @@ using System.Windows.Forms;
namespace ProjStormtrooper
{
+ ///
+ /// Форма для работы с набором объектов класса DrawningPlane
+ ///
public partial class PlaneCollection : Form
{
- private readonly PlanesGenericCollection _planes;
+ ///
+ /// Набор объектов
+ ///
+ private readonly PlanesGenericStorage _storage;
+ ///
+ /// Конструктор
+ ///
public PlaneCollection()
{
InitializeComponent();
- _planes = new PlanesGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ _storage = new PlanesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
+
+ private void ReloadObjects()
+ {
+ int index = listBoxStorages.SelectedIndex;
+ listBoxStorages.Items.Clear();
+ for (int i = 0; i < _storage.Keys.Count; i++)
+ {
+ listBoxStorages.Items.Add(_storage.Keys[i]);
+ }
+ if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
+ {
+ listBoxStorages.SelectedIndex = 0;
+ }
+ else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
+ {
+ listBoxStorages.SelectedIndex = index;
+ }
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ ///
+ ///
+ ///
private void buttonAddPlane_Click(object sender, EventArgs e)
{
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
Stormtrooper form = new();
if (form.ShowDialog() == DialogResult.OK)
{
- if (_planes + form.SelectedPlane > -1)
+ if (obj + form.SelectedPlane > -1)
{
MessageBox.Show("Объект добавлен");
- pictureBoxCollection.Image = _planes.ShowPlanes();
+ pictureBoxCollection.Image = obj.ShowPlanes();
}
else
{
@@ -34,26 +76,83 @@ namespace ProjStormtrooper
}
}
}
+ ///
+ /// Удаление объекта из набора
+ ///
+ ///
+ ///
private void buttonRemovePlane_Click(object sender, EventArgs e)
{
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
- if (_planes - pos != null)
+ if (obj - pos != null)
{
MessageBox.Show("Объект удален");
- pictureBoxCollection.Image = _planes.ShowPlanes();
+ pictureBoxCollection.Image = obj.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
+ ///
+ /// Обновление рисунка по набору
+ ///
+ ///
+ ///
private void buttonRefreshCollection_Click(object sender, EventArgs e)
{
- pictureBoxCollection.Image = _planes.ShowPlanes();
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
+ pictureBoxCollection.Image = obj.ShowPlanes();
+ }
+
+ private void buttonAddStorage_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxStorageName.Text))
+ {
+ MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _storage.AddSet(textBoxStorageName.Text);
+ ReloadObjects();
+ }
+
+ private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
+ }
+
+ private void buttonRemoveStorage_Click(object sender, EventArgs e)
+ {
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
+ ReloadObjects();
+ }
}
}
}
diff --git a/ProjStormtrooper/ProjStormtrooper/PlaneCollection.resx b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.resx
index a395bff..af32865 100644
--- a/ProjStormtrooper/ProjStormtrooper/PlaneCollection.resx
+++ b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.resx
@@ -18,7 +18,7 @@
System.Resources.ResXResourceReader, System.Windows.Forms, ...
System.Resources.ResXResourceWriter, System.Windows.Forms, ...
this is my long stringthis is a comment
- Blue
+ Blue
[base64 mime encoded serialized .NET Framework object]
diff --git a/ProjStormtrooper/ProjStormtrooper/PlanesGenericCollection.cs b/ProjStormtrooper/ProjStormtrooper/PlanesGenericCollection.cs
index 11036c0..db20764 100644
--- a/ProjStormtrooper/ProjStormtrooper/PlanesGenericCollection.cs
+++ b/ProjStormtrooper/ProjStormtrooper/PlanesGenericCollection.cs
@@ -6,15 +6,40 @@ using System.Threading.Tasks;
namespace ProjStormtrooper
{
+ ///
+ /// Параметризованный класс для набора объектов DrawningPlane
+ ///
+ ///
+ ///
internal class PlanesGenericCollection
where T : DrawingPlane
where U : IMoveableObject
{
+ ///
+ /// Ширина окна прорисовки
+ ///
private readonly int _pictureWidth;
+ ///
+ /// Высота окна прорисовки
+ ///
private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
private readonly int _placeSizeWidth = 160;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
private readonly int _placeSizeHeight = 120;
+ ///
+ /// Набор объектов
+ ///
private readonly SetGeneric _collection;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
public PlanesGenericCollection(int picWidth, int picHeight)
{
int horizontalObjectsCount = picWidth / _placeSizeWidth;
@@ -23,7 +48,12 @@ namespace ProjStormtrooper
_pictureHeight = picHeight;
_collection = new SetGeneric(horizontalObjectsCount * verticalObjectsCount);
}
-
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
public static int operator +(PlanesGenericCollection collect, T? obj)
{
if (obj == null)
@@ -32,22 +62,34 @@ namespace ProjStormtrooper
}
return collect?._collection.Insert(obj) ?? -1;
}
-
- public static bool operator -(PlanesGenericCollection collect, int pos)
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static T? operator -(PlanesGenericCollection collect, int pos)
{
- T? obj = collect._collection.Get(pos);
+ T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
- return false;
+ return obj;
}
-
+ ///
+ /// Получение объекта IMoveableObject
+ ///
+ ///
+ ///
public U? GetU(int pos)
{
- return (U?)_collection.Get(pos)?.GetMoveableObject;
+ return (U?)_collection[pos]?.GetMoveableObject;
}
-
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
public Bitmap ShowPlanes()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
@@ -56,6 +98,10 @@ namespace ProjStormtrooper
DrawObjects(gr);
return bmp;
}
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
private void DrawBackground(Graphics g)
{
@@ -64,7 +110,7 @@ namespace ProjStormtrooper
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
- {
+ {//линия разметки места
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
@@ -73,18 +119,36 @@ namespace ProjStormtrooper
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
+ /// Метод прорисовки объектов
+ ///
+ ///
+ //private void DrawObjects(Graphics g)
+ //{
+ // for (int i = 0; i < _collection.Count; i++)
+ // {
+ // DrawingPlane plane = _collection.Get(i);
+ // if (plane != null)
+ // {
+ // int inRow = _pictureWidth / _placeSizeWidth;
+ // plane.SetPosition((_pictureWidth -30- (i % inRow + 1) * _placeSizeWidth), (i / inRow) * _placeSizeHeight);
+ // plane.DrawTransport(g);
+ // }
+ // }
+ //}
private void DrawObjects(Graphics g)
{
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
for (int i = 0; i < _collection.Count; i++)
{
- DrawingPlane plane = _collection.Get(i);
- if (plane != null)
- {
- int inRow = _pictureWidth / _placeSizeWidth;
- plane.SetPosition((_pictureWidth - 30 - (i % inRow + 1) * _placeSizeWidth), (i / inRow) * _placeSizeHeight);
- plane.DrawTransport(g);
- }
+ var obj = _collection[i];
+ obj?.SetPosition(
+ (int)((width - 1) * _placeSizeWidth - (i % width * _placeSizeWidth)),
+ (int)((i / width) * _placeSizeHeight)
+ );
+ obj?.DrawTransport(g);
}
}
}
diff --git a/ProjStormtrooper/ProjStormtrooper/PlanesGenericStorage.cs b/ProjStormtrooper/ProjStormtrooper/PlanesGenericStorage.cs
new file mode 100644
index 0000000..24643c2
--- /dev/null
+++ b/ProjStormtrooper/ProjStormtrooper/PlanesGenericStorage.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjStormtrooper
+{
+ internal class PlanesGenericStorage
+ {
+ ///
+ /// Словарь (хранилище)
+ ///
+ readonly Dictionary> _planeStorages;
+ ///
+ /// Возвращение списка названий наборов
+ ///
+ public List Keys => _planeStorages.Keys.ToList();
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public PlanesGenericStorage(int pictureWidth, int pictureHeight)
+ {
+ _planeStorages = new Dictionary>();
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ }
+ ///
+ /// Добавление набора
+ ///
+ /// Название набора
+ public void AddSet(string name)
+ {
+ _planeStorages.Add(name, new PlanesGenericCollection(_pictureWidth, _pictureHeight));
+ }
+ ///
+ /// Удаление набора
+ ///
+ /// Название набора
+ public void DelSet(string name)
+ {
+ if (_planeStorages.ContainsKey(name))
+ _planeStorages.Remove(name);
+ }
+ ///
+ /// Доступ к набору
+ ///
+ ///
+ ///
+ public PlanesGenericCollection? this[string ind]
+ {
+ get
+ {
+ if (_planeStorages.ContainsKey(ind))
+ return _planeStorages[ind];
+ return null;
+ }
+ }
+ }
+}
diff --git a/ProjStormtrooper/ProjStormtrooper/Program.cs b/ProjStormtrooper/ProjStormtrooper/Program.cs
index 52a7c1f..0f9abaf 100644
--- a/ProjStormtrooper/ProjStormtrooper/Program.cs
+++ b/ProjStormtrooper/ProjStormtrooper/Program.cs
@@ -2,6 +2,9 @@ namespace ProjStormtrooper
{
internal static class Program
{
+ ///
+ /// The main entry point for the application.
+ ///
[STAThread]
static void Main()
{
diff --git a/ProjStormtrooper/ProjStormtrooper/SetGeneric.cs b/ProjStormtrooper/ProjStormtrooper/SetGeneric.cs
index ea7a8f5..da30ea0 100644
--- a/ProjStormtrooper/ProjStormtrooper/SetGeneric.cs
+++ b/ProjStormtrooper/ProjStormtrooper/SetGeneric.cs
@@ -6,71 +6,117 @@ using System.Threading.Tasks;
namespace ProjStormtrooper
{
+ ///
+ /// Параметризованный набор объектов
+ ///
internal class SetGeneric where T : class
{
- private readonly T?[] _places;
- public int Count => _places.Length;
+ ///
+ /// Список объектов, которые храним
+ ///
+ private readonly List _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Count;
+ ///
+ /// Максимальное количество объектов в списке
+ ///
+ private readonly int _maxCount;
+ ///
+ /// Конструктор
+ ///
+ ///
public SetGeneric(int count)
{
- _places = new T?[count];
+ _maxCount = count;
+ _places = new List(count);
}
+ ///
+ /// Добавления объекта в набор
+ ///
+ ///
+ ///
public int Insert(T plane)
{
return Insert(plane, 0);
}
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ ///
+ ///
+ ///
public int Insert(T plane, int position)
{
- if (position < 0 || position >= Count)
+ // Проверка позиции
+ if (position < 0 || position >= _maxCount)
{
return -1;
}
-
- if (_places[position] != null)
- {
- int nullIndex = -1;
- for (int i = position + 1; i < Count; i++)
- {
- if (_places[i] == null)
- {
- nullIndex = i;
- break;
- }
- }
-
- if (nullIndex < 0)
- {
- return -1;
- }
-
- int j = nullIndex - 1;
- while (j >= position)
- {
- _places[j + 1] = _places[j];
- j--;
- }
- }
- _places[position] = plane;
+ // Вставка по позиции
+ _places.Insert(position, plane);
return position;
}
-
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
public T? Remove(int position)
{
+ // Проверка позиции
if (position < 0 || position >= Count)
{
return null;
}
+ // Удаление объекта из массива, присвоив элементу массива значение null
T? plane = _places[position];
_places[position] = null;
return plane;
}
-
- public T? Get(int position)
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T? this[int position]
{
- if (position < 0 || position >= Count)
+ get
{
- return null;
+ // Проверка позиции
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+ return _places[position];
+ }
+ set
+ {
+ // Проверка позиции
+ // Проверка свободных мест в списке
+ if (position < 0 || position >= _maxCount || Count == _maxCount)
+ {
+ return;
+ }
+ // Вставка в список по позиции
+ _places.Insert(position, value);
+ }
+ }
+ ///
+ /// Проход по списку
+ ///
+ ///
+ public IEnumerable GetPlanes(int? maxPlanes = null)
+ {
+ for (int i = 0; i < _places.Count; ++i)
+ {
+ yield return _places[i];
+ if (maxPlanes.HasValue && i == maxPlanes.Value)
+ {
+ yield break;
+ }
}
- return _places[position];
}
}
}
diff --git a/ProjStormtrooper/ProjStormtrooper/Status.cs b/ProjStormtrooper/ProjStormtrooper/Status.cs
index b6dad5d..063cd06 100644
--- a/ProjStormtrooper/ProjStormtrooper/Status.cs
+++ b/ProjStormtrooper/ProjStormtrooper/Status.cs
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
namespace ProjStormtrooper
{
+ ///
+ /// Статус выполнения операции перемещения
+ ///
public enum Status
{
NotInit,
diff --git a/ProjStormtrooper/ProjStormtrooper/Stormtrooper.cs b/ProjStormtrooper/ProjStormtrooper/Stormtrooper.cs
index 27c7f3b..0f74794 100644
--- a/ProjStormtrooper/ProjStormtrooper/Stormtrooper.cs
+++ b/ProjStormtrooper/ProjStormtrooper/Stormtrooper.cs
@@ -6,17 +6,30 @@ namespace ProjStormtrooper
{
public partial class Stormtrooper : Form
{
+ ///
+ /// -
+ ///
private DrawingPlane? _drawingPlane;
+ ///
+ ///
+ ///
private AbstractStrategy? _strategy;
+ ///
+ ///
+ ///
public DrawingPlane? SelectedPlane { get; private set; }
-
+ ///
+ ///
+ ///
public Stormtrooper()
{
InitializeComponent();
_strategy = null;
SelectedPlane = null;
}
-
+ ///
+ ///
+ ///
private void Draw()
{
if (_drawingPlane == null)
@@ -28,7 +41,11 @@ namespace ProjStormtrooper
_drawingPlane.DrawTransport(g);
pictureBoxStormtrooper.Image = bmp;
}
-
+ ///
+ /// " "
+ ///
+ ///
+ ///
private void buttonCreateStormtrooper_Click(object sender, EventArgs e)
{
Random random = new();
@@ -57,7 +74,11 @@ namespace ProjStormtrooper
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
-
+ ///
+ /// " "
+ ///
+ ///
+ ///
private void buttonCreatePlane_Click(object sender, EventArgs e)
{
Random random = new();
@@ -77,7 +98,11 @@ namespace ProjStormtrooper
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
-
+ ///
+ ///
+ ///
+ ///
+ ///
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingPlane == null)
@@ -102,7 +127,11 @@ namespace ProjStormtrooper
}
Draw();
}
-
+ ///
+ /// ""
+ ///
+ ///
+ ///
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawingPlane == null)
@@ -142,5 +171,12 @@ namespace ProjStormtrooper
SelectedPlane = _drawingPlane;
DialogResult = DialogResult.OK;
}
+
+ ///
+ ///
+ ///
+ ///
+ ///
+
}
}
\ No newline at end of file