ISEbd-21. Gruzdev A.P. Lab work 02 hard. #2

Closed
y3nnn wants to merge 2 commits from lab02 into lab01
18 changed files with 1039 additions and 245 deletions

View File

@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWarmlyShip.MovementStrategy
{
/// <summary>
/// Класс-стратегия перемещения объекта
/// </summary>
public abstract class AbstractStrategy
{
/// <summary>
/// Перемещаемый объект
/// </summary>
private IMoveableObject? _moveableObject;
/// <summary>
/// Статус перемещения
/// </summary>
private Status _state = Status.NotInit;
/// <summary>
/// Ширина поля
/// </summary>
protected int FieldWidth { get; private set; }
/// <summary>
/// Высота поля
/// </summary>
protected int FieldHeight { get; private set; }
/// <summary>
/// Статус перемещения
/// </summary>
public Status 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 = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
/// <summary>
/// Шаг перемещения
/// </summary>
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
/// <summary>
/// Перемещение влево
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveLeft() => MoveTo(DirectionType.Left);
/// <summary>
/// Перемещение вправо
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveRight() => MoveTo(DirectionType.Right);
/// <summary>
/// Перемещение вверх
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveUp() => MoveTo(DirectionType.Up);
/// <summary>
/// Перемещение вниз
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveDown() => MoveTo(DirectionType.Down);
/// <summary>
/// Параметры объекта
/// </summary>
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
/// <summary>
/// Шаг объекта
/// </summary>
/// <returns></returns>
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
/// <summary>
/// Перемещение к цели
/// </summary>
protected abstract void MoveToTarget();
/// <summary>
/// Достигнута ли цель
/// </summary>
/// <returns></returns>
protected abstract bool IsTargetDestinaion();
/// <summary>
/// Попытка перемещения в требуемом направлении
/// </summary>
/// <param name="directionType">Направление</param>
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWarmlyShip
{
public class DrawDecksParal : IDrawingDecks
{
private NumDecks numDecks;
public int SomeProperty
{
set
{
switch (value)
{
case 1:
numDecks = NumDecks.OneDeck;
break;
case 2:
numDecks = NumDecks.TwoDecks;
break;
case 3:
numDecks = NumDecks.ThreeDecks;
break;
default:
numDecks = NumDecks.OneDeck;
MessageBox.Show("Было введено неверное количество палуб, поэтому была выведена 1 палуба");
break;
}
}
}
public void Draw(int _startPosX, int _startPosY, Color Os, Graphics g)
{
Pen pen = new Pen(Color.Black);
Brush os = new SolidBrush(Os);
if (numDecks == NumDecks.OneDeck)
{
Point point1 = new Point(_startPosX + 40, _startPosY + 12);
Point point2 = new Point(_startPosX + 50, _startPosY);
Point point3 = new Point(_startPosX + 175, _startPosY);
Point point4 = new Point(_startPosX + 165, _startPosY + 12);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(os, curvePoints1);
}
if (numDecks == NumDecks.TwoDecks)
{
Point point1 = new Point(_startPosX + 40, _startPosY + 24);
Point point2 = new Point(_startPosX + 50, _startPosY + 12);
Point point3 = new Point(_startPosX + 175, _startPosY + 12);
Point point4 = new Point(_startPosX + 165, _startPosY + 24);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(os, curvePoints1);
Point point5 = new Point(_startPosX + 62, _startPosY + 12);
Point point6 = new Point(_startPosX + 72, _startPosY);
Point point7 = new Point(_startPosX + 153, _startPosY);
Point point8 = new Point(_startPosX + 143, _startPosY + 12);
Point[] curvePoints2 = { point5, point6, point7, point8 };
g.FillPolygon(os, curvePoints2);
}
if (numDecks == NumDecks.ThreeDecks)
{
Point point1 = new Point(_startPosX + 40, _startPosY + 36);
Point point2 = new Point(_startPosX + 50, _startPosY + 24);
Point point3 = new Point(_startPosX + 175, _startPosY + 24);
Point point4 = new Point(_startPosX + 165, _startPosY + 36);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(os, curvePoints1);
Point point5 = new Point(_startPosX + 62, _startPosY + 24);
Point point6 = new Point(_startPosX + 72, _startPosY + 12);
Point point7 = new Point(_startPosX + 153, _startPosY + 12);
Point point8 = new Point(_startPosX + 143, _startPosY + 24);
Point[] curvePoints2 = { point5, point6, point7, point8 };
g.FillPolygon(os, curvePoints2);
Point point9 = new Point(_startPosX + 87, _startPosY + 12);
Point point10 = new Point(_startPosX + 97, _startPosY);
Point point11 = new Point(_startPosX + 131, _startPosY);
Point point12 = new Point(_startPosX + 121, _startPosY + 12);
Point[] curvePoints3 = { point9, point10, point11, point12 };
g.FillPolygon(os, curvePoints3);
}
}
}
}

View File

@ -6,16 +6,12 @@ using System.Threading.Tasks;
namespace ProjectWarmlyShip namespace ProjectWarmlyShip
{ {
public class DecksDrawing public class DrawDecksSquare : IDrawingDecks
{ {
private NumDecks numDecks; private NumDecks numDecks;
public int? SomeProperty public int SomeProperty
{ {
get
{
return SomeProperty;
}
set set
{ {
switch (value) switch (value)
@ -34,23 +30,33 @@ namespace ProjectWarmlyShip
MessageBox.Show("Было введено неверное количество палуб, поэтому была выведена 1 палуба"); MessageBox.Show("Было введено неверное количество палуб, поэтому была выведена 1 палуба");
break; break;
} }
} }
} }
public void Draw(int _startPosX, int _startPosY, Color Os, Color Ad, Graphics g) public void Draw(int _startPosX, int _startPosY, Color Os, Graphics g)
{ {
Brush ad = new SolidBrush(Ad); Pen pen = new Pen(Color.Black);
Brush os = new SolidBrush(Os); Brush os = new SolidBrush(Os);
if (numDecks == NumDecks.OneDeck)
{
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 0, 125, 12);
g.FillRectangle(os, _startPosX + 50, _startPosY + 0, 125, 12);
}
if (numDecks == NumDecks.TwoDecks) if (numDecks == NumDecks.TwoDecks)
{ {
g.FillRectangle(ad, _startPosX + 75, _startPosY, 75, 12); g.DrawRectangle(pen, _startPosX + 50, _startPosY + 12, 125, 12);
g.DrawRectangle(pen, _startPosX + 75, _startPosY, 75, 12);
g.FillRectangle(os, _startPosX + 50, _startPosY + 12, 125, 12);
g.FillRectangle(os, _startPosX + 75, _startPosY, 75, 12);
} }
if (numDecks == NumDecks.ThreeDecks) if (numDecks == NumDecks.ThreeDecks)
{ {
g.FillRectangle(ad, _startPosX + 75, _startPosY + 12, 75, 12); g.DrawRectangle(pen, _startPosX + 50, _startPosY + 24, 125, 12);
g.DrawRectangle(pen, _startPosX + 75, _startPosY + 12, 75, 12);
g.DrawRectangle(pen, _startPosX + 100, _startPosY, 25, 12);
g.FillRectangle(os, _startPosX + 50, _startPosY + 24, 125, 12);
g.FillRectangle(os, _startPosX + 75, _startPosY + 12, 75, 12);
g.FillRectangle(os, _startPosX + 100, _startPosY, 25, 12); g.FillRectangle(os, _startPosX + 100, _startPosY, 25, 12);
} }
} }
} }
} }

