Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8028c8ffa1 | |||
| 6c9a4e4cde |
@@ -4,13 +4,18 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat
|
||||
namespace MotorBoat.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
@@ -1,11 +1,18 @@
|
||||
namespace MotorBoat
|
||||
using MotorBoat.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat.Drawnings
|
||||
{
|
||||
internal class DrawningMotorBoat
|
||||
public class DrawningBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityMotorBoat? EntityMotorBoat { get; private set; }
|
||||
public EntityBoat? EntityBoat { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
@@ -20,12 +27,12 @@
|
||||
/// <summary>
|
||||
/// Координата прорисовки x
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата прорисовки y
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки
|
||||
@@ -38,25 +45,58 @@
|
||||
private readonly int _drawningMotorBoatHeight = 60;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="addTwoMotors">Два дополнительных мотора</param>
|
||||
/// <param name="sofa">Наличие дивана</param>
|
||||
/// <param name="sportLines">Наличие двух полос</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool addTwoMotors, bool sofa, bool sportLines)
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningMotorBoatWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningMotorBoatHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
public DrawningBoat()
|
||||
{
|
||||
EntityMotorBoat = new EntityMotorBoat();
|
||||
EntityMotorBoat.Init(speed, weight, bodyColor, additionalColor, addTwoMotors, sofa, sportLines);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningBoat(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityBoat = new EntityBoat(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningMotorBoatWidth">Ширина прорисовки лодки</param>
|
||||
/// <param name="drawningMotorBoatHeight">Высота прорисовки лодки</param>
|
||||
protected DrawningBoat(int drawningMotorBoatWidth, int drawningMotorBoatHeight) : this()
|
||||
{
|
||||
_drawningMotorBoatWidth = drawningMotorBoatWidth;
|
||||
_drawningMotorBoatHeight = drawningMotorBoatHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@@ -65,8 +105,6 @@
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
@@ -124,7 +162,7 @@
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityMotorBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -133,30 +171,30 @@
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityMotorBoat.Step > 0)
|
||||
if (_startPosX.Value - EntityBoat.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityMotorBoat.Step;
|
||||
_startPosX -= (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityMotorBoat.Step > 0)
|
||||
if (_startPosY.Value - EntityBoat.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityMotorBoat.Step;
|
||||
_startPosY -= (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + 140 + EntityMotorBoat.Step < _pictureWidth)
|
||||
if (_startPosX.Value + 140 + EntityBoat.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityMotorBoat.Step;
|
||||
_startPosX += (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + 60 + EntityMotorBoat.Step < _pictureHeight)
|
||||
if (_startPosY.Value + 60 + EntityBoat.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityMotorBoat.Step;
|
||||
_startPosY += (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@@ -168,88 +206,51 @@
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityMotorBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityMotorBoat.AdditionalColor);
|
||||
|
||||
// добавляем два мотора
|
||||
if (EntityMotorBoat.AddTwoMotors)
|
||||
{
|
||||
Brush br1 = new SolidBrush(EntityMotorBoat.AdditionalColor);
|
||||
g.FillEllipse(br1, _startPosX.Value + 10, _startPosY.Value + 10, 10, 10);
|
||||
g.FillRectangle(br1, _startPosX.Value + 20, _startPosY.Value + 10, 5, 10);
|
||||
g.FillEllipse(br1, _startPosX.Value + 10, _startPosY.Value + 40, 10, 10);
|
||||
g.FillRectangle(br1, _startPosX.Value + 20, _startPosY.Value + 40, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 10, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 40, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 40, 5, 10);
|
||||
}
|
||||
|
||||
// нос лодки
|
||||
Brush br2 = new SolidBrush(EntityMotorBoat.BodyColor);
|
||||
Brush br2 = new SolidBrush(EntityBoat.BodyColor);
|
||||
g.FillEllipse(br2, _startPosX.Value + 40, _startPosY.Value + 5, 100, 50);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 5, 100, 50);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 5, 100, 50);
|
||||
|
||||
// лобовое стекло
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 87, _startPosY.Value + 10, 10, 40);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 87, _startPosY.Value + 10, 10, 40);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 87, _startPosY.Value + 10, 10, 40);
|
||||
|
||||
// тело лодки
|
||||
Brush br3 = new SolidBrush(EntityMotorBoat.BodyColor);
|
||||
Brush br3 = new SolidBrush(EntityBoat.BodyColor);
|
||||
g.FillRectangle(br3, _startPosX.Value + 22, _startPosY.Value + 5, 70, 50);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 5, 70, 50);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 5, 70, 50);
|
||||
|
||||
// пространство для пассажиров
|
||||
Brush brLightGray = new SolidBrush(Color.LightGray);
|
||||
g.FillRectangle(brLightGray, _startPosX.Value + 30, _startPosY.Value + 10, 62, 40);
|
||||
g.FillRectangle(brLightGray, _startPosX.Value + 30, _startPosY.Value + 10, 62, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 10, 62, 40);
|
||||
|
||||
// прожектор лампа
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
g.FillEllipse(brYellow, _startPosX.Value + 130, _startPosY.Value + 27, 6, 6);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 130, _startPosY.Value + 27, 6, 6);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 130, _startPosY.Value + 27, 6, 6);
|
||||
|
||||
// прожектор корпус
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brBlack, _startPosX.Value + 129, _startPosY.Value + 26, 3, 8);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 129, _startPosY.Value + 26, 3, 8);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 129, _startPosY.Value + 26, 3, 8);
|
||||
|
||||
// мотор центральный
|
||||
Brush brDarkBlue = new SolidBrush(Color.DarkBlue);
|
||||
g.FillEllipse(brDarkBlue, _startPosX.Value + 10, _startPosY.Value + 25, 10, 10);
|
||||
g.FillRectangle(brDarkBlue, _startPosX.Value + 20, _startPosY.Value + 25, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 25, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 25, 5, 10);
|
||||
|
||||
// добавляем две полоски
|
||||
if (EntityMotorBoat.SportLines)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 22, 25, 2);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 36, 25, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 22, 25, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 36, 25, 2);
|
||||
}
|
||||
|
||||
// добавляем диван
|
||||
if (EntityMotorBoat.Sofa)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 10, 15, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 10, 3, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 33, _startPosY.Value + 10, 10, 2);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 33, _startPosY.Value + 48, 10, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 10, 15, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 10, 3, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 33, _startPosY.Value + 10, 10, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 33, _startPosY.Value + 48, 10, 2);
|
||||
}
|
||||
g.FillEllipse(brDarkBlue, _startPosX.Value + 10, _startPosY.Value + 25, 10, 10);
|
||||
g.FillRectangle(brDarkBlue, _startPosX.Value + 20, _startPosY.Value + 25, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 25, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 25, 5, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
72
MotorBoat/MotorBoat/Drawnings/DrawningMotorBoat.cs
Normal file
72
MotorBoat/MotorBoat/Drawnings/DrawningMotorBoat.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using MotorBoat.Entities;
|
||||
|
||||
namespace MotorBoat.Drawnings
|
||||
{
|
||||
public class DrawningMotorBoat : DrawningBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="addTwoMotors">Два дополнительных мотора</param>
|
||||
/// <param name="sofa">Наличие дивана</param>
|
||||
/// <param name="sportLines">Наличие двух полос</param>
|
||||
public DrawningMotorBoat(int speed, double weight, Color bodyColor, Color additionalColor, bool addTwoMotors, bool sofa, bool sportLines) : base (140, 60)
|
||||
{
|
||||
EntityBoat = new EntityMotorBoat(speed, weight, bodyColor, additionalColor, addTwoMotors, sofa, sportLines);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBoat == null || EntityBoat is not EntityMotorBoat motorBoat || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(motorBoat.AdditionalColor);
|
||||
base.DrawTransport(g);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
// добавляем два мотора
|
||||
if (motorBoat.AddTwoMotors)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 10, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 40, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 40, 5, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 10, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 10, 5, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 40, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 40, 5, 10);
|
||||
|
||||
}
|
||||
|
||||
// добавляем две полоски
|
||||
if (motorBoat.SportLines)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 22, 25, 2);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 36, 25, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 22, 25, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 36, 25, 2);
|
||||
}
|
||||
|
||||
// добавляем диван
|
||||
if (motorBoat.Sofa)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 10, 15, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 10, 3, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 33, _startPosY.Value + 10, 10, 2);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 33, _startPosY.Value + 48, 10, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 10, 15, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 10, 3, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 33, _startPosY.Value + 10, 10, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 33, _startPosY.Value + 48, 10, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
MotorBoat/MotorBoat/Entities/EntityBoat.cs
Normal file
42
MotorBoat/MotorBoat/Entities/EntityBoat.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
namespace MotorBoat.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность лодка
|
||||
/// </summary>
|
||||
public class EntityBoat
|
||||
{
|
||||
/// <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 EntityBoat(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,10 @@
|
||||
namespace MotorBoat
|
||||
namespace MotorBoat.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// Класс-сущность моторная лодка
|
||||
/// </summary>
|
||||
public class EntityMotorBoat
|
||||
public class EntityMotorBoat : EntityBoat
|
||||
{
|
||||
/// <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>
|
||||
@@ -46,7 +31,7 @@
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
@@ -55,11 +40,8 @@
|
||||
/// <param name="addTwoMotors">Два дополнительных мотора</param>
|
||||
/// <param name="sofa">Наличие дивана</param>
|
||||
/// <param name="sportLines">Наличие полос</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool addTwoMotors, bool sofa, bool sportLines)
|
||||
public EntityMotorBoat(int speed, double weight, Color bodyColor, Color additionalColor, bool addTwoMotors, bool sofa, bool sportLines) : base (speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
AddTwoMotors = addTwoMotors;
|
||||
Sofa = sofa;
|
||||
46
MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
generated
46
MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
generated
@@ -34,6 +34,9 @@
|
||||
buttonUp = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateBoat = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@@ -51,9 +54,9 @@
|
||||
buttonCreateMotorBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateMotorBoat.Location = new Point(12, 345);
|
||||
buttonCreateMotorBoat.Name = "buttonCreateMotorBoat";
|
||||
buttonCreateMotorBoat.Size = new Size(75, 23);
|
||||
buttonCreateMotorBoat.Size = new Size(169, 23);
|
||||
buttonCreateMotorBoat.TabIndex = 1;
|
||||
buttonCreateMotorBoat.Text = "Создать";
|
||||
buttonCreateMotorBoat.Text = "Создать спортивную лодку";
|
||||
buttonCreateMotorBoat.UseVisualStyleBackColor = true;
|
||||
buttonCreateMotorBoat.Click += ButtonCreateMotorBoat_Click;
|
||||
//
|
||||
@@ -105,11 +108,47 @@
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateBoat
|
||||
//
|
||||
buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBoat.Location = new Point(187, 345);
|
||||
buttonCreateBoat.Name = "buttonCreateBoat";
|
||||
buttonCreateBoat.Size = new Size(169, 23);
|
||||
buttonCreateBoat.TabIndex = 6;
|
||||
buttonCreateBoat.Text = "Создать обычную лодку";
|
||||
buttonCreateBoat.UseVisualStyleBackColor = true;
|
||||
buttonCreateBoat.Click += ButtonCreateBoat_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(712, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(117, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonStrategyStep.Location = new Point(712, 41);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(116, 23);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "Шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// FormMotorBoat
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(841, 380);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateBoat);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonUp);
|
||||
@@ -130,5 +169,8 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateBoat;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace MotorBoat
|
||||
using MotorBoat.Drawnings;
|
||||
using MotorBoat.MovementStratagy;
|
||||
|
||||
namespace MotorBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма работы с объектом
|
||||
@@ -8,7 +11,12 @@
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningMotorBoat? _drawningMotorBoat;
|
||||
private DrawningBoat? _drawningBoat;
|
||||
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
@@ -16,6 +24,7 @@
|
||||
public FormMotorBoat()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -23,34 +32,60 @@
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningMotorBoat == null)
|
||||
if (_drawningBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningMotorBoat.DrawTransport(gr);
|
||||
_drawningBoat.DrawTransport(gr);
|
||||
pictureBoxMotorBoat.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBoat):
|
||||
_drawningBoat = new DrawningBoat(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(DrawningMotorBoat):
|
||||
_drawningBoat = new DrawningMotorBoat(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;
|
||||
}
|
||||
|
||||
_drawningBoat.SetPictureSize(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
||||
_drawningBoat.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 ButtonCreateMotorBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningMotorBoat = new DrawningMotorBoat();
|
||||
_drawningMotorBoat.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)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningMotorBoat.SetPictureSize(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
||||
_drawningMotorBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateMotorBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMotorBoat));
|
||||
|
||||
/// <summary>
|
||||
/// Создать лодку
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
@@ -59,7 +94,7 @@
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningMotorBoat == null)
|
||||
if (_drawningBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -69,16 +104,16 @@
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningMotorBoat.MoveTransport(DirectionType.Up);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningMotorBoat.MoveTransport(DirectionType.Down);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningMotorBoat.MoveTransport(DirectionType.Left);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningMotorBoat.MoveTransport(DirectionType.Right);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -87,5 +122,43 @@
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableCar(_drawningBoat), pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
140
MotorBoat/MotorBoat/MovementStratagy/AbstractStrategy.cs
Normal file
140
MotorBoat/MotorBoat/MovementStratagy/AbstractStrategy.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
namespace MotorBoat.MovementStratagy
|
||||
{
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
MotorBoat/MotorBoat/MovementStratagy/IMoveableObject.cs
Normal file
25
MotorBoat/MotorBoat/MovementStratagy/IMoveableObject.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace MotorBoat.MovementStratagy
|
||||
{
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
47
MotorBoat/MotorBoat/MovementStratagy/MoveToBorder.cs
Normal file
47
MotorBoat/MotorBoat/MovementStratagy/MoveToBorder.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace MotorBoat.MovementStratagy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в правый нижний угол экрана
|
||||
/// </summary>
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth - 150 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth - 150 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight - 60 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight - 60;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int diffX = objParams.ObjectMiddleHorizontal - (FieldWidth - 75);
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX < 0)
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
|
||||
int diffY = objParams.ObjectMiddleVertical - (FieldWidth - 30);
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY < 0)
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
MotorBoat/MotorBoat/MovementStratagy/MoveToCenter.cs
Normal file
55
MotorBoat/MotorBoat/MovementStratagy/MoveToCenter.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace MotorBoat.MovementStratagy
|
||||
{
|
||||
/// <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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
65
MotorBoat/MotorBoat/MovementStratagy/MoveableBoat.cs
Normal file
65
MotorBoat/MotorBoat/MovementStratagy/MoveableBoat.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using MotorBoat.Drawnings;
|
||||
|
||||
namespace MotorBoat.MovementStratagy
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-реализация IMoveableObject с использованием DrawningCar
|
||||
/// </summary>
|
||||
public class MoveableCar : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningBoat или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningBoat? _boat = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="boat">Объект класса DrawningCar</param>
|
||||
public MoveableCar(DrawningBoat boat)
|
||||
{
|
||||
_boat = boat;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_boat == null || _boat.EntityBoat == null || !_boat.GetPosX.HasValue || !_boat.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_boat.GetPosX.Value, _boat.GetPosY.Value, _boat.GetWidth, _boat.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_boat?.EntityBoat?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_boat == null || _boat.EntityBoat == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _boat.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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
28
MotorBoat/MotorBoat/MovementStratagy/MovementDirections.cs
Normal file
28
MotorBoat/MotorBoat/MovementStratagy/MovementDirections.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace MotorBoat.MovementStratagy
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum MovementDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
}
|
||||
73
MotorBoat/MotorBoat/MovementStratagy/ObjectParameters.cs
Normal file
73
MotorBoat/MotorBoat/MovementStratagy/ObjectParameters.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
namespace MotorBoat.MovementStratagy
|
||||
{
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
29
MotorBoat/MotorBoat/MovementStratagy/StrategyStatus.cs
Normal file
29
MotorBoat/MotorBoat/MovementStratagy/StrategyStatus.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat.MovementStratagy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Все готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user