Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
3f846c73d2 | |||
c25cdbe283 | |||
9fb556bc07 | |||
83c1b990fe | |||
3d579a1bb0 | |||
7654aae38c | |||
f0e2b75b99 | |||
20628bbcf4 | |||
fdba4a7bba |
25
ArtilleryUnit/ArtilleryUnit.sln
Normal file
25
ArtilleryUnit/ArtilleryUnit.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34728.123
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArtilleryUnit", "ArtilleryUnit\ArtilleryUnit.csproj", "{BD69E8D6-7716-4B2C-8043-4D5F78273792}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BD69E8D6-7716-4B2C-8043-4D5F78273792}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BD69E8D6-7716-4B2C-8043-4D5F78273792}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BD69E8D6-7716-4B2C-8043-4D5F78273792}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BD69E8D6-7716-4B2C-8043-4D5F78273792}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {4D09057D-D11F-4AAC-80B5-29BBEC32C2B8}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
11
ArtilleryUnit/ArtilleryUnit/ArtilleryUnit.csproj
Normal file
11
ArtilleryUnit/ArtilleryUnit/ArtilleryUnit.csproj
Normal file
@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
27
ArtilleryUnit/ArtilleryUnit/Drawnings/DirectionType.cs
Normal file
27
ArtilleryUnit/ArtilleryUnit/Drawnings/DirectionType.cs
Normal file
@ -0,0 +1,27 @@
|
||||
namespace ProjectArtilleryUnit.Drawnings;
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
226
ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningArtilleryUnit.cs
Normal file
226
ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningArtilleryUnit.cs
Normal file
@ -0,0 +1,226 @@
|
||||
using ProjectArtilleryUnit.Entities;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ProjectArtilleryUnit.Drawnings;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningArtilleryUnit
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityArtilleryUnit? EntityArtilleryUnit { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки танка
|
||||
/// </summary>
|
||||
private readonly int _drawningArtilleryUnitWidth = 150;
|
||||
/// <summary>
|
||||
/// Высота прорисовки танка
|
||||
/// </summary>
|
||||
private readonly int _drawningArtilleryUnitHeight = 50;
|
||||
private readonly int _drawningEnginesWidth = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningArtilleryUnitWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningArtilleryUnitHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой онструктор
|
||||
/// </summary>
|
||||
private DrawningArtilleryUnit()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningArtilleryUnit(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityArtilleryUnit = new EntityArtilleryUnit(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningCarWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="drawningCarHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawningArtilleryUnit(int drawningCarWidth, int drawningCarHeight) : this()
|
||||
{
|
||||
_drawningArtilleryUnitWidth = drawningCarWidth;
|
||||
_pictureHeight = drawningCarHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена
|
||||
|
||||
if (_drawningArtilleryUnitHeight > height || _drawningArtilleryUnitWidth > width)
|
||||
{
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
SetPosition(_startPosX.Value, _startPosY.Value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (x < 0 || x + _drawningArtilleryUnitWidth > _pictureWidth || y < 0 || y + _drawningArtilleryUnitHeight > _pictureHeight)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningArtilleryUnitWidth;
|
||||
_startPosY = _pictureHeight - _drawningArtilleryUnitHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityArtilleryUnit == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityArtilleryUnit.Step - _drawningEnginesWidth > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityArtilleryUnit.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityArtilleryUnit.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityArtilleryUnit.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига в право
|
||||
if (_startPosX.Value + EntityArtilleryUnit.Step + _drawningArtilleryUnitWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityArtilleryUnit.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityArtilleryUnit.Step + _drawningArtilleryUnitHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityArtilleryUnit.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityArtilleryUnit == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Pen pen2 = new(Color.Black, 3);
|
||||
Brush Brush = new SolidBrush(EntityArtilleryUnit.BodyColor);
|
||||
|
||||
//границы танка
|
||||
Point[] points = { new Point(_startPosX.Value + 60, _startPosY.Value + 6), new Point(_startPosX.Value + 110, _startPosY.Value + 6), new Point(_startPosX.Value + 110, _startPosY.Value + 11), new Point(_startPosX.Value + 80, _startPosY.Value + 21), new Point(_startPosX.Value + 60, _startPosY.Value + 21), new Point(_startPosX.Value + 45, _startPosY.Value + 16), new Point(_startPosX.Value + 45, _startPosY.Value + 11) };
|
||||
g.FillPolygon(Brush, points);
|
||||
g.DrawPolygon(pen, points);
|
||||
|
||||
g.FillRectangle(Brush, _startPosX.Value + 7, _startPosY.Value + 21, 132, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 7, _startPosY.Value + 21, 132, 10);
|
||||
|
||||
|
||||
g.DrawArc(pen, _startPosX.Value, _startPosY.Value + 6 + 22, 25, 25, 70, 200);
|
||||
g.DrawArc(pen, _startPosX.Value + 122, _startPosY.Value + 28, 25, 25, 260, 200);
|
||||
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 29, _startPosX.Value + 135, _startPosY.Value + 29);
|
||||
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 53, _startPosX.Value + 135, _startPosY.Value + 53);
|
||||
g.DrawEllipse(pen2, _startPosX.Value + 5, _startPosY.Value + 31, 18, 18);
|
||||
g.DrawEllipse(pen2, _startPosX.Value + 125, _startPosY.Value + 31, 18, 18);
|
||||
g.DrawEllipse(pen2, _startPosX.Value + 103, _startPosY.Value + 37, 12, 12);
|
||||
g.DrawEllipse(pen2, _startPosX.Value + 34, _startPosY.Value + 37, 12, 12);
|
||||
g.DrawEllipse(pen2, _startPosX.Value + 57, _startPosY.Value + 37, 12, 12);
|
||||
g.DrawEllipse(pen2, _startPosX.Value + 80, _startPosY.Value + 37, 12, 12);
|
||||
g.DrawArc(pen, _startPosX.Value + 47, _startPosY.Value + 24, 10, 10, 0, 170);
|
||||
g.DrawArc(pen, _startPosX.Value + 70, _startPosY.Value + 24, 10, 10, 0, 170);
|
||||
g.DrawArc(pen, _startPosX.Value + 93, _startPosY.Value + 24, 10, 10, 0, 170);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using ProjectArtilleryUnit.Entities;
|
||||
|
||||
namespace ProjectArtilleryUnit.Drawnings
|
||||
{
|
||||
public class DrawningMilitaryArtilleryUnit : DrawningArtilleryUnit
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="muzzle">Признак наличия дула</param>
|
||||
/// <param name="gun">Признак наличия ракетной установки</param>
|
||||
/// <param name="luke">Признак наличия люка</param>
|
||||
|
||||
public DrawningMilitaryArtilleryUnit(int speed, double weight, Color bodyColor, Color additionalColor, bool muzzle, bool gun, bool luke)
|
||||
: base(150, 50)
|
||||
{
|
||||
EntityArtilleryUnit = new EntityMilitaryArtilleryUnit(speed, weight, bodyColor, additionalColor, muzzle, gun, luke);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityArtilleryUnit == null || EntityArtilleryUnit is not EntityMilitaryArtilleryUnit entityMilitaryArtilleryUnit || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(entityMilitaryArtilleryUnit.AdditionalColor, 2);
|
||||
Pen pen2 = new(Color.Black, 2);
|
||||
Pen pen3 = new(Color.Red, 4);
|
||||
Brush additionalBrush = new SolidBrush(entityMilitaryArtilleryUnit.AdditionalColor);
|
||||
//внутренности танка
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (entityMilitaryArtilleryUnit.Muzzle)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 11, 35, 3);
|
||||
g.DrawRectangle(pen2, _startPosX.Value + 10, _startPosY.Value + 11, 35, 3);
|
||||
}
|
||||
|
||||
if (entityMilitaryArtilleryUnit.Gun)
|
||||
{
|
||||
g.DrawLine(pen3, _startPosX.Value + 113, _startPosY.Value + 11, _startPosX.Value + 119, _startPosY.Value + 13);
|
||||
g.DrawLine(pen3, _startPosX.Value + 115, _startPosY.Value + 6, _startPosX.Value + 121, _startPosY.Value + 8);
|
||||
g.DrawLine(pen3, _startPosX.Value + 117, _startPosY.Value + 1, _startPosX.Value + 123, _startPosY.Value + 4);
|
||||
|
||||
Point[] points2 = { new Point(_startPosX.Value + 122, _startPosY.Value - 1), new Point(_startPosX.Value + 147, _startPosY.Value + 6), new Point(_startPosX.Value + 142, _startPosY.Value + 21), new Point(_startPosX.Value + 117, _startPosY.Value + 16) };
|
||||
g.FillPolygon(additionalBrush, points2);
|
||||
g.DrawPolygon(pen2, points2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (entityMilitaryArtilleryUnit.Luke)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 4, 25, 2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
38
ArtilleryUnit/ArtilleryUnit/Entities/EntityArtilleryUnit.cs
Normal file
38
ArtilleryUnit/ArtilleryUnit/Entities/EntityArtilleryUnit.cs
Normal file
@ -0,0 +1,38 @@
|
||||
namespace ProjectArtilleryUnit.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "танк"
|
||||
/// </summary>
|
||||
public class EntityArtilleryUnit
|
||||
{
|
||||
//свойства
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса танка
|
||||
/// </summary>
|
||||
/// <param name="speed">скорость</param>
|
||||
/// <param name="weight">вес</param>
|
||||
/// <param name="bodyColor">основной цвет</param>
|
||||
public EntityArtilleryUnit(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
namespace ProjectArtilleryUnit.Entities
|
||||
{
|
||||
internal class EntityMilitaryArtilleryUnit : EntityArtilleryUnit
|
||||
{
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие пушка
|
||||
/// </summary>
|
||||
public bool Muzzle { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие артелирийской пушки
|
||||
/// </summary>
|
||||
public bool Gun { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие люка
|
||||
/// </summary>
|
||||
public bool Luke { get; private set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
public EntityMilitaryArtilleryUnit(int speed, double weight, Color bodyColor, Color additionalColor, bool мuzzle, bool gun, bool luke) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Muzzle = мuzzle;
|
||||
Gun = gun;
|
||||
Luke = luke;
|
||||
}
|
||||
}
|
||||
}
|
189
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.Designer.cs
generated
Normal file
189
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.Designer.cs
generated
Normal file
@ -0,0 +1,189 @@
|
||||
namespace ProjectArtilleryUnit
|
||||
{
|
||||
partial class FormArtilleryUnit
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormArtilleryUnit));
|
||||
pictureBoxArtilleryUnit = new PictureBox();
|
||||
button1 = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonLeft = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonCretaeArtilleryUnit = new Button();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxArtilleryUnit).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxArtilleryUnit
|
||||
//
|
||||
pictureBoxArtilleryUnit.Dock = DockStyle.Fill;
|
||||
pictureBoxArtilleryUnit.Location = new Point(0, 0);
|
||||
pictureBoxArtilleryUnit.Margin = new Padding(3, 2, 3, 2);
|
||||
pictureBoxArtilleryUnit.Name = "pictureBoxArtilleryUnit";
|
||||
pictureBoxArtilleryUnit.Size = new Size(700, 338);
|
||||
pictureBoxArtilleryUnit.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxArtilleryUnit.TabIndex = 0;
|
||||
pictureBoxArtilleryUnit.TabStop = false;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
button1.Location = new Point(10, 307);
|
||||
button1.Margin = new Padding(3, 2, 3, 2);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(269, 22);
|
||||
button1.TabIndex = 1;
|
||||
button1.Text = "создать военную артиллерийскую установку";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += ButtonCreateArtilleryUnit_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(632, 280);
|
||||
buttonUp.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(26, 22);
|
||||
buttonUp.TabIndex = 2;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(632, 307);
|
||||
buttonDown.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(26, 22);
|
||||
buttonDown.TabIndex = 3;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(663, 307);
|
||||
buttonRight.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(26, 22);
|
||||
buttonRight.TabIndex = 4;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(600, 307);
|
||||
buttonLeft.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(26, 22);
|
||||
buttonLeft.TabIndex = 5;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "к центру", "к краю" });
|
||||
comboBoxStrategy.Location = new Point(557, 9);
|
||||
comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(133, 23);
|
||||
comboBoxStrategy.TabIndex = 6;
|
||||
//
|
||||
// buttonCretaeArtilleryUnit
|
||||
//
|
||||
buttonCretaeArtilleryUnit.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCretaeArtilleryUnit.Location = new Point(285, 307);
|
||||
buttonCretaeArtilleryUnit.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonCretaeArtilleryUnit.Name = "buttonCretaeArtilleryUnit";
|
||||
buttonCretaeArtilleryUnit.Size = new Size(224, 23);
|
||||
buttonCretaeArtilleryUnit.TabIndex = 7;
|
||||
buttonCretaeArtilleryUnit.Text = "создать артиллерийскую установку";
|
||||
buttonCretaeArtilleryUnit.UseVisualStyleBackColor = true;
|
||||
buttonCretaeArtilleryUnit.Click += buttonCretaeArtilleryUnit_Click;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Location = new Point(607, 34);
|
||||
buttonStrategyStep.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(82, 22);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// FormArtilleryUnit
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(700, 338);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(buttonCretaeArtilleryUnit);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(button1);
|
||||
Controls.Add(pictureBoxArtilleryUnit);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormArtilleryUnit";
|
||||
Text = "FormArtilleryUnit";
|
||||
Click += ButtonMove_Click;
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxArtilleryUnit).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxArtilleryUnit;
|
||||
private Button button1;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonCretaeArtilleryUnit;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
174
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.cs
Normal file
174
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.cs
Normal file
@ -0,0 +1,174 @@
|
||||
using ProjectArtilleryUnit.Drawnings;
|
||||
using ProjectArtilleryUnit.MovementStrategy;
|
||||
|
||||
namespace ProjectArtilleryUnit
|
||||
{
|
||||
public partial class FormArtilleryUnit : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningArtilleryUnit? _drawningArtilleryUnit;
|
||||
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public FormArtilleryUnit()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод прорисовки танка
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningArtilleryUnit == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxArtilleryUnit.Width,
|
||||
pictureBoxArtilleryUnit.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningArtilleryUnit.DrawTransport(gr);
|
||||
pictureBoxArtilleryUnit.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningArtilleryUnit):
|
||||
_drawningArtilleryUnit = new DrawningArtilleryUnit(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningMilitaryArtilleryUnit):
|
||||
_drawningArtilleryUnit = new DrawningMilitaryArtilleryUnit(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)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_drawningArtilleryUnit.SetPictureSize(pictureBoxArtilleryUnit.Width,
|
||||
pictureBoxArtilleryUnit.Height);
|
||||
_drawningArtilleryUnit.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать военный танк"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateArtilleryUnit_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryArtilleryUnit));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать танк"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCretaeArtilleryUnit_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningArtilleryUnit));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningArtilleryUnit == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result =
|
||||
_drawningArtilleryUnit.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result =
|
||||
_drawningArtilleryUnit.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result =
|
||||
_drawningArtilleryUnit.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawningArtilleryUnit.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// обработка нажатия кнопки шаг
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningArtilleryUnit == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableArtilleryUnit(_drawningArtilleryUnit), pictureBoxArtilleryUnit.Width, pictureBoxArtilleryUnit.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
1540
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.resx
Normal file
1540
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.resx
Normal file
File diff suppressed because it is too large
Load Diff
123
ArtilleryUnit/ArtilleryUnit/MovementStrategy/AbstractStrategy.cs
Normal file
123
ArtilleryUnit/ArtilleryUnit/MovementStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,123 @@
|
||||
namespace ProjectArtilleryUnit.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="movementDirection">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||
private bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
namespace ProjectArtilleryUnit.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Попытка переместить объект в указанном направлении
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
||||
|
||||
}
|
53
ArtilleryUnit/ArtilleryUnit/MovementStrategy/MoveToBorder.cs
Normal file
53
ArtilleryUnit/ArtilleryUnit/MovementStrategy/MoveToBorder.cs
Normal file
@ -0,0 +1,53 @@
|
||||
namespace ProjectArtilleryUnit.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта к краю экрана
|
||||
/// </summary>
|
||||
internal class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder - GetStep() <= FieldWidth
|
||||
&& objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder - GetStep() <= FieldHeight
|
||||
&& objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
53
ArtilleryUnit/ArtilleryUnit/MovementStrategy/MoveToCenter.cs
Normal file
53
ArtilleryUnit/ArtilleryUnit/MovementStrategy/MoveToCenter.cs
Normal file
@ -0,0 +1,53 @@
|
||||
namespace ProjectArtilleryUnit.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в центр экрана
|
||||
/// </summary>
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2
|
||||
&& objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
|
||||
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
using ProjectArtilleryUnit.Drawnings;
|
||||
|
||||
namespace ProjectArtilleryUnit.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// класс реалтзация для IMoveableObject с использованием DrawningArtilleryUnit
|
||||
/// </summary>
|
||||
public class MoveableArtilleryUnit : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningArtilleryUnit или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningArtilleryUnit? _artilleryUnit = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="artilleryUnit">Объект класса DrawningArtilleryUnit</param>
|
||||
public MoveableArtilleryUnit(DrawningArtilleryUnit artilleryUnit)
|
||||
{
|
||||
_artilleryUnit = artilleryUnit;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_artilleryUnit == null || _artilleryUnit.EntityArtilleryUnit == null ||
|
||||
!_artilleryUnit.GetPosX.HasValue || !_artilleryUnit.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_artilleryUnit.GetPosX.Value,
|
||||
_artilleryUnit.GetPosY.Value, _artilleryUnit.GetWidth, _artilleryUnit.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_artilleryUnit?.EntityArtilleryUnit?.Step ?? 0);
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_artilleryUnit == null || _artilleryUnit.EntityArtilleryUnit == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _artilleryUnit.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// </summary>
|
||||
/// <param name="direction">MovementDirection</param>
|
||||
/// <returns>DirectionType</returns>
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
MovementDirection.Left => DirectionType.Left,
|
||||
MovementDirection.Right => DirectionType.Right,
|
||||
MovementDirection.Up => DirectionType.Up,
|
||||
MovementDirection.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknow,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
namespace ProjectArtilleryUnit.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum MovementDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
namespace ProjectArtilleryUnit.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
/// </summary>
|
||||
public class ObjectParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Координата X
|
||||
/// </summary>
|
||||
private readonly int _x;
|
||||
/// <summary>
|
||||
/// Координата Y
|
||||
/// </summary>
|
||||
private readonly int _y;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
private readonly int _width;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина объекта</param>
|
||||
/// <param name="height">Высота объекта</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
namespace ProjectArtilleryUnit.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Все готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
||||
|
||||
}
|
17
ArtilleryUnit/ArtilleryUnit/Program.cs
Normal file
17
ArtilleryUnit/ArtilleryUnit/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace ProjectArtilleryUnit
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormArtilleryUnit());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user