Лаба02
This commit is contained in:
parent
95a9f6f733
commit
bc9b12c8fe
135
ContainerShip/ContainerShip/AbstractStrategy.cs
Normal file
135
ContainerShip/ContainerShip/AbstractStrategy.cs
Normal file
@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static ProjectContainerShip.Direction;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace ProjectContainerShip.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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectContainerShip
|
||||
{
|
||||
public enum Direction
|
||||
public class Direction
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
@ -26,3 +30,4 @@ namespace ProjectContainerShip
|
||||
Right = 4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
64
ContainerShip/ContainerShip/DrawingContainerShip.cs
Normal file
64
ContainerShip/ContainerShip/DrawingContainerShip.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static ProjectContainerShip.Direction;
|
||||
using ProjectContainerShip.Entities;
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace ProjectContainerShip.DrawningObjects
|
||||
{
|
||||
public class DrawningContainerShip : DrawningShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет палубы</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="crane">Признак наличия крана</param>
|
||||
/// <param name="container">Признак наличия контейнеров</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||
public DrawningContainerShip(int speed, double weight, Color bodyColor, Color additionalColor, bool crane, bool container, int width, int height) :
|
||||
base(speed, weight, bodyColor, width, height, 200, 30)
|
||||
{
|
||||
if (EntityShip != null)
|
||||
{
|
||||
EntityShip = new EntityContainerShip(speed, weight, bodyColor, additionalColor, crane, container);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityShip is not EntityContainerShip containerShip)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Brush additionalBrush = new SolidBrush(containerShip.AdditionalColor);
|
||||
// Контейнер
|
||||
if (containerShip.Container)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY + 7, 35, 5);
|
||||
}
|
||||
//кран
|
||||
if (containerShip.Crane)
|
||||
{
|
||||
Brush brBl = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brBl, _startPosX + 110, _startPosY + 0, 3, 12);
|
||||
g.FillRectangle(brBl, _startPosX + 105, _startPosY + 1, 20, 2);
|
||||
}
|
||||
// несколько контенеров
|
||||
if (containerShip.Container)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY + 2, 35, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY + 7, 35, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY + 2, 35, 5);
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,189 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectContainerShip
|
||||
{
|
||||
public class DrawningContainerShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityContainerShip? EntityContainerShip { get; private set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
/// <summary>
|
||||
/// /// Левая координата прорисовки контейнеровоза
|
||||
/// </summary>
|
||||
private int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки контенеровоза
|
||||
/// </summary>
|
||||
private int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки Контейнеровоза
|
||||
/// </summary>
|
||||
private readonly int _shipWidth = 200;
|
||||
/// <summary>
|
||||
/// Высота прорисовки Контейнеровоза
|
||||
/// </summary>
|
||||
private readonly int _shipHeight = 30;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет палубы</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="crane">Признак наличия крана</param>
|
||||
/// <param name="container">Признак наличия количества контейнеров</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool crane, bool container, int width, int height)
|
||||
{
|
||||
if (width < _shipWidth || height < _shipHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityContainerShip = new EntityContainerShip();
|
||||
EntityContainerShip.Init(speed, weight, bodyColor, additionalColor,
|
||||
crane, container);
|
||||
return true;
|
||||
}
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (EntityContainerShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case Direction.Left:
|
||||
if (_startPosX - EntityContainerShip.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityContainerShip.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
//вверх
|
||||
case Direction.Up:
|
||||
if (_startPosY - EntityContainerShip.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityContainerShip.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
// вправо
|
||||
case Direction.Right:
|
||||
if (_startPosX + _shipWidth + EntityContainerShip.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityContainerShip.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = _pictureWidth - _shipWidth;
|
||||
}
|
||||
break;
|
||||
|
||||
//вниз
|
||||
case Direction.Down:
|
||||
if (_startPosY + _shipHeight + EntityContainerShip.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityContainerShip.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = _pictureHeight - _shipHeight;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityContainerShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(EntityContainerShip.AdditionalColor);
|
||||
//граница палубы
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 0, 16, 12);
|
||||
// Контейнер
|
||||
g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY + 7, 35, 5);
|
||||
//кран
|
||||
if (EntityContainerShip.Crane)
|
||||
{
|
||||
Brush brBl = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brBl, _startPosX + 110, _startPosY + 0, 3, 12);
|
||||
g.FillRectangle(brBl, _startPosX + 105, _startPosY + 1, 20, 2);
|
||||
}
|
||||
// несколько контенеров
|
||||
if (EntityContainerShip.Container)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY + 2, 35, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY + 7, 35, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY + 2, 35, 5);
|
||||
}
|
||||
//границы корабля
|
||||
Brush brRD = new SolidBrush(Color.Red);
|
||||
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(brRD, curvePoints1);
|
||||
}
|
||||
}
|
||||
}
|
36
ContainerShip/ContainerShip/DrawningObjectShip.cs
Normal file
36
ContainerShip/ContainerShip/DrawningObjectShip.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectContainerShip.DrawningObjects;
|
||||
using static ProjectContainerShip.Direction;
|
||||
|
||||
namespace ProjectContainerShip.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);
|
||||
}
|
||||
}
|
200
ContainerShip/ContainerShip/DrawningShip.cs
Normal file
200
ContainerShip/ContainerShip/DrawningShip.cs
Normal file
@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectContainerShip;
|
||||
using ProjectContainerShip.Entities;
|
||||
using ProjectContainerShip.MovementStrategy;
|
||||
using static ProjectContainerShip.Direction;
|
||||
|
||||
namespace ProjectContainerShip.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningShip
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectShip(this);
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityShip? EntityShip { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки корабля
|
||||
/// </summary>
|
||||
protected int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки корабля
|
||||
/// </summary>
|
||||
protected int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки корабля
|
||||
/// </summary>
|
||||
protected readonly int _shipWidth = 200;
|
||||
/// <summary>
|
||||
/// Высота прорисовки корабля
|
||||
/// </summary>
|
||||
protected readonly 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)
|
||||
{
|
||||
if (width > _shipWidth && height > _shipHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityShip = new EntityShip(speed, weight, bodyColor);
|
||||
}
|
||||
}
|
||||
/// <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)
|
||||
{
|
||||
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;
|
||||
public object GetObjectPosition { get; internal set; }
|
||||
/// <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 brRD = new SolidBrush(Color.Red);
|
||||
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(brRD, curvePoints1);
|
||||
|
||||
//граница палубы
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 0, 16, 12);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectContainerShip
|
||||
{
|
||||
public class EntityContainerShip
|
||||
public class EntityContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -23,37 +23,18 @@ namespace ProjectContainerShip
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия крана
|
||||
/// </summary>
|
||||
public bool Crane { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия контейнеров
|
||||
/// </summary>
|
||||
public bool Container { get; private set; }
|
||||
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса контейнеровоза
|
||||
/// Инициализация полей объекта-класса конетейнеровоза
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес Контейнеровоза</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="crane">Признак наличия крана</param>
|
||||
/// <param name="container">Признак наличия дополнительных контейнеров</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool crane, bool container)
|
||||
public void Init(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Crane = crane;
|
||||
Container = container;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
ContainerShip/ContainerShip/EntityContainerShip.cs
Normal file
40
ContainerShip/ContainerShip/EntityContainerShip.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectContainerShip.Entities
|
||||
{
|
||||
internal class EntityContainerShip : EntityShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия крана
|
||||
/// </summary>
|
||||
public bool Crane { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия дополнительных контейнеров
|
||||
/// </summary>
|
||||
public bool Container { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса контейнеровоза
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес </param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="Crane">Признак наличия крана</param>
|
||||
/// <param name="Container">Признак наличия контейнеров</param>
|
||||
public EntityContainerShip(int speed, double weight, Color bodyColor, Color additionalColor, bool crane, bool container) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Crane = crane;
|
||||
Container = container;
|
||||
}
|
||||
}
|
||||
}
|
40
ContainerShip/ContainerShip/EntityShip.cs
Normal file
40
ContainerShip/ContainerShip/EntityShip.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectContainerShip
|
||||
{
|
||||
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;
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
180
ContainerShip/ContainerShip/FormContainerShip.Designer.cs
generated
Normal file
180
ContainerShip/ContainerShip/FormContainerShip.Designer.cs
generated
Normal file
@ -0,0 +1,180 @@
|
||||
namespace ProjectWarmlyShip
|
||||
{
|
||||
partial class FormContainerShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormContainerShip));
|
||||
pictureBoxWarmlyShip = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonLeft = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
buttonCreateDeckShip = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxWarmlyShip
|
||||
//
|
||||
pictureBoxWarmlyShip.Dock = DockStyle.Fill;
|
||||
pictureBoxWarmlyShip.Location = new Point(0, 0);
|
||||
pictureBoxWarmlyShip.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxWarmlyShip.Name = "pictureBoxWarmlyShip";
|
||||
pictureBoxWarmlyShip.Size = new Size(1010, 615);
|
||||
pictureBoxWarmlyShip.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxWarmlyShip.TabIndex = 0;
|
||||
pictureBoxWarmlyShip.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(225, 564);
|
||||
buttonCreate.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(86, 31);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(962, 559);
|
||||
buttonRight.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(34, 40);
|
||||
buttonRight.TabIndex = 2;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(921, 511);
|
||||
buttonUp.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(34, 40);
|
||||
buttonUp.TabIndex = 3;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(921, 559);
|
||||
buttonDown.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(34, 40);
|
||||
buttonDown.TabIndex = 4;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(880, 559);
|
||||
buttonLeft.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(34, 40);
|
||||
buttonLeft.TabIndex = 5;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Location = new Point(858, 16);
|
||||
comboBoxStrategy.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(138, 28);
|
||||
comboBoxStrategy.TabIndex = 6;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Location = new Point(898, 55);
|
||||
buttonStep.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(86, 31);
|
||||
buttonStep.TabIndex = 7;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += ButtonStep_Click;
|
||||
//
|
||||
// buttonCreateDeckShip
|
||||
//
|
||||
buttonCreateDeckShip.Location = new Point(14, 564);
|
||||
buttonCreateDeckShip.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreateDeckShip.Name = "buttonCreateDeckShip";
|
||||
buttonCreateDeckShip.Size = new Size(205, 31);
|
||||
buttonCreateDeckShip.TabIndex = 8;
|
||||
buttonCreateDeckShip.Text = "Создать контейнеровоз";
|
||||
buttonCreateDeckShip.UseVisualStyleBackColor = true;
|
||||
buttonCreateDeckShip.Click += buttonCreateDeckShip_Click;
|
||||
//
|
||||
// FormContainerShip
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1010, 615);
|
||||
Controls.Add(buttonCreateDeckShip);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxWarmlyShip);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormContainerShip";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "WarmlyShip";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxWarmlyShip;
|
||||
private Button buttonCreate;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonCreateDeckShip;
|
||||
}
|
||||
}
|
141
ContainerShip/ContainerShip/FormContainerShip.cs
Normal file
141
ContainerShip/ContainerShip/FormContainerShip.cs
Normal file
@ -0,0 +1,141 @@
|
||||
using ProjectContainerShip.DrawningObjects;
|
||||
using ProjectContainerShip.MovementStrategy;
|
||||
using static ProjectContainerShip.Direction;
|
||||
|
||||
namespace ProjectWarmlyShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Êîíòåéíåðîâîç"
|
||||
/// </summary>
|
||||
public partial class FormContainerShip : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawningShip? _drawingContainerShip;
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
/// </summary>
|
||||
public FormContainerShip()
|
||||
{
|
||||
InitializeComponent();
|
||||
comboBoxStrategy.Items.Add(0);
|
||||
comboBoxStrategy.Items.Add(1);
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingContainerShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingContainerShip.DrawTransport(gr);
|
||||
pictureBoxWarmlyShip.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingContainerShip = new DrawningShip(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);
|
||||
_drawingContainerShip.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();
|
||||
_drawingContainerShip = new DrawningContainerShip(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)),
|
||||
pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
||||
_drawingContainerShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Èçìåíåíèå ïîëîæåíèÿ êîðàáëÿ
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingContainerShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingContainerShip.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingContainerShip.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingContainerShip.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingContainerShip.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingContainerShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawningObjectShip(_drawingContainerShip), pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
201
ContainerShip/ContainerShip/FormContainerShip.resx
Normal file
201
ContainerShip/ContainerShip/FormContainerShip.resx
Normal file
@ -0,0 +1,201 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAABGdBTUEAALGPC/xhBQAAAG9QTFRF////
|
||||
AAAAWVlZ8fHx9PT0REREtLS0Ojo6+Pj4a2trp6enj4+P3t7eXl5efX1919fXh4eHw8PD6+vrdXV10dHR
|
||||
5ubmDAwMy8vLTU1NlZWVvLy8iIiINjY2nJycFhYWYWFhJycnUVFRHR0dr6+vKioqoesKnwAAAAlwSFlz
|
||||
AAAOvgAADr4B6kKxwAAAAipJREFUeF7t3NlS20AQRmEJGzAgL+ybIQTy/s8YOfyawtJtZIWT891QVleB
|
||||
u6iWZnpmVEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS9F3N8hOqWdb13WqeT0BP9aebfMa5TYJ1fZ4rNKvk
|
||||
17rOJZjjpLdzirzjnCa7P+6IxXiU5AJYjN2ttLPKdZAfSa3zwCvGs6TWeV8nwPGS1IqTBDjuk1mxSYDj
|
||||
du+Z0XrADVMX/WJ8axLheExqxVMCHJfJrHhOgKPZJrXOcpEIxqKdCu/Z8orxOakVlwlw9Eep9WMCHM1b
|
||||
Uuuc4Ypx/jOpdbZXiXBsklpxnwDHSTIrXhLgWL8ntQ6vRzX72p/aAfaovjQZP/GK8SOZFbwe1U0yK3g9
|
||||
qll/WnzMK8brpFbwGsbnyaz4SIBj0KPiFePVoBh5S6n9YerriA3j9ero8Jb9if+IxXiRPzC9kYpxcF+b
|
||||
0EW+0181e81v/yeMMSseDKImNUaHajAtndQYDSr+/3COr0P+vfQ/eB5WVbPJOOOQDjmmmcghx6VTwM8t
|
||||
8PND/Byf3qfB99rw/VJ8z5u+boFfe1r35zG09UP8GjB9HR+/FwO/nwa/J4q+r23RO12C25uI31+K3yNM
|
||||
3+c92Kv/C1aCw/MWsBLEn5nBn3vCn13Dnz/knyHlnwPee04gz3Lzz+Pz36nAfy8G/90m7bywfSKi30+z
|
||||
g7zDSJIkSZIkSZIkSZIkSZIkSZIkSZIkSZK+q6r6DXB6GOTqATe4AAAAAElFTkSuQmCC
|
||||
</value>
|
||||
</data>
|
||||
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAABGdBTUEAALGPC/xhBQAAAG9QTFRF////
|
||||
AAAAWVlZ8fHx9PT0REREtLS0Ojo6+Pj4a2trp6enj4+P3t7eXl5efX1919fXh4eHw8PD6+vrdXV10dHR
|
||||
5ubmDAwMy8vLTU1NlZWVvLy8iIiINjY2nJycFhYWYWFhJycnUVFRHR0dr6+vKioqoesKnwAAAAlwSFlz
|
||||
AAAOvgAADr4B6kKxwAAAA01JREFUeF7t3dluo0AURVHwEGdO7DjznPT/f2PHcAgULsD90FKd0l5P7jKR
|
||||
2FF0jYuWXQAAAAAAAAAAAAAAAADA/7JZP643epyls3LnTP/K0GUVWJaX+nd2vhVYlt9aycyV8nautJaV
|
||||
xZvqdt4WWs3JUnG1pVYz0kyZRnbTpp0yjcymzVZZXVs9l4W5okJzPZuDcMo0Mpo2/SnTyGbanCpo36mO
|
||||
MHevnJh7HWMtPmUaOUyblVriVjrK2I1ShtzoOFuvChn2qiNNjU2ZhvW02ShinPHGzfGLGirXF3pQlhfX
|
||||
elB5Odbxfk6UUFkVncJwwp7oeDuPCqhtipkeleWs9/f7qJ8ws9bp137mSbewN4PW+hkr5zr52u4KNCjs
|
||||
Xa2eVz9jJZwy1et6WBheCxhOm3as/KivzXqF4bS5qJaMPOvEa/X1db8wvCZ/rtZsPOm0a9qR6Rf2dm+e
|
||||
6kUP4ZRpdtX2Cns7cEbTZvGhc6787lXsF4b7G398ps2DTrnS7jdFCsM9qgctJi+46Pxq38XHCufduxnl
|
||||
tVYTd6TTrXXuMsUKgztSZXmk1aQNn3K0cPgXkqr5l861EvzZxQsH/6hTFUyZTy3WBgqLT61Wkp82wfj/
|
||||
CO+DDhUOvLikafQNw1Bh5G1IssYvwwYL4xd5KZrf6Rwre5fSw4XhhfpdutNm4u3QSGHnuR/JboRPvaUd
|
||||
K4y8YU7P5LbEWKHDtAmnTGxrabSwt3GV4LRZ6NRq0e3B8cLe5mN6/6UoeKmPb/FOFIYbyOm98HdfKFbx
|
||||
t7JThcfdWXynxWQEu0q3WuyZKixu9XQluRdFndfO0O2yycJgI1xL6Wj3RwdveU4Xdm6ovmslHb+vZ8M3
|
||||
kg4obKdNghtvunoe+d0fUli810ckuXl6e7lczcbO7KDC4mm2Wl4OzKrUHVbojEJ/FPqj0B+F/ij0R6E/
|
||||
Cv1R6I9CfxT6o9Afhf4o9EehPwr9UeiPQn8U+qPQH4X+KPRHoT8K/VHoj0J/FPqj0B+F/ij0R6E/Cv1R
|
||||
6I9CfxT6o9Afhf4o9EehPwr9UeiPQn/tBw+afDL5P2s/6dvwG0kOU39pddZfW326+xT9t0y+9TBuvj3a
|
||||
5vhlxwAAAAAAAAAAAAAAAACSUBR/Aa2bGOTQ6k1jAAAAAElFTkSuQmCC
|
||||
</value>
|
||||
</data>
|
||||
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAABGdBTUEAALGPC/xhBQAAAG9QTFRF////
|
||||
AAAAWVlZ8fHx9PT0REREtLS0Ojo6+Pj4a2trp6enj4+P3t7eXl5efX1919fXh4eHw8PD6+vrdXV10dHR
|
||||
5ubmDAwMy8vLTU1NlZWVvLy8iIiINjY2nJycFhYWYWFhJycnUVFRHR0dr6+vKioqoesKnwAAAAlwSFlz
|
||||
AAAOvgAADr4B6kKxwAAAA2JJREFUeF7t3dtyolAQheHgIZqTicacMznO+z/jBFgoLRtwLqame9f/XUnj
|
||||
xV6W1UBTBScAAAAAAAAAAAAAAAAA8K/MtqfbqT5n6fytKIq3c21l6OInX+lC29m5VMCiuFYlNzfKVxQr
|
||||
VXIzUb6imKiSGxLGR8L4SBgfCeMjYXwkjI+E8ZEwPhLGR8L4SBgfCeMjYXwkjI+E8ZEwPhLGR8L4SBgf
|
||||
CeMjYXwkjI+E8ZEwPhLGR8L4SBgfCeMjYXwkjI+E8ZEwPhLGR8L4SBgfCeMjYXwkjI+E8ZEwPhK6d7ea
|
||||
LybP2kg5LuHzZDFf3WnDled68e/aTDgq4Xv9jaFf6j/ZParsTIWuYxKe6RvFpQp+6Lf/8UuVjiMS/tIX
|
||||
iuJKFT+0sNKDSofGEz5of0klN6ZaV6WnT4wmvNPuirsHSN5rYaXFUkVrLOFyod2lexX9WGlllXS3GUu4
|
||||
6zIlfw8enGlltSdVjZGET9pZm6nqyFZLq61VbRtOuNa+2lZVV861uFrieDaYcP/oz5LTh7jeanmV1263
|
||||
GUq4fNWuyq2q7rR7YSLFUMIr7aksVPRn2j5kFC+q7gwkfNGOyr3jZynbbnN49tyfUGft4rLLNAa7TW/C
|
||||
EF2mYQ78H/ag1pdw9qFyxf0zhh+10MqnirW+hJ+qVh5V9Gv6paVWblSt9CTcPyL6x1eAJ7Zfa621U1VL
|
||||
6YSnqtVCPOm7d8nJhP0/iGPmb/e2/9ulEg78qT0z3WauYjrhXJWK/y7TWP7Wkiu79p9IOHRwcc0ewr9V
|
||||
7Sb81nbN33htQPI0rJNw+CTPOXMqranSYUIzveqeqHuXuBw6TGgutvzNR8ckLmkPEo5dMLvXvWCwCUeH
|
||||
Hv7Z0dLDQcL2eDs9uArAjgc3JuFGn2rJ4WMEZsS7aDWfK9tl+m9XeWe7zU0roTl1jdhlGva/2Gejb4dk
|
||||
+0la3824IPa3PPv03lCNwhzXE9yOt49numaH3/H28ez59aEAg6dxQ90meJdp2DPQtmzehGhmFS0ZvULP
|
||||
zJt29jOq+NLdJosu07ATmZrrm2h/z07VSs0ELhuH3SbDF3XabpNTl2nMyncBN94CjbeP177LlOnrcvfd
|
||||
Jrsu02i6TYZdplG/tjrbl1aXNuundeixDAAAAAAAAAAAAAAAAADPTk7+AFMOGOSa0d0UAAAAAElFTkSu
|
||||
QmCC
|
||||
</value>
|
||||
</data>
|
||||
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAABGdBTUEAALGPC/xhBQAAAG9QTFRF////
|
||||
AAAAWVlZ8fHx9PT0REREtLS0Ojo6+Pj4a2trp6enj4+P3t7eXl5efX1919fXh4eHw8PD6+vrdXV10dHR
|
||||
5ubmDAwMy8vLTU1NlZWVvLy8iIiINjY2nJycFhYWYWFhJycnUVFRHR0dr6+vKioqoesKnwAAAAlwSFlz
|
||||
AAAOvgAADr4B6kKxwAAAAkFJREFUeF7t3GtT2zAQhWErF5JAnIQQSrmFW///b+wCR6LY/Vg3nqP3+cJE
|
||||
O5Nhh1kjrSQ3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAACMyVQ/Tc02P1J6WuuToUP6dKfPds6VYErXGjFz
|
||||
pfTCRkNWpgtl926uQSeHeMR8WWjUyFcJfpho2MdGmWVuD9PpTyWWPSngYvuqxLKVAi7OlFfxqICLnfIq
|
||||
bhQwseyW4MJsOrP+pcSy1VIRE3fKq7hVwMW98iouFTCxbJVX9mC2Llw/KLFsYlaCl8qruFfAxa3yKsxm
|
||||
osuV8sqezUpw3y3Bl5kiJm6UV7FTwMWj8irOFHDxR7/pw3GrgIlv/aZ3c7Med68E3dqGnX5TSm8KuOj2
|
||||
m9JBARPTufLKFmYlmHddiisFXLwpr+JcARe9EjTrN816JbhXxMT2qMQyt4lorwRT207+v91gK7ReCZ7M
|
||||
hX6jf+xCXz8Ggzy/9/ryUTgOsdLudZxOaohpYq/ldFJDLLb9/4bjqsNB5vr2z9IK/h+OZk6zGbDlZT8v
|
||||
rWBtEdzXh8F+jV9Bn6aCXltw75cG+553BfsWFew9he7+4avZ/mGw3wOuYB+/grMYFZynCe5nooL9uba/
|
||||
nE1szc4mVnC+NLifEQ7257yjGJ+VWuZ2Vr9pZu73LYL7nZlgf++pgrtrFdw/DN0eleGFfPt7wBXc5e70
|
||||
qBzv4wf3dyoE+/diVPBuE72fpvVbJ37j1wMHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFSiaX4DkC8Y5EW8
|
||||
SJQAAAAASUVORK5CYII=
|
||||
</value>
|
||||
</data>
|
||||
</root>
|
35
ContainerShip/ContainerShip/IMoveableObject.cs
Normal file
35
ContainerShip/ContainerShip/IMoveableObject.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static ProjectContainerShip.Direction;
|
||||
|
||||
namespace ProjectContainerShip.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);
|
||||
}
|
||||
}
|
60
ContainerShip/ContainerShip/MoveToBorder.cs
Normal file
60
ContainerShip/ContainerShip/MoveToBorder.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectContainerShip.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
62
ContainerShip/ContainerShip/MoveToCenter.cs
Normal file
62
ContainerShip/ContainerShip/MoveToCenter.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectContainerShip.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
65
ContainerShip/ContainerShip/ObjectParametrs.cs
Normal file
65
ContainerShip/ContainerShip/ObjectParametrs.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectContainerShip.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;
|
||||
}
|
||||
}
|
||||
}
|
138
ContainerShip/ContainerShip/OutputForm.Designer.cs
generated
138
ContainerShip/ContainerShip/OutputForm.Designer.cs
generated
@ -1,138 +0,0 @@
|
||||
namespace ProjectContainerShip
|
||||
{
|
||||
partial class OutputForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxContainerShip = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxContainerShip).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxContainerShip
|
||||
//
|
||||
pictureBoxContainerShip.Dock = DockStyle.Fill;
|
||||
pictureBoxContainerShip.Location = new Point(0, 0);
|
||||
pictureBoxContainerShip.Name = "pictureBoxContainerShip";
|
||||
pictureBoxContainerShip.Size = new Size(882, 453);
|
||||
pictureBoxContainerShip.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxContainerShip.TabIndex = 0;
|
||||
pictureBoxContainerShip.TabStop = false;
|
||||
pictureBoxContainerShip.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 412);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(94, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = ContainerShip.Properties.Resources.keyboard_left_arrow_button_icon_icons_com_72692;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(768, 412);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 2;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = ContainerShip.Properties.Resources.angle_arrow_down_icon_icons_com_73683;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(804, 411);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 3;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = ContainerShip.Properties.Resources.keyboard_right_arrow_button_1_icon_icons_com_72690;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(840, 412);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 4;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = ContainerShip.Properties.Resources.up_arrow_icon_icons_com_73351;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(804, 375);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 5;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
//
|
||||
// OutputForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxContainerShip);
|
||||
Name = "OutputForm";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "ContainerShip";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxContainerShip).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxContainerShip;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
namespace ProjectContainerShip
|
||||
{
|
||||
public partial class OutputForm : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawningContainerShip? _drawningContainerShip;
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
/// </summary>
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè êîíòåéíåðîâîçà
|
||||
/// </summary>
|
||||
public OutputForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningContainerShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxContainerShip.Width,
|
||||
pictureBoxContainerShip.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningContainerShip.DrawTransport(gr);
|
||||
pictureBoxContainerShip.Image = bmp;
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningContainerShip = new DrawningContainerShip();
|
||||
_drawningContainerShip.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)),
|
||||
pictureBoxContainerShip.Width, pictureBoxContainerShip.Height);
|
||||
_drawningContainerShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningContainerShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningContainerShip.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningContainerShip.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningContainerShip.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningContainerShip.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -1,3 +1,5 @@
|
||||
using ProjectWarmlyShip;
|
||||
|
||||
namespace ProjectContainerShip
|
||||
{
|
||||
internal static class Program
|
||||
@ -11,8 +13,8 @@ namespace ProjectContainerShip
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new OutputForm());
|
||||
Application.Run(new FormContainerShip());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
13
ContainerShip/ContainerShip/Status.cs
Normal file
13
ContainerShip/ContainerShip/Status.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectContainerShip.MovementStrategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit,InProgress, Finish
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user