View File

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWarmlyShip
{
public class DrawDecksTrapeze : IDrawingDecks
{
private NumDecks numDecks;
public int SomeProperty
{
set
{
switch (value)
{
case 1:
numDecks = NumDecks.OneDeck;
break;
case 2:
numDecks = NumDecks.TwoDecks;
break;
case 3:
numDecks = NumDecks.ThreeDecks;
break;
default:
numDecks = NumDecks.OneDeck;
MessageBox.Show("Было введено неверное количество палуб, поэтому была выведена 1 палуба");
break;
}
}
}
public void Draw(int _startPosX, int _startPosY, Color Os, Graphics g)
{
Pen pen = new Pen(Color.Black);
Brush os = new SolidBrush(Os);
if (numDecks == NumDecks.OneDeck)
{
Point point1 = new Point(_startPosX + 40, _startPosY + 12);
Point point2 = new Point(_startPosX + 50, _startPosY);
Point point3 = new Point(_startPosX + 165, _startPosY);
Point point4 = new Point(_startPosX + 175, _startPosY + 12);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(os, curvePoints1);
}
if (numDecks == NumDecks.TwoDecks)
{
Point point1 = new Point(_startPosX + 40, _startPosY + 24);
Point point2 = new Point(_startPosX + 50, _startPosY + 12);
Point point3 = new Point(_startPosX + 165, _startPosY + 12);
Point point4 = new Point(_startPosX + 175, _startPosY + 24);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(os, curvePoints1);
Point point5 = new Point(_startPosX + 62, _startPosY + 12);
Point point6 = new Point(_startPosX + 72, _startPosY);
Point point7 = new Point(_startPosX + 143, _startPosY);
Point point8 = new Point(_startPosX + 153, _startPosY + 12);
Point[] curvePoints2 = { point5, point6, point7, point8 };
g.FillPolygon(os, curvePoints2);
}
if (numDecks == NumDecks.ThreeDecks)
{
Point point1 = new Point(_startPosX + 40, _startPosY + 36);
Point point2 = new Point(_startPosX + 50, _startPosY + 24);
Point point3 = new Point(_startPosX + 165, _startPosY + 24);
Point point4 = new Point(_startPosX + 175, _startPosY + 36);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(os, curvePoints1);
Point point5 = new Point(_startPosX + 62, _startPosY + 24);
Point point6 = new Point(_startPosX + 72, _startPosY + 12);
Point point7 = new Point(_startPosX + 143, _startPosY + 12);
Point point8 = new Point(_startPosX + 153, _startPosY + 24);
Point[] curvePoints2 = { point5, point6, point7, point8 };
g.FillPolygon(os, curvePoints2);
Point point9 = new Point(_startPosX + 87, _startPosY + 12);
Point point10 = new Point(_startPosX + 97, _startPosY);
Point point11 = new Point(_startPosX + 121, _startPosY);
Point point12 = new Point(_startPosX + 131, _startPosY + 12);
Point[] curvePoints3 = { point9, point10, point11, point12 };
g.FillPolygon(os, curvePoints3);
}
}
}
}

