diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/DirectionType.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/DirectionType.cs
index ef5e6cc..ad2d556 100644
--- a/ProjectAircraftCarrier/ProjectAircraftCarrier/DirectionType.cs
+++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/DirectionType.cs
@@ -1,18 +1,27 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ProjectAircraftCarrier;
+namespace ProjectAircraftCarrier;
+///
+/// Направление перемещения
+///
public enum DirectionType
{
+ ///
+ /// Вверх
+ ///
Up = 1,
+ ///
+ /// Вниз
+ ///
Down = 2,
+ ///
+ /// Влево
+ ///
Left = 3,
+ ///
+ /// Вправо
+ ///
Right = 4
}
diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs
index 870a1f2..e82c3be 100644
--- a/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs
+++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs
@@ -1,27 +1,54 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ProjectAircraftCarrier;
+namespace ProjectAircraftCarrier;
+///
+/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+///
public class DrawningAircraftCarrier
{
+ ///
+ /// Класс-сущность
+ ///
public EntityAircraftCarrier? EntityAircraftCarrier { get; private set; }
+ ///
+ /// Ширина окна
+ ///
private int? _pictureWidth;
+ ///
+ /// Высота окна
+ ///
private int? _pictureHeight;
+ ///
+ /// Левая координата прорисовки авианосца
+ ///
private int? _startPosX;
+ ///
+ /// Верхняя координата отрисовки авианосца
+ ///
private int? _startPosY;
+ ///
+ /// Ширина прорисовки авианосца
+ ///
private readonly int _drawningAircraftCarrierWidth = 150;
+ ///
+ /// Высота прорисовки авианосца
+ ///
private readonly int _drawningAircraftCarrierHeight = 65;
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия взлётно-посадочной полосы
+ /// Признак наличия рубки управления
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool aircraftDeck, bool controlRoom)
{
EntityAircraftCarrier = new EntityAircraftCarrier();
@@ -32,6 +59,12 @@ public class DrawningAircraftCarrier
_startPosY = null;
}
+ ///
+ /// Установка границ поля
+ ///
+ /// Ширина поля
+ /// Высота поля
+ /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах
public bool SetPictureSize(int width, int height)
{
if (width < _drawningAircraftCarrierWidth || height < _drawningAircraftCarrierHeight)
@@ -64,6 +97,11 @@ public class DrawningAircraftCarrier
}
+ ///
+ /// Установка позиции
+ ///
+ /// Координата X
+ /// Координата Y
public void SetPosition(int x, int y)
{
if(!_pictureHeight.HasValue || !_pictureWidth.HasValue)
@@ -85,6 +123,11 @@ public class DrawningAircraftCarrier
_startPosY = y;
}
+ ///
+ /// Измнение направления перемещения
+ ///
+ /// Направление
+ /// true - перемещение выполнено, false - перемещение невозможно
public bool MoveTransport(DirectionType direction)
{
if(EntityAircraftCarrier == null || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@@ -94,24 +137,28 @@ public class DrawningAircraftCarrier
switch (direction)
{
+ //влево
case DirectionType.Left:
if (_startPosX.Value - EntityAircraftCarrier.Step > 0)
{
_startPosX -= (int)EntityAircraftCarrier.Step;
}
return true;
+ //вверх
case DirectionType.Up:
if (_startPosY.Value - EntityAircraftCarrier.Step > 0)
{
_startPosY -= (int)EntityAircraftCarrier.Step;
}
return true;
+ //вправо
case DirectionType.Right:
if (_startPosX.Value + _drawningAircraftCarrierWidth + EntityAircraftCarrier.Step < _pictureWidth)
{
_startPosX += (int)EntityAircraftCarrier.Step;
}
return true;
+ //вниз
case DirectionType.Down:
if (_startPosY.Value + _drawningAircraftCarrierHeight + EntityAircraftCarrier.Step < _pictureHeight)
{
@@ -123,6 +170,10 @@ public class DrawningAircraftCarrier
}
}
+ ///
+ /// Прорисовка объекта
+ ///
+ ///
public void DrawTransport(Graphics g)
{
if (EntityAircraftCarrier == null || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@@ -198,7 +249,5 @@ public class DrawningAircraftCarrier
g.DrawPolygon(pen, DeckPoint);
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 45, _startPosX.Value + 55, _startPosY.Value + 20);
}
-
}
-
}
diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/EntityAircraftCarrier.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/EntityAircraftCarrier.cs
index 385cee7..18896d3 100644
--- a/ProjectAircraftCarrier/ProjectAircraftCarrier/EntityAircraftCarrier.cs
+++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/EntityAircraftCarrier.cs
@@ -1,60 +1,54 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ProjectAircraftCarrier;
+namespace ProjectAircraftCarrier;
///
-///
+/// Класс-сущность "Авианосец"
///
public class EntityAircraftCarrier
{
///
- ///
+ /// Скорость
///
public int Speed { get; private set; }
///
- ///
+ /// Вес
///
public double Weight { get; private set; }
///
- ///
+ /// Основной цвет
///
public Color BodyColor { get; private set; }
///
- ///
+ /// Дополнительный цвет (для опциональных элементов)
///
public Color AdditionalColor { get; private set; }
///
- ///
+ /// Признак (опция) наличие взлётно-посадочной полосы
///
public bool AircraftDeck { get; private set; }
///
- ///
+ /// Признак (опция) наличие рубки управления
///
public bool ControlRoom { get; private set; }
///
- ///
+ /// Шаг перемещения авианосца
///
public double Step => Speed * 100 / Weight;
///
- ///
+ /// Инициализация полей объекта-класса авианосца
///
- ///
- ///
- ///
- ///
- ///
- ///
+ /// Скорость
+ /// Вес авианосца
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия взлётно-посадочной полосы
+ /// Признак наличия рубки управления
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool aircraftDeck, bool controlRoom)
{
Speed = speed;
diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs
index cb771ef..f9ac235 100644
--- a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs
+++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs
@@ -41,8 +41,9 @@
//
pictureBoxAircraftCarrier.Dock = DockStyle.Fill;
pictureBoxAircraftCarrier.Location = new Point(0, 0);
+ pictureBoxAircraftCarrier.Margin = new Padding(3, 4, 3, 4);
pictureBoxAircraftCarrier.Name = "pictureBoxAircraftCarrier";
- pictureBoxAircraftCarrier.Size = new Size(803, 471);
+ pictureBoxAircraftCarrier.Size = new Size(918, 628);
pictureBoxAircraftCarrier.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxAircraftCarrier.TabIndex = 0;
pictureBoxAircraftCarrier.TabStop = false;
@@ -50,9 +51,10 @@
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(12, 436);
+ buttonCreate.Location = new Point(14, 581);
+ buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(75, 23);
+ buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "создать";
buttonCreate.UseVisualStyleBackColor = true;
@@ -63,7 +65,8 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
- buttonRight.Location = new Point(761, 429);
+ buttonRight.Location = new Point(876, 585);
+ buttonRight.Margin = new Padding(3, 4, 3, 4);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 2;
@@ -75,7 +78,8 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
- buttonUp.Location = new Point(725, 393);
+ buttonUp.Location = new Point(840, 547);
+ buttonUp.Margin = new Padding(3, 4, 3, 4);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 3;
@@ -87,7 +91,8 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
- buttonDown.Location = new Point(725, 429);
+ buttonDown.Location = new Point(840, 585);
+ buttonDown.Margin = new Padding(3, 4, 3, 4);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 4;
@@ -99,7 +104,8 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
- buttonLeft.Location = new Point(689, 429);
+ buttonLeft.Location = new Point(804, 585);
+ buttonLeft.Margin = new Padding(3, 4, 3, 4);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 5;
@@ -108,15 +114,16 @@
//
// FormAircraftCarrier
//
- AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(803, 471);
+ ClientSize = new Size(918, 628);
Controls.Add(buttonLeft);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxAircraftCarrier);
+ Margin = new Padding(3, 4, 3, 4);
Name = "FormAircraftCarrier";
StartPosition = FormStartPosition.CenterScreen;
Text = "Авианосец";
diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs
index b3f0311..e46f886 100644
--- a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs
+++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs
@@ -8,72 +8,93 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
-namespace ProjectAircraftCarrier
+namespace ProjectAircraftCarrier;
+
+///
+/// Форма работы с объектом "Авианосец"
+///
+public partial class FormAircraftCarrier : Form
{
- public partial class FormAircraftCarrier : Form
+ ///
+ /// Поле-объект для прорисовки объекта
+ ///
+ private DrawningAircraftCarrier? _drawningAircraftCarrier;
+
+ ///
+ /// Конструктор формы
+ ///
+ public FormAircraftCarrier()
{
- private DrawningAircraftCarrier? _drawningAircraftCarrier;
+ InitializeComponent();
+ }
- public FormAircraftCarrier()
+ ///
+ /// Метод прорисовки авианосца
+ ///
+ private void Draw()
+ {
+ if (_drawningAircraftCarrier == null)
{
- InitializeComponent();
+ return;
}
- private void Draw()
- {
- if (_drawningAircraftCarrier == null)
- {
- return;
- }
+ Bitmap bmp = new(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawningAircraftCarrier.DrawTransport(gr);
+ pictureBoxAircraftCarrier.Image = bmp;
+ }
- Bitmap bmp = new(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
- Graphics gr = Graphics.FromImage(bmp);
- _drawningAircraftCarrier.DrawTransport(gr);
- pictureBoxAircraftCarrier.Image = bmp;
+ ///
+ /// Обработка нажатия кнопки "Создать"
+ ///
+ ///
+ ///
+ private void buttonCreate_Click(object sender, EventArgs e)
+ {
+ Random random = new();
+ _drawningAircraftCarrier = new DrawningAircraftCarrier();
+ _drawningAircraftCarrier.Init(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ _drawningAircraftCarrier.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
+ _drawningAircraftCarrier.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ Draw();
+ }
+
+ ///
+ /// Перемещение объекта по форме (нажатие кнопок навигации)
+ ///
+ ///
+ ///
+ private void buttonMove_Click(object sender, EventArgs e)
+ {
+ if (_drawningAircraftCarrier == null)
+ {
+ return;
}
- private void buttonCreate_Click(object sender, EventArgs e)
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ bool result = false;
+ switch (name)
+ {
+ case "buttonUp":
+ result = _drawningAircraftCarrier.MoveTransport(DirectionType.Up);
+ break;
+ case "buttonDown":
+ result = _drawningAircraftCarrier.MoveTransport(DirectionType.Down);
+ break;
+ case "buttonLeft":
+ result = _drawningAircraftCarrier.MoveTransport(DirectionType.Left);
+ break;
+ case "buttonRight":
+ result = _drawningAircraftCarrier.MoveTransport(DirectionType.Right);
+ break;
+ }
+
+ if (result)
{
- Random random = new();
- _drawningAircraftCarrier = new DrawningAircraftCarrier();
- _drawningAircraftCarrier.Init(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
- _drawningAircraftCarrier.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
- _drawningAircraftCarrier.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
-
- private void buttonMove_Click(object sender, EventArgs e)
- {
- if (_drawningAircraftCarrier == null)
- {
- return;
- }
-
- string name = ((Button)sender)?.Name ?? string.Empty;
- bool result = false;
- switch (name)
- {
- case "buttonUp":
- result = _drawningAircraftCarrier.MoveTransport(DirectionType.Up);
- break;
- case "buttonDown":
- result = _drawningAircraftCarrier.MoveTransport(DirectionType.Down);
- break;
- case "buttonLeft":
- result = _drawningAircraftCarrier.MoveTransport(DirectionType.Left);
- break;
- case "buttonRight":
- result = _drawningAircraftCarrier.MoveTransport(DirectionType.Right);
- break;
- }
-
- if (result)
- {
- Draw();
- }
- }
}
}