изменения в лабе 2
This commit is contained in:
parent
7f9117622a
commit
a30f2a037c
18
ProjectCar/ProjectCar/FormGasMachine.Designer.cs
generated
18
ProjectCar/ProjectCar/FormGasMachine.Designer.cs
generated
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectCar
|
namespace ProjectGasMachine
|
||||||
{
|
{
|
||||||
partial class FormGasMachine
|
partial class FormGasMachine
|
||||||
{
|
{
|
||||||
@ -28,7 +28,7 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormGasMachine));
|
//System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormGasMachine));
|
||||||
buttonCreate = new Button();
|
buttonCreate = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
@ -53,7 +53,8 @@
|
|||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
//buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||||
|
buttonLeft.BackgroundImage = Properties.Resources.free_icon_left_arrow_10696518;
|
||||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonLeft.Location = new Point(862, 481);
|
buttonLeft.Location = new Point(862, 481);
|
||||||
buttonLeft.Name = "buttonLeft";
|
buttonLeft.Name = "buttonLeft";
|
||||||
@ -65,7 +66,8 @@
|
|||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
//buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||||
|
buttonRight.BackgroundImage = Properties.Resources.free_icon_left_arrow_10696518;
|
||||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonRight.Location = new Point(944, 481);
|
buttonRight.Location = new Point(944, 481);
|
||||||
buttonRight.Name = "buttonRight";
|
buttonRight.Name = "buttonRight";
|
||||||
@ -77,7 +79,8 @@
|
|||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
//buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||||
|
buttonUp.BackgroundImage = Properties.Resources.free_icon_left_arrow_10696518;
|
||||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonUp.Location = new Point(903, 440);
|
buttonUp.Location = new Point(903, 440);
|
||||||
buttonUp.Name = "buttonUp";
|
buttonUp.Name = "buttonUp";
|
||||||
@ -89,7 +92,8 @@
|
|||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
//buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||||
|
buttonDown.BackgroundImage = Properties.Resources.free_icon_left_arrow_10696518;
|
||||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonDown.Location = new Point(903, 481);
|
buttonDown.Location = new Point(903, 481);
|
||||||
buttonDown.Name = "buttonDown";
|
buttonDown.Name = "buttonDown";
|
||||||
@ -117,7 +121,7 @@
|
|||||||
buttonCreateMachine.TabIndex = 6;
|
buttonCreateMachine.TabIndex = 6;
|
||||||
buttonCreateMachine.Text = "Создать орнамент на колесах";
|
buttonCreateMachine.Text = "Создать орнамент на колесах";
|
||||||
buttonCreateMachine.UseVisualStyleBackColor = true;
|
buttonCreateMachine.UseVisualStyleBackColor = true;
|
||||||
buttonCreateMachine.Click += buttonCreateMachine_Click;
|
buttonCreateMachine.Click += ButtonCreateMachine_Click;
|
||||||
//
|
//
|
||||||
// FormGasMachine
|
// FormGasMachine
|
||||||
//
|
//
|
||||||
|
69
ProjectCar/ProjectCar/MovementStrategy/AbstractStrategy.cs
Normal file
69
ProjectCar/ProjectCar/MovementStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
namespace ProjectGasMachine.MovementStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// класс-стратегия перемещения объекта
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// перемещаемый объект
|
||||||
|
/// </summary>
|
||||||
|
private IMoveableObjects? _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(IMoveableObjects moveableObject, int width, int height)
|
||||||
|
{
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
_state = StrategyStatus.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = StrategyStatus.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsTargetDestination())
|
||||||
|
{
|
||||||
|
_state = StrategyStatus.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
24
ProjectCar/ProjectCar/MovementStrategy/IMoveableObjects.cs
Normal file
24
ProjectCar/ProjectCar/MovementStrategy/IMoveableObjects.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
namespace ProjectGasMachine.MovementStrategy;
|
||||||
|
/// <summary>
|
||||||
|
/// интерфейс для работы с перемещаемым объектом
|
||||||
|
/// </summary>
|
||||||
|
public interface IMoveableObjects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// получение координаты объекта
|
||||||
|
/// </summary>
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
int GetStep { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// попытка переместить объект в указанном направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
||||||
|
bool TryMoveObject(MovementDirection direction);
|
||||||
|
|
||||||
|
}
|
21
ProjectCar/ProjectCar/MovementStrategy/MovementDirection.cs
Normal file
21
ProjectCar/ProjectCar/MovementStrategy/MovementDirection.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
namespace ProjectGasMachine.MovementStrategy;
|
||||||
|
|
||||||
|
public enum MovementDirection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
72
ProjectCar/ProjectCar/MovementStrategy/ObjectParameters.cs
Normal file
72
ProjectCar/ProjectCar/MovementStrategy/ObjectParameters.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
namespace ProjectGasMachine.MovementStrategy;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
22
ProjectCar/ProjectCar/MovementStrategy/StrategyStatus.cs
Normal file
22
ProjectCar/ProjectCar/MovementStrategy/StrategyStatus.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
namespace ProjectGasMachine.MovementStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// статус выполнения операции перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum StrategyStatus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// все готово к началу
|
||||||
|
/// </summary>
|
||||||
|
NotInit,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// выполняется
|
||||||
|
/// </summary>
|
||||||
|
InProgress,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// завершено
|
||||||
|
/// </summary>
|
||||||
|
Finish
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user