View File

@ -3,50 +3,13 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ProjectWarmlyShip.Entities;
namespace ProjectWarmlyShip namespace ProjectWarmlyShip.DrawningObjects
{ {
// Класс, отвечающий за прорисовку и перемещение объекта-сущности // Класс, отвечающий за прорисовку и перемещение объекта-сущности
internal class DrawingWarmlyShip public class DrawingWarmlyShip : DrawningShip
{ {
/// <summary>
/// Класс-сущность
/// </summary>
public EntityWarmlyShip? EntityWarmlyShip { get; private set; }
public DecksDrawing? DrawingDecks;
/// <summary>
///Ширина окна
/// </summary>
private int _pictureWidth;
/// <summary>
///Высота окна
/// </summary>
private int _pictureHeight;
/// <summary>
/// Левая координата прорисовки теплохода
/// </summary>
private int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки теплохода
/// </summary>
///
private int _startPosY;
/// <summary>
/// Ширина прорисовки теплохода
/// </summary>
private int _shipWidth = 200;
/// <summary>
/// Высота прорисовки теплохода
/// </summary>
private int _shipHeight = 30;
/// <summary> /// <summary>
/// Инициализация свойств /// Инициализация свойств
/// </summary> /// </summary>
@ -58,191 +21,67 @@ namespace ProjectWarmlyShip
/// <param name="width">Ширина картинки</param> /// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param> /// <param name="height">Высота картинки</param>
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns> /// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool shipPipes, bool shipFuel, int width, int height, int _numDecks) public DrawingWarmlyShip(int speed, double weight, Color bodyColor, Color additionalColor, bool shipPipes, bool shipFuel, int width, int height, int numdecks, int nummode) :
base(speed, weight, bodyColor, width, height, numdecks, nummode)
{ {
if (width < _shipWidth || height < _shipHeight) if (EntityShip != null)
{ {
return false; EntityShip = new EntityWarmlyShip(speed, weight, bodyColor, additionalColor, shipPipes, shipFuel);
} }
_pictureWidth = width;
_pictureHeight = height;
EntityWarmlyShip = new EntityWarmlyShip();
EntityWarmlyShip.Init(speed, weight, bodyColor, additionalColor, shipPipes, shipFuel, _numDecks);
DrawingDecks = new DecksDrawing();
DrawingDecks.SomeProperty = _numDecks;
return true;
} }
/// <summary> public override void DrawTransport(Graphics g)
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{ {
if ((x > 0) && (x < _pictureWidth)) _startPosX = x; if (EntityShip is not EntityWarmlyShip warmlyShip)
else _startPosX = 0;
if ((y > 0) && (y < _pictureHeight)) _startPosY = y;
else _startPosY = 0;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (EntityWarmlyShip == null)
{ {
return; return;
} }
switch (direction) Brush additionalBrush = new SolidBrush(warmlyShip.AdditionalColor);
if (_shipHeight == 30)
{ {
//влево //трубы
case DirectionType.Left: if (warmlyShip.ShipPipes)
if (_startPosX - EntityWarmlyShip.Step > 0)
{ {
_startPosX -= (int)EntityWarmlyShip.Step; g.FillRectangle(additionalBrush, _startPosX + 180, _startPosY + 2, 3, 12);
g.FillRectangle(additionalBrush, _startPosX + 185, _startPosY + 4, 5, 10);
} }
else
{
_startPosX = 0;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - EntityWarmlyShip.Step > 0)
{
_startPosY -= (int)EntityWarmlyShip.Step;
}
else
{
_startPosY = 0;
}
break;
// вправо
case DirectionType.Right:
if (_startPosX + _shipWidth + EntityWarmlyShip.Step < _pictureWidth)
{
_startPosX += (int)EntityWarmlyShip.Step;
}
else
{
_startPosX = _pictureWidth - _shipWidth;
}
break;
//вниз
case DirectionType.Down:
if (_startPosY + _shipHeight + EntityWarmlyShip.Step < _pictureHeight)
{
_startPosY += (int)EntityWarmlyShip.Step;
}
else
{
_startPosY = _pictureHeight - _shipHeight;
}
break;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{
if (EntityWarmlyShip == null)
{
return;
}
Brush additionalBrush = new SolidBrush(EntityWarmlyShip.AdditionalColor);
Brush bodyBrush = new SolidBrush(EntityWarmlyShip.BodyColor);
Brush brAqua = new SolidBrush(Color.Aquamarine);
//границы корабля
if (EntityWarmlyShip.numDecks == 1)
{
Point point1 = new Point(_startPosX, _startPosY + 12);
Point point2 = new Point(_startPosX + 25, _startPosY + 35);
Point point3 = new Point(_startPosX + 175, _startPosY + 35);
Point point4 = new Point(_startPosX + 200, _startPosY + 12);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(bodyBrush, curvePoints1);
//граница палубы
g.FillRectangle(brAqua, _startPosX + 50, _startPosY + 0, 125, 12);
//топливо //топливо
if (EntityWarmlyShip.ShipFuel) if (warmlyShip.ShipFuel)
{ {
g.FillRectangle(additionalBrush, _startPosX + 12, _startPosY + 5, 27, 7); g.FillRectangle(additionalBrush, _startPosX + 12, _startPosY + 5, 27, 7);
} }
}
if (_shipHeight == 42)
{
//трубы //трубы
if (EntityWarmlyShip.ShipPipes) if (warmlyShip.ShipPipes)
{ {
g.FillRectangle(additionalBrush, _startPosX + 180, _startPosY + 2, 3, 10); g.FillRectangle(additionalBrush, _startPosX + 180, _startPosY + 14, 3, 12);
g.FillRectangle(additionalBrush, _startPosX + 185, _startPosY + 4, 5, 8); g.FillRectangle(additionalBrush, _startPosX + 185, _startPosY + 16, 5, 10);
} }
//палубы
DrawingDecks.Draw(_startPosX, _startPosY, EntityWarmlyShip.BodyColor, EntityWarmlyShip.AdditionalColor, g);
}
if (EntityWarmlyShip.numDecks == 2)
{
_shipHeight = 42;
Point point1 = new Point(_startPosX, _startPosY + 24);
Point point2 = new Point(_startPosX + 25, _startPosY + 47);
Point point3 = new Point(_startPosX + 175, _startPosY + 47);
Point point4 = new Point(_startPosX + 200, _startPosY + 22);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(bodyBrush, curvePoints1);
//граница палубы
g.FillRectangle(brAqua, _startPosX + 50, _startPosY + 12, 125, 12);
//топливо //топливо
if (EntityWarmlyShip.ShipFuel) if (warmlyShip.ShipFuel)
{ {
g.FillRectangle(additionalBrush, _startPosX + 12, _startPosY + 17, 27, 7); g.FillRectangle(additionalBrush, _startPosX + 12, _startPosY + 17, 27, 7);
} }
}
if (_shipHeight == 54)
{
//трубы //трубы
if (EntityWarmlyShip.ShipPipes) if (warmlyShip.ShipPipes)
{ {
g.FillRectangle(additionalBrush, _startPosX + 180, _startPosY + 14, 3, 10); g.FillRectangle(additionalBrush, _startPosX + 180, _startPosY + 26, 3, 12);
g.FillRectangle(additionalBrush, _startPosX + 185, _startPosY + 16, 5, 8); g.FillRectangle(additionalBrush, _startPosX + 185, _startPosY + 28, 5, 10);
} }
//палубы
DrawingDecks.Draw(_startPosX, _startPosY, EntityWarmlyShip.BodyColor, EntityWarmlyShip.AdditionalColor, g);
}
if (EntityWarmlyShip.numDecks == 3)
{
_shipHeight = 54;
Point point1 = new Point(_startPosX, _startPosY + 36);
Point point2 = new Point(_startPosX + 25, _startPosY + 59);
Point point3 = new Point(_startPosX + 175, _startPosY + 59);
Point point4 = new Point(_startPosX + 200, _startPosY + 34);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(bodyBrush, curvePoints1);
//граница палубы
g.FillRectangle(brAqua, _startPosX + 50, _startPosY + 24, 125, 12);
//топливо //топливо
if (EntityWarmlyShip.ShipFuel) if (warmlyShip.ShipFuel)
{ {
g.FillRectangle(additionalBrush, _startPosX + 12, _startPosY + 29, 27, 7); g.FillRectangle(additionalBrush, _startPosX + 12, _startPosY + 29, 27, 7);
} }
//трубы
if (EntityWarmlyShip.ShipPipes)
{
g.FillRectangle(additionalBrush, _startPosX + 180, _startPosY + 26, 3, 10);
g.FillRectangle(additionalBrush, _startPosX + 185, _startPosY + 28, 5, 8);
}
//палубы
DrawingDecks.Draw(_startPosX, _startPosY, EntityWarmlyShip.BodyColor, EntityWarmlyShip.AdditionalColor, g);
} }
base.DrawTransport(g);
} }
} }
} }

View File

@ -0,0 +1,35 @@
using ProjectWarmlyShip.DrawningObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWarmlyShip.MovementStrategy
{
/// <summary>
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningShip (паттерн Adapter)
/// </summary>
public class DrawningObjectShip : IMoveableObject
{
private readonly DrawningShip? _drawningShip = null;
public DrawningObjectShip(DrawningShip drawningShip)
{
_drawningShip = drawningShip;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningShip == null || _drawningShip.EntityShip == null)
{
return null;
}
return new ObjectParameters(_drawningShip.GetPosX, _drawningShip.GetPosY, _drawningShip.GetWidth, _drawningShip.GetHeight);
}
}
public int GetStep => (int)(_drawningShip?.EntityShip?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) => _drawningShip?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) => _drawningShip?.MoveTransport(direction);
}
}

