готово
This commit is contained in:
parent
8c8bb2c79d
commit
5a1e792e5b
@ -1,196 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
||||
{
|
||||
internal class DrawningDoubleDeckerBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityDoubleDeckerBus? EntityDoubleDeckerBus { 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 _busWidth = 110;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки автобуса
|
||||
/// </summary>
|
||||
private readonly int _busHeight = 70;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="secondFloor">Признак наличия второго этажа</param>
|
||||
/// <param name="ladder">Признак наличия лестницы на второй этаж</param>
|
||||
/// <param name="roadLine">Признак наличия дорожной полосы</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 secondFloor, bool ladder, bool roadLine, int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureHeight < _busHeight || _pictureWidth < _busWidth)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
EntityDoubleDeckerBus = new EntityDoubleDeckerBus();
|
||||
EntityDoubleDeckerBus.Init(speed, weight, bodyColor, additionalColor,
|
||||
secondFloor, ladder, roadLine);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
_startPosX = Math.Min(x, _pictureWidth - _busWidth);
|
||||
_startPosY = Math.Min(y, _pictureHeight - _busHeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityDoubleDeckerBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityDoubleDeckerBus.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityDoubleDeckerBus.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityDoubleDeckerBus.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityDoubleDeckerBus.Step;
|
||||
}
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + _busWidth + EntityDoubleDeckerBus.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityDoubleDeckerBus.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + _busHeight + EntityDoubleDeckerBus.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityDoubleDeckerBus.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityDoubleDeckerBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
// Границы первого этажа автобуса
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 30, 100, 30);
|
||||
Brush brBodyColor = new SolidBrush(EntityDoubleDeckerBus.BodyColor);
|
||||
g.FillRectangle(brBodyColor, _startPosX, _startPosY + 30, 100, 30);
|
||||
|
||||
// Дверь
|
||||
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 40, 10, 20);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 40, 10, 20);
|
||||
|
||||
// Колеса
|
||||
g.DrawEllipse(pen, _startPosX + 7, _startPosY + 55, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 77, _startPosY + 55, 10, 10);
|
||||
g.FillEllipse(brBlack, _startPosX + 7, _startPosY + 55, 10, 10);
|
||||
g.FillEllipse(brBlack, _startPosX + 77, _startPosY + 55, 10, 10);
|
||||
|
||||
// Окна
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 35, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 35, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 35, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 35, 10, 15);
|
||||
|
||||
if (EntityDoubleDeckerBus.SecondFloor)
|
||||
{
|
||||
// Границы второго этажа автобуса
|
||||
g.FillRectangle(brBodyColor, _startPosX, _startPosY, 100, 30);
|
||||
|
||||
// Дверь второго этажа
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 10, 10, 20);
|
||||
g.FillRectangle(brBlack, _startPosX, _startPosY + 10, 10, 20);
|
||||
|
||||
// Окна второго этажа
|
||||
g.FillEllipse(brBlue, _startPosX + 12, _startPosY + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 30, _startPosY + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 5, 10, 15);
|
||||
}
|
||||
|
||||
if (EntityDoubleDeckerBus.Ladder)
|
||||
{
|
||||
//Вертикальные прямые
|
||||
g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 55)), new Point((int)(_startPosX), (int)(_startPosY + 25)));
|
||||
g.DrawLine(pen, new Point((int)(_startPosX + 10), (int)(_startPosY + 55)), new Point((int)(_startPosX + 10), (int)(_startPosY + 25)));
|
||||
|
||||
//Горизонтальные прямые
|
||||
g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 35)), new Point((int)(_startPosX + 10), (int)(_startPosY + 35)));
|
||||
g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 45)), new Point((int)(_startPosX + 10), (int)(_startPosY + 45)));
|
||||
g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 55)), new Point((int)(_startPosX + 10), (int)(_startPosY + 55)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,227 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Entities;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBus? EntityBus { 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 _busWidth = 110;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки автобуса
|
||||
/// </summary>
|
||||
protected readonly int _busHeight = 70;
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _busWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _busHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawningBus(int speed, double weight, Color bodyColor, int
|
||||
width, int height)
|
||||
{
|
||||
if (width < _busWidth || height < _busHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityBus = new EntityBus(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="busWidth">Ширина прорисовки автобуса</param>
|
||||
/// <param name="busHeight">Высота прорисовки автобуса</param>
|
||||
protected DrawningBus(int speed, double weight, Color bodyColor, int
|
||||
width, int height, int busWidth, int busHeight)
|
||||
{
|
||||
if (width <= _busWidth || height <= _busHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_busWidth = busWidth;
|
||||
_busHeight = busHeight;
|
||||
EntityBus = new EntityBus(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 + _busWidth > _pictureWidth)
|
||||
{
|
||||
x = Math.Max(0, _pictureWidth - _busWidth);
|
||||
}
|
||||
if (y < 0 || y + _busHeight > _pictureHeight)
|
||||
{
|
||||
y = Math.Max(0, _pictureHeight - _busHeight);
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка, что объект может переместится по указанному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityBus == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityBus.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityBus.Step > 0,
|
||||
//вправо
|
||||
DirectionType.Right => _startPosX + _busWidth + EntityBus.Step < _pictureWidth,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + _busHeight + EntityBus.Step < _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
_startPosX -= (int)EntityBus.Step;
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
_startPosY -= (int)EntityBus.Step;
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
_startPosX += (int)EntityBus.Step;
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
_startPosY += (int)EntityBus.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
// Границы первого этажа автобуса
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 30, 100, 30);
|
||||
Brush brBodyColor = new SolidBrush(EntityBus.BodyColor);
|
||||
g.FillRectangle(brBodyColor, _startPosX, _startPosY + 30, 100, 30);
|
||||
|
||||
// Дверь
|
||||
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 40, 10, 20);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 40, 10, 20);
|
||||
|
||||
// Колеса
|
||||
g.DrawEllipse(pen, _startPosX + 7, _startPosY + 55, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 77, _startPosY + 55, 10, 10);
|
||||
g.FillEllipse(brBlack, _startPosX + 7, _startPosY + 55, 10, 10);
|
||||
g.FillEllipse(brBlack, _startPosX + 77, _startPosY + 55, 10, 10);
|
||||
|
||||
// Окна
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 35, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 35, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 35, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 35, 10, 15);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Entities;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningDoubleDeckerBus : DrawningBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="secondFloor">Признак наличия второго этажа</param>
|
||||
/// <param name="ladder">Признак наличия лестницы на второй этаж</param>
|
||||
/// <param name="lineBetweenFloor">Признак наличия полосы между этажами</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена,
|
||||
/// нельзя создать объект в этих размерах</returns>
|
||||
public DrawningDoubleDeckerBus(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool secondFloor, bool ladder, bool lineBetweenFloor, int width, int height) :
|
||||
base(speed, weight, bodyColor, width, height, 120, 85)
|
||||
{
|
||||
if (EntityBus != null)
|
||||
{
|
||||
EntityBus = new EntityDoubleDeckerBus(speed, weight, bodyColor,
|
||||
additionalColor, secondFloor, ladder, lineBetweenFloor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBus is not EntityDoubleDeckerBus doubleDeckerBus)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brAdditionalColor = new SolidBrush(doubleDeckerBus.AdditionalColor);
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
|
||||
// второй этаж
|
||||
if (doubleDeckerBus.SecondFloor)
|
||||
{
|
||||
// Границы второго этажа автобуса
|
||||
g.FillRectangle(brAdditionalColor, _startPosX, _startPosY, 100, 30);
|
||||
|
||||
// Дверь второго этажа
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 10, 10, 20);
|
||||
g.FillRectangle(brAdditionalColor, _startPosX, _startPosY + 10, 10, 20);
|
||||
|
||||
// Окна второго этажа
|
||||
g.FillEllipse(brBlue, _startPosX + 12, _startPosY + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 30, _startPosY + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 5, 10, 15);
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
// лестница на второй этаж
|
||||
if (doubleDeckerBus.Ladder)
|
||||
{
|
||||
if (doubleDeckerBus.SecondFloor == true)
|
||||
{
|
||||
//Вертикальные прямые
|
||||
g.DrawLine(pen, new Point(_startPosX, _startPosY + 55), new Point(_startPosX, _startPosY + 25));
|
||||
g.DrawLine(pen, new Point(_startPosX + 10, _startPosY + 55), new Point(_startPosX + 10, _startPosY + 25));
|
||||
|
||||
//Горизонтальные прямые
|
||||
g.DrawLine(pen, new Point(_startPosX, _startPosY + 35), new Point(_startPosX + 10, _startPosY + 35));
|
||||
g.DrawLine(pen, new Point(_startPosX, _startPosY + 45), new Point(_startPosX + 10, _startPosY + 45));
|
||||
g.DrawLine(pen, new Point(_startPosX, _startPosY + 55), new Point(_startPosX + 10, _startPosY + 55));
|
||||
}
|
||||
}
|
||||
|
||||
// полоса между этажами
|
||||
if (doubleDeckerBus.LineBetweenFloor)
|
||||
{
|
||||
g.FillRectangle(brBlack, _startPosX, _startPosY + 30, 100, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Автобус"
|
||||
/// </summary>
|
||||
public class EntityBus
|
||||
{
|
||||
/// <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 EntityBus(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,45 +4,35 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Entities
|
||||
{
|
||||
public class EntityDoubleDeckerBus
|
||||
/// <summary>
|
||||
/// Класс-сущность "Двухэтажный автобус"
|
||||
/// </summary>
|
||||
public class EntityDoubleDeckerBus : EntityBus
|
||||
{
|
||||
/// <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 Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия второго этажа
|
||||
/// </summary>
|
||||
public bool SecondFloor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия лестницы на второй этаж
|
||||
/// </summary>
|
||||
public bool Ladder { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool RoadLine { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения автобуса
|
||||
/// Признак (опция) наличия полосы между этажами
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
public bool LineBetweenFloor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// Инициализация полей объекта-класса двухэтажного автобуса
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автобуса</param>
|
||||
@ -50,18 +40,14 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="secondFloor">Признак наличия второго этажа</param>
|
||||
/// <param name="ladder">Признак наличия лестницы на второй этаж</param>
|
||||
/// <param name="roadLine">Признак наличия дорожной полосы</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool secondFloor, bool ladder, bool roadLine)
|
||||
/// <param name="lineBetweenFloor">Признак наличия полосы между этажами</param>
|
||||
public EntityDoubleDeckerBus(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool secondFloor, bool ladder, bool lineBetweenFloor) : base(speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
SecondFloor = secondFloor;
|
||||
Ladder = ladder;
|
||||
RoadLine = roadLine;
|
||||
LineBetweenFloor = lineBetweenFloor;
|
||||
}
|
||||
}
|
||||
}
|
@ -29,11 +29,14 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxDoubleDeckerBus = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonCreateDoubleDeckerBus = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
buttonCreateBus = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxDoubleDeckerBus).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -48,17 +51,6 @@
|
||||
pictureBoxDoubleDeckerBus.TabIndex = 0;
|
||||
pictureBoxDoubleDeckerBus.TabStop = false;
|
||||
//
|
||||
// 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;
|
||||
@ -69,7 +61,7 @@
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 2;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
@ -81,7 +73,7 @@
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 3;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
@ -93,7 +85,7 @@
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 4;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
@ -105,18 +97,63 @@
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateDoubleDeckerBus
|
||||
//
|
||||
buttonCreateDoubleDeckerBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateDoubleDeckerBus.Location = new Point(12, 389);
|
||||
buttonCreateDoubleDeckerBus.Name = "buttonCreateDoubleDeckerBus";
|
||||
buttonCreateDoubleDeckerBus.Size = new Size(167, 52);
|
||||
buttonCreateDoubleDeckerBus.TabIndex = 6;
|
||||
buttonCreateDoubleDeckerBus.Text = "Создать двухэтажный автобус";
|
||||
buttonCreateDoubleDeckerBus.UseVisualStyleBackColor = true;
|
||||
buttonCreateDoubleDeckerBus.Click += ButtonCreateDoubleDeckerBus_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(768, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(102, 28);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Location = new Point(804, 46);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(66, 26);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += ButtonStep_Click;
|
||||
//
|
||||
// buttonCreateBus
|
||||
//
|
||||
buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBus.Location = new Point(185, 389);
|
||||
buttonCreateBus.Name = "buttonCreateBus";
|
||||
buttonCreateBus.Size = new Size(167, 52);
|
||||
buttonCreateBus.TabIndex = 10;
|
||||
buttonCreateBus.Text = "Создать автобус";
|
||||
buttonCreateBus.UseVisualStyleBackColor = true;
|
||||
buttonCreateBus.Click += buttonCreateBus_Click;
|
||||
//
|
||||
// FormDoubleDeckerBus
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
Controls.Add(buttonCreateBus);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateDoubleDeckerBus);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxDoubleDeckerBus);
|
||||
Name = "FormDoubleDeckerBus";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
@ -129,10 +166,13 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxDoubleDeckerBus;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateDoubleDeckerBus;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonCreateBus;
|
||||
}
|
||||
}
|
@ -1,12 +1,19 @@
|
||||
using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.DrawningObjects;
|
||||
using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.MovementStrategy;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
||||
{
|
||||
public partial class FormDoubleDeckerBus : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Äâóõýòàæíûé àâòîáóñ"
|
||||
/// </summary>
|
||||
private DrawningBus? _drawningBus;
|
||||
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private DrawningDoubleDeckerBus? _drawningDoubleDeckerBus;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
@ -21,45 +28,57 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningDoubleDeckerBus == null)
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxDoubleDeckerBus.Width,
|
||||
pictureBoxDoubleDeckerBus.Height);
|
||||
Bitmap bmp = new(pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningDoubleDeckerBus.DrawTransport(gr);
|
||||
_drawningBus.DrawTransport(gr);
|
||||
pictureBoxDoubleDeckerBus.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü äâóõýòàæíûé àâòîáóñ"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
private void ButtonCreateDoubleDeckerBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningDoubleDeckerBus = new DrawningDoubleDeckerBus();
|
||||
_drawningDoubleDeckerBus.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)),
|
||||
_drawningBus = new DrawningDoubleDeckerBus(random.Next(100, 300),
|
||||
random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height);
|
||||
_drawningDoubleDeckerBus.SetPosition(random.Next(10, 100),
|
||||
random.Next(10, 100));
|
||||
_drawningBus.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)
|
||||
private void buttonCreateBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningDoubleDeckerBus == null)
|
||||
Random random = new();
|
||||
_drawningBus = new DrawningBus(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height);
|
||||
_drawningBus.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 (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -67,19 +86,61 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningDoubleDeckerBus.MoveTransport(DirectionType.Up);
|
||||
_drawningBus.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningDoubleDeckerBus.MoveTransport(DirectionType.Down);
|
||||
_drawningBus.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningDoubleDeckerBus.MoveTransport(DirectionType.Left);
|
||||
_drawningBus.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningDoubleDeckerBus.MoveTransport(DirectionType.Right);
|
||||
_drawningBus.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawningObjectBus(_drawningBus), pictureBoxDoubleDeckerBus.Width,
|
||||
pictureBoxDoubleDeckerBus.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.DrawningObjects;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningBus (паттерн Adapter)
|
||||
/// </summary>
|
||||
public class DrawningObjectBus : IMoveableObject
|
||||
{
|
||||
private readonly DrawningBus? _drawningBus = null;
|
||||
|
||||
public DrawningObjectBus(DrawningBus drawningBus)
|
||||
{
|
||||
_drawningBus = drawningBus;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningBus == null || _drawningBus.EntityBus == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningBus.GetPosX,
|
||||
_drawningBus.GetPosY, _drawningBus.GetWidth, _drawningBus.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_drawningBus?.EntityBus?.Step ?? 0);
|
||||
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawningBus?.CanMove(direction) ?? false;
|
||||
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawningBus?.MoveTransport(direction);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.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);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в правый нижний край экрана
|
||||
/// </summary>
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.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>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user