View File

@ -0,0 +1,236 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectWarmlyShip.Entities;
namespace ProjectWarmlyShip.DrawningObjects
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningShip
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityShip? EntityShip { get; protected set; }
private IDrawingDecks? DrawingDecks;
/// <summary>
/// Ширина окна
/// </summary>
private int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int _pictureHeight;
/// <summary>
/// Левая координата прорисовки автомобиля
/// </summary>
protected int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки автомобиля
/// </summary>
protected int _startPosY;
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
protected readonly int _shipWidth = 200;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
public int _shipHeight = 30;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawningShip(int speed, double weight, Color bodyColor, int width, int height, int numDecks, int nummode)
{
// TODO: Продумать проверки
if (width > _shipWidth && height > _shipHeight)
{
_pictureWidth = width;
_pictureHeight = height;
EntityShip = new EntityShip(speed, weight, bodyColor);
int mode = nummode % 3;
switch (mode)
{
case 0:
DrawingDecks = new DrawDecksSquare();
break;
case 1:
DrawingDecks = new DrawDecksTrapeze();
break;
case 2:
DrawingDecks = new DrawDecksParal();
break;
}
DrawingDecks.SomeProperty = numDecks;
if (numDecks == 2)
_shipHeight = 42;
if (numDecks == 3)
_shipHeight = 54;
}
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
/// <param name="shipWidth">Ширина прорисовки автомобиля</param>
/// <param name="shipHeight">Высота прорисовки автомобиля</param>
protected DrawningShip(int speed, double weight, Color bodyColor, int width, int height, int shipWidth, int shipHeight, int numDecks)
{
// TODO: Продумать проверки
//if (width > _shipWidth && height > _shipHeight)
_pictureWidth = width;
_pictureHeight = height;
_shipWidth = shipWidth;
_shipHeight = shipHeight;
EntityShip = new EntityShip(speed, weight, bodyColor);
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
if ((x > 0) && (x < _pictureWidth))
_startPosX = x;
else _startPosX = 0;
if ((y > 0) && (y < _pictureHeight))
_startPosY = y;
else _startPosY = 0;
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY => _startPosY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _shipWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _shipHeight;
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному направлению</returns>
public bool CanMove(DirectionType direction)
{
if (EntityShip == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityShip.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityShip.Step > 0,
// вправо
DirectionType.Right => _startPosX + _shipWidth + EntityShip.Step < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + _shipHeight + EntityShip.Step < _pictureHeight,
};
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityShip == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
_startPosX -= (int)EntityShip.Step;
break;
//вверх
case DirectionType.Up:
_startPosY -= (int)EntityShip.Step;
break;
// вправо
case DirectionType.Right:
_startPosX += (int)EntityShip.Step;
break;
//вниз
case DirectionType.Down:
_startPosY += (int)EntityShip.Step;
break;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (EntityShip == null)
{
return;
}
Brush BodyBrush = new SolidBrush(EntityShip.BodyColor);
//границы корабля
if (_shipHeight == 30)
{
Point point1 = new Point(_startPosX, _startPosY + 12);
Point point2 = new Point(_startPosX + 25, _startPosY + 35);
Point point3 = new Point(_startPosX + 175, _startPosY + 35);
Point point4 = new Point(_startPosX + 200, _startPosY + 12);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(BodyBrush, curvePoints1);
}
if (_shipHeight == 42)
{
Point point1 = new Point(_startPosX, _startPosY + 24);
Point point2 = new Point(_startPosX + 25, _startPosY + 47);
Point point3 = new Point(_startPosX + 175, _startPosY + 47);
Point point4 = new Point(_startPosX + 200, _startPosY + 22);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(BodyBrush, curvePoints1);
}
if (_shipHeight == 54)
{
Point point1 = new Point(_startPosX, _startPosY + 36);
Point point2 = new Point(_startPosX + 25, _startPosY + 59);
Point point3 = new Point(_startPosX + 175, _startPosY + 59);
Point point4 = new Point(_startPosX + 200, _startPosY + 34);
Point[] curvePoints1 = { point1, point2, point3, point4 };
g.FillPolygon(BodyBrush, curvePoints1);
}
DrawingDecks.Draw(_startPosX, _startPosY, EntityShip.BodyColor, g);
}
}
}

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWarmlyShip.Entities
{
/// <summary>
/// Класс-сущность "Корабль"
/// </summary>
public class EntityShip
{
/// <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 => (double)Speed * 100 / Weight;
public int numDecks;
/// <summary>
/// Конструктор с параметрами
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityShip(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -3,23 +3,12 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ProjectWarmlyShip.DrawningObjects;
namespace ProjectWarmlyShip namespace ProjectWarmlyShip.Entities
{ {
public class EntityWarmlyShip internal class EntityWarmlyShip : EntityShip
{ {
/// <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>
/// Дополнительный цвет (для опциональных элементов) /// Дополнительный цвет (для опциональных элементов)
/// </summary> /// </summary>
@ -31,15 +20,10 @@ namespace ProjectWarmlyShip
/// <summary> /// <summary>
/// Признак (опция) наличия дополнительного топлива /// Признак (опция) наличия дополнительного топлива
/// </summary> /// </summary>
public bool ShipFuel { get; private set; } /// /// <summary>
/// <summary>
/// Шаг перемещения теплохода
/// </summary>
public double Step => (double)Speed * 100 / Weight;
/// <summary>
/// количество палуб [2;3] /// количество палуб [2;3]
/// </summary> /// </summary>
public int numDecks; public bool ShipFuel { get; private set; }
/// <summary> /// <summary>
/// Инициализация полей объекта-класса теплохода /// Инициализация полей объекта-класса теплохода
/// </summary> /// </summary>
@ -49,17 +33,11 @@ namespace ProjectWarmlyShip
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="ShipPipes">Признак наличия труб</param> /// <param name="ShipPipes">Признак наличия труб</param>
/// <param name="ShipFuel">Признак наличия топлива</param> /// <param name="ShipFuel">Признак наличия топлива</param>
/// /// <param name="ShipFuel">Признак наличия топлива</param> public EntityWarmlyShip(int speed, double weight, Color bodyColor, Color additionalColor, bool shipPipes, bool shipFuel) : base(speed, weight, bodyColor)
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool shipPipes, bool shipFuel, int _numDecks)
{ {
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
ShipPipes = shipPipes; ShipPipes = shipPipes;
ShipFuel = shipFuel; ShipFuel = shipFuel;
numDecks = _numDecks;
} }
} }
} }

View File

@ -31,6 +31,9 @@
buttonDown = new Button(); buttonDown = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonRight = new Button(); buttonRight = new Button();
buttonCreateDeckShip = new Button();
comboBoxStrategy = new ComboBox();
buttonStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -45,7 +48,7 @@
// //
// buttonCreate // buttonCreate
// //
buttonCreate.Location = new Point(12, 426); buttonCreate.Location = new Point(195, 426);
buttonCreate.Name = "buttonCreate"; buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(75, 23); buttonCreate.Size = new Size(75, 23);
buttonCreate.TabIndex = 1; buttonCreate.TabIndex = 1;
@ -97,11 +100,42 @@
buttonRight.UseVisualStyleBackColor = true; buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click; buttonRight.Click += buttonMove_Click;
// //
// buttonCreateDeckShip
//
buttonCreateDeckShip.Location = new Point(12, 426);
buttonCreateDeckShip.Name = "buttonCreateDeckShip";
buttonCreateDeckShip.Size = new Size(177, 23);
buttonCreateDeckShip.TabIndex = 6;
buttonCreateDeckShip.Text = "Создать корабль с обвесами";
buttonCreateDeckShip.UseVisualStyleBackColor = true;
buttonCreateDeckShip.Click += buttonCreateDeckShip_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Location = new Point(706, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(166, 23);
comboBoxStrategy.TabIndex = 7;
//
// buttonStep
//
buttonStep.Location = new Point(761, 41);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(75, 23);
buttonStep.TabIndex = 8;
buttonStep.Text = "Шаг";
buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += ButtonStep_Click;
//
// FormWarmlyShip // FormWarmlyShip
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(884, 461); ClientSize = new Size(884, 461);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateDeckShip);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonDown); Controls.Add(buttonDown);
@ -123,5 +157,8 @@
private Button buttonDown; private Button buttonDown;
private Button buttonUp; private Button buttonUp;
private Button buttonRight; private Button buttonRight;
private Button buttonCreateDeckShip;
private ComboBox comboBoxStrategy;
private Button buttonStep;
} }
} }

View File

@ -1,4 +1,6 @@
using ProjectWarmlyShip; using ProjectWarmlyShip;
using ProjectWarmlyShip.DrawningObjects;
using ProjectWarmlyShip.MovementStrategy;
using static ProjectWarmlyShip.DirectionType; using static ProjectWarmlyShip.DirectionType;
namespace ProjectWarmlyShipHard namespace ProjectWarmlyShipHard
{ {
@ -7,13 +9,19 @@ namespace ProjectWarmlyShipHard
/// <summary> /// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà /// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary> /// </summary>
private DrawingWarmlyShip? _drawingWarmlyShip; private DrawningShip? _drawingWarmlyShip;
/// <summary>
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
/// </summary>
private AbstractStrategy? _abstractStrategy;
/// <summary> /// <summary>
/// Èíèöèàëèçàöèÿ ôîðìû /// Èíèöèàëèçàöèÿ ôîðìû
/// </summary> /// </summary>
public FormWarmlyShip() public FormWarmlyShip()
{ {
InitializeComponent(); InitializeComponent();
comboBoxStrategy.Items.Add("Äâèæåíèå â öåíòð");
comboBoxStrategy.Items.Add("Äâèæåíèå ê ãðàíèöå");
} }
/// <summary> /// <summary>
/// Ìåòîä ïðîðèñîâêè êîðàáëÿ /// Ìåòîä ïðîðèñîâêè êîðàáëÿ
@ -37,12 +45,25 @@ namespace ProjectWarmlyShipHard
private void buttonCreate_Click(object sender, EventArgs e) private void buttonCreate_Click(object sender, EventArgs e)
{ {
Random random = new(); Random random = new();
_drawingWarmlyShip = new DrawingWarmlyShip(); _drawingWarmlyShip = new DrawningShip(random.Next(100, 300), random.Next(1000, 3000),
_drawingWarmlyShip.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height, random.Next(1, 4), random.Next(1, 4));
_drawingWarmlyShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü êîðàáëü ñ îáâåñàìè"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateDeckShip_Click(object sender, EventArgs e)
{
Random random = new();
_drawingWarmlyShip = new DrawingWarmlyShip(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)),
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)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height, random.Next(1, 4)); pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height, random.Next(1, 4), random.Next(1, 4));
_drawingWarmlyShip.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawingWarmlyShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }
@ -75,5 +96,44 @@ namespace ProjectWarmlyShipHard
} }
Draw(); Draw();
} }
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawingWarmlyShip == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new DrawningObjectShip(_drawingWarmlyShip), pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
} }
} }

View File

@ -123,7 +123,7 @@
iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAABGdBTUEAALGPC/xhBQAAAG9QTFRF//// iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAABGdBTUEAALGPC/xhBQAAAG9QTFRF////
AAAAWVlZ8fHx9PT0REREtLS0Ojo6+Pj4a2trp6enj4+P3t7eXl5efX1919fXh4eHw8PD6+vrdXV10dHR AAAAWVlZ8fHx9PT0REREtLS0Ojo6+Pj4a2trp6enj4+P3t7eXl5efX1919fXh4eHw8PD6+vrdXV10dHR
5ubmDAwMy8vLTU1NlZWVvLy8iIiINjY2nJycFhYWYWFhJycnUVFRHR0dr6+vKioqoesKnwAAAAlwSFlz 5ubmDAwMy8vLTU1NlZWVvLy8iIiINjY2nJycFhYWYWFhJycnUVFRHR0dr6+vKioqoesKnwAAAAlwSFlz
AAAOwQAADsEBuJFr7QAAAkFJREFUeF7t3GtT2zAQhWErF5JAnIQQSrmFW///b+wCR6LY/Vg3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AAAAlwSFlz 5ubmDAwMy8vLTU1NlZWVvLy8iIiINjY2nJycFhYWYWFhJycnUVFRHR0dr6+vKioqoesKnwAAAAlwSFlz
AAAOwQAADsEBuJFr7QAAAipJREFUeF7t3NlS20AQRmEJGzAgL+ybIQTy/s8YOfyawtJtZIWT891QVleB AAAOvwAADr8BOAVTJAAAAipJREFUeF7t3NlS20AQRmEJGzAgL+ybIQTy/s8YOfyawtJtZIWT891QVleB
u6iWZnpmVEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS9F3N8hOqWdb13WqeT0BP9aebfMa5TYJ1fZ4rNKvk u6iWZnpmVEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS9F3N8hOqWdb13WqeT0BP9aebfMa5TYJ1fZ4rNKvk
17rOJZjjpLdzirzjnCa7P+6IxXiU5AJYjN2ttLPKdZAfSa3zwCvGs6TWeV8nwPGS1IqTBDjuk1mxSYDj 17rOJZjjpLdzirzjnCa7P+6IxXiU5AJYjN2ttLPKdZAfSa3zwCvGs6TWeV8nwPGS1IqTBDjuk1mxSYDj
du+Z0XrADVMX/WJ8axLheExqxVMCHJfJrHhOgKPZJrXOcpEIxqKdCu/Z8orxOakVlwlw9Eep9WMCHM1b du+Z0XrADVMX/WJ8axLheExqxVMCHJfJrHhOgKPZJrXOcpEIxqKdCu/Z8orxOakVlwlw9Eep9WMCHM1b

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWarmlyShip
{
public interface IDrawingDecks
{
int SomeProperty { set;}
void Draw(int _startPosX, int _startPosY, Color Os, Graphics g);
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWarmlyShip.MovementStrategy
{
/// <summary>
/// Интерфейс для работы с перемещаемым объектом
/// </summary>
public interface IMoveableObject
{
/// <summary>
/// Получение координаты X объекта
/// </summary>
ObjectParameters? GetObjectPosition { get; }
/// <summary>
/// Шаг объекта
/// </summary>
int GetStep { get; }
/// <summary>
/// Проверка, можно ли переместиться по нужному направлению
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
bool CheckCanMove(DirectionType direction);
/// <summary>
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
void MoveObject(DirectionType direction);
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWarmlyShip.MovementStrategy
{
/// <summary>
/// Стратегия перемещения объекта в центр экрана
/// </summary>
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectRightBorder <= FieldWidth &&
objParams.ObjectRightBorder + GetStep() >= FieldWidth &&
objParams.ObjectDownBorder <= FieldHeight &&
objParams.ObjectDownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.ObjectRightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.ObjectDownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWarmlyShip.MovementStrategy
{
/// <summary>
/// Стратегия перемещения объекта в центр экрана
/// </summary>
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace ProjectWarmlyShip.MovementStrategy
{
/// <summary>
/// Параметры-координаты объекта
/// </summary>
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
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>
public int ObjectRightBorder => _x + _width;
/// <summary>
/// Нижняя граница
/// </summary>
public int ObjectDownBorder => _y + _height;
/// <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;
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWarmlyShip.MovementStrategy
{
public enum Status
{
NotInit, InProgress, Finish
}
}