lab2_90%
This commit is contained in:
parent
eedea31350
commit
6a6d84cd58
@ -3,11 +3,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using static DumpTruck.DrawningDumpTruck;
|
|
||||||
|
|
||||||
namespace DumpTruck.MovementStrategy
|
namespace DumpTruck.MovementStrategy
|
||||||
{
|
{
|
||||||
internal class AbstractStrategy
|
abstract class AbstractStrategy
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -104,12 +103,12 @@ namespace DumpTruck.MovementStrategy
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перемещение к цели
|
/// Перемещение к цели
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// protected abstract void MoveToTarget();
|
protected abstract void MoveToTarget();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Достигнута ли цель
|
/// Достигнута ли цель
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
// protected abstract bool IsTargetDestinaion();
|
protected abstract bool IsTargetDestinaion();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Попытка перемещения в требуемом направлении
|
/// Попытка перемещения в требуемом направлении
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -3,39 +3,12 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DumpTruck.Entities;
|
||||||
|
|
||||||
namespace DumpTruck
|
namespace DumpTruck.DrawningObjects
|
||||||
{
|
{
|
||||||
internal class DrawningDumpTruck
|
internal class DrawningDumpTruck : DrawningTruck
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Класс-сущность
|
|
||||||
/// </summary>
|
|
||||||
public DumpTruck? DumpTruck { 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 _DumpTruckWidth = 110;
|
|
||||||
/// <summary>
|
|
||||||
/// Высота прорисовки автомобиля
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _DumpTruckHeight = 85;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -46,102 +19,24 @@ namespace DumpTruck
|
|||||||
/// <param name="width">Ширина картинки</param>
|
/// <param name="width">Ширина картинки</param>
|
||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
/// <returns>true - объект создан, false - проверка не пройдена,
|
/// <returns>true - объект создан, false - проверка не пройдена,
|
||||||
public bool Init(int speed, double weight, Color bodyColor, Color
|
public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color
|
||||||
additionalColor, bool body, bool trailer, int width, int height)
|
additionalColor, bool trailer, int width, int height) : base (speed, weight, bodyColor, additionalColor, width, height,100, 55)
|
||||||
{
|
{
|
||||||
if ((height < _DumpTruckHeight) || (width < _DumpTruckWidth))
|
if (EntityTruck != null)
|
||||||
{
|
{
|
||||||
return false;
|
EntityTruck = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, trailer);
|
||||||
}
|
|
||||||
_pictureWidth = width;
|
|
||||||
_pictureHeight = height;
|
|
||||||
DumpTruck = new DumpTruck();
|
|
||||||
DumpTruck.Init(speed, weight, bodyColor, additionalColor,
|
|
||||||
body, trailer);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Установка позиции
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">Координата X</param>
|
|
||||||
/// <param name="y">Координата Y</param>
|
|
||||||
public void SetPosition(int x, int y)
|
|
||||||
{
|
|
||||||
if ((x < 0 || y < 0) || (x + _DumpTruckWidth > _pictureWidth || y + _DumpTruckHeight > _pictureHeight))
|
|
||||||
{
|
|
||||||
_startPosX = 0;
|
|
||||||
_startPosY = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Изменение направления перемещения
|
public override void DrawTransport(Graphics g)
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction">Направление</param>
|
|
||||||
public void MoveTransport(DirectionType direction)
|
|
||||||
{
|
{
|
||||||
if (DumpTruck == null)
|
if (EntityTruck is not EntityDumpTruck dumpTruck
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (direction)
|
base.DrawTransport(g);
|
||||||
{
|
if (dumpTruck.Trailer)
|
||||||
//влево
|
|
||||||
case DirectionType.Left:
|
|
||||||
if (_startPosX - DumpTruck.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosX -= (int)DumpTruck.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вверх
|
|
||||||
case DirectionType.Up:
|
|
||||||
if (_startPosY - DumpTruck.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosY -= (int)DumpTruck.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
// вправо
|
|
||||||
case DirectionType.Right:
|
|
||||||
if (_startPosX + _DumpTruckWidth + DumpTruck.Step < _pictureWidth)
|
|
||||||
{
|
|
||||||
_startPosX += (int)DumpTruck.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вниз
|
|
||||||
case DirectionType.Down:
|
|
||||||
if (_startPosY + _DumpTruckHeight + DumpTruck.Step < _pictureHeight)
|
|
||||||
{
|
|
||||||
_startPosY += (int)DumpTruck.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if (DumpTruck == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Pen pen = new(Color.Black);
|
|
||||||
Brush additionalBrush = new SolidBrush(DumpTruck.AdditionalColor);
|
|
||||||
//грани
|
|
||||||
g.DrawRectangle(pen, _startPosX + 80, _startPosY, 30, 40);
|
|
||||||
g.DrawRectangle(pen, _startPosX, _startPosY + 40, 110, 20);
|
|
||||||
//кузов
|
|
||||||
Brush br = new SolidBrush(DumpTruck.BodyColor);
|
|
||||||
g.FillRectangle(br, _startPosX + 81, _startPosY + 1, 29, 40);
|
|
||||||
Brush br1 = new SolidBrush(DumpTruck.AdditionalColor);
|
|
||||||
g.FillRectangle(br1, _startPosX + 1, _startPosY + 41, 109, 19);
|
|
||||||
//колеса
|
|
||||||
Brush wheels = new SolidBrush(Color.Black);
|
|
||||||
g.FillEllipse(wheels, _startPosX, _startPosY + 63, 25, 25);
|
|
||||||
g.FillEllipse(wheels, _startPosX + 25, _startPosY + 63, 25, 25);
|
|
||||||
g.FillEllipse(wheels, _startPosX + 85, _startPosY + 63, 25, 25);
|
|
||||||
if (DumpTruck.Trailer)
|
|
||||||
{
|
{
|
||||||
//прицеп
|
//прицеп
|
||||||
Brush trailer = new SolidBrush(Color.Black);
|
Brush trailer = new SolidBrush(Color.Black);
|
||||||
|
36
DumpTruck/DumpTruck/DrawningObjectTruck.cs
Normal file
36
DumpTruck/DumpTruck/DrawningObjectTruck.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DumpTruck.DrawningObjects;
|
||||||
|
|
||||||
|
|
||||||
|
namespace DumpTruck.MovementStrategy
|
||||||
|
{
|
||||||
|
internal class DrawningObjectTruck : IMoveableObject
|
||||||
|
|
||||||
|
{
|
||||||
|
private readonly DrawningTruck? _drawningTruck = null;
|
||||||
|
public DrawningObjectTruck(DrawningTruck drawningTruck)
|
||||||
|
{
|
||||||
|
_drawningTruck = drawningTruck;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningTruck == null || _drawningTruck.EntityTruck == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawningTruck.GetPosX, _drawningTruck.GetPosY, _drawningTruck.GetWidth, _drawningTruck.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningTruck?.EntityTruck?.Step ?? 0);
|
||||||
|
|
||||||
|
public bool CheckCanMove(DirectionType direction) => _drawningTruck?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(DirectionType direction) => _drawningTruck?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,7 @@ namespace DumpTruck.DrawningObjects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Truck? Truck { get; protected set; }
|
public EntityTruck? EntityTruck { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -40,6 +40,23 @@ namespace DumpTruck.DrawningObjects
|
|||||||
/// Высота прорисовки автомобиля
|
/// Высота прорисовки автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly int _truckHeight = 55;
|
protected readonly int _truckHeight = 55;
|
||||||
|
/// <summary>
|
||||||
|
/// Координата X объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
/// <summary>
|
||||||
|
/// Координата Y объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetWidth => _truckWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetHeight => _truckHeight;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -53,7 +70,7 @@ namespace DumpTruck.DrawningObjects
|
|||||||
// TODO: Продумать проверки
|
// TODO: Продумать проверки
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
Truck = new Truck(speed, weight, bodyColor, additionalColor);
|
EntityTruck = new EntityTruck(speed, weight, bodyColor, additionalColor);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
@ -72,7 +89,7 @@ namespace DumpTruck.DrawningObjects
|
|||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
_truckWidth = truckWidth;
|
_truckWidth = truckWidth;
|
||||||
_truckHeight = truckHeight;
|
_truckHeight = truckHeight;
|
||||||
Truck = new Truck(speed, weight, bodyColor, additionalColor);
|
EntityTruck = new EntityTruck(speed, weight, bodyColor, additionalColor);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции
|
/// Установка позиции
|
||||||
@ -81,17 +98,49 @@ namespace DumpTruck.DrawningObjects
|
|||||||
/// <param name="y">Координата Y</param>
|
/// <param name="y">Координата Y</param>
|
||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
// TODO: Изменение x, y, если при установке объект выходит за границы
|
if (x < 0 || x + _truckWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
x = Math.Max(0, _pictureWidth - _truckWidth);
|
||||||
|
}
|
||||||
|
if (y < 0 || y + _truckHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
y = Math.Max(0, _pictureHeight - _truckHeight);
|
||||||
|
}
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка, что объект может переместится по указанному направлению
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||||
|
public bool CanMove(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityTruck == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
DirectionType.Left => _startPosX - EntityTruck.Step > 0,
|
||||||
|
//вверх
|
||||||
|
DirectionType.Up => _startPosY - EntityTruck.Step > 0,
|
||||||
|
// вправо
|
||||||
|
DirectionType.Right => _startPosX + _truckWidth + EntityTruck.Step < _pictureWidth,
|
||||||
|
//вниз
|
||||||
|
DirectionType.Down => _startPosY + _truckHeight + EntityTruck.Step < _pictureHeight,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Изменение направления перемещения
|
/// Изменение направления перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="direction">Направление</param>
|
/// <param name="direction">Направление</param>
|
||||||
public void MoveTransport(DirectionType direction)
|
public void MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (Truck == null)
|
if (!CanMove(direction) || EntityTruck == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -99,37 +148,37 @@ namespace DumpTruck.DrawningObjects
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX - Truck.Step > 0)
|
if (_startPosX - EntityTruck.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)Truck.Step;
|
_startPosX -= (int)EntityTruck.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY - Truck.Step > 0)
|
if (_startPosY - EntityTruck.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)Truck.Step;
|
_startPosY -= (int)EntityTruck.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX + _truckWidth + Truck.Step < _pictureWidth)
|
if (_startPosX + _truckWidth + EntityTruck.Step < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)Truck.Step;
|
_startPosX += (int)EntityTruck.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY + _truckHeight + Truck.Step < _pictureHeight)
|
if (_startPosY + _truckHeight + EntityTruck.Step < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)Truck.Step;
|
_startPosY += (int)EntityTruck.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public virtual void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (Truck == null)
|
if (EntityTruck == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -138,9 +187,9 @@ namespace DumpTruck.DrawningObjects
|
|||||||
g.DrawRectangle(pen, _startPosX + 80, _startPosY, 30, 40);
|
g.DrawRectangle(pen, _startPosX + 80, _startPosY, 30, 40);
|
||||||
g.DrawRectangle(pen, _startPosX, _startPosY + 40, 110, 20);
|
g.DrawRectangle(pen, _startPosX, _startPosY + 40, 110, 20);
|
||||||
//кузов
|
//кузов
|
||||||
Brush br = new SolidBrush(Truck.BodyColor);
|
Brush br = new SolidBrush(EntityTruck.BodyColor);
|
||||||
g.FillRectangle(br, _startPosX + 81, _startPosY + 1, 29, 40);
|
g.FillRectangle(br, _startPosX + 81, _startPosY + 1, 29, 40);
|
||||||
Brush br1 = new SolidBrush(Truck.AdditionalColor);
|
Brush br1 = new SolidBrush(EntityTruck.AdditionalColor);
|
||||||
g.FillRectangle(br1, _startPosX + 1, _startPosY + 41, 109, 19);
|
g.FillRectangle(br1, _startPosX + 1, _startPosY + 41, 109, 19);
|
||||||
//колеса
|
//колеса
|
||||||
Brush wheels = new SolidBrush(Color.Black);
|
Brush wheels = new SolidBrush(Color.Black);
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DumpTruck
|
|
||||||
{
|
|
||||||
internal class DumpTruck
|
|
||||||
{
|
|
||||||
/// <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 Body { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак (опция) наличия антикрыла
|
|
||||||
/// </summary>
|
|
||||||
public bool Trailer { 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>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
|
||||||
additionalColor, bool body, bool trailer)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
Body = body;
|
|
||||||
Trailer = trailer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
28
DumpTruck/DumpTruck/EntityDumpTruck.cs
Normal file
28
DumpTruck/DumpTruck/EntityDumpTruck.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DumpTruck.Entities
|
||||||
|
{
|
||||||
|
public class EntityDumpTruck : EntityTruck
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличия антикрыла
|
||||||
|
/// </summary>
|
||||||
|
public bool Trailer { get; private set; }
|
||||||
|
|
||||||
|
/// Инициализация полей объекта-класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
public EntityDumpTruck(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool trailer) : base (speed,weight, bodyColor,additionalColor)
|
||||||
|
{
|
||||||
|
Trailer = trailer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,7 @@ namespace DumpTruck.Entities
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Автомобиль"
|
/// Класс-сущность "Автомобиль"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Truck
|
public class EntityTruck
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Скорость
|
/// Скорость
|
||||||
@ -36,7 +36,7 @@ namespace DumpTruck.Entities
|
|||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес автомобиля</param>
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
public Truck(int speed, double weight, Color bodyColor, Color additionalColor)
|
public EntityTruck(int speed, double weight, Color bodyColor,Color additionalColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
13
DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
generated
13
DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
generated
@ -29,7 +29,6 @@
|
|||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDumpTruck));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDumpTruck));
|
||||||
this.pictureBoxDumpTruck = new System.Windows.Forms.PictureBox();
|
this.pictureBoxDumpTruck = new System.Windows.Forms.PictureBox();
|
||||||
this.Button_Create = new System.Windows.Forms.Button();
|
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
@ -46,16 +45,6 @@
|
|||||||
this.pictureBoxDumpTruck.TabIndex = 0;
|
this.pictureBoxDumpTruck.TabIndex = 0;
|
||||||
this.pictureBoxDumpTruck.TabStop = false;
|
this.pictureBoxDumpTruck.TabStop = false;
|
||||||
//
|
//
|
||||||
// Button_Create
|
|
||||||
//
|
|
||||||
this.Button_Create.Location = new System.Drawing.Point(30, 407);
|
|
||||||
this.Button_Create.Name = "Button_Create";
|
|
||||||
this.Button_Create.Size = new System.Drawing.Size(75, 23);
|
|
||||||
this.Button_Create.TabIndex = 1;
|
|
||||||
this.Button_Create.Text = "Создать";
|
|
||||||
this.Button_Create.UseVisualStyleBackColor = true;
|
|
||||||
this.Button_Create.Click += new System.EventHandler(this.Button_Create_Click);
|
|
||||||
//
|
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
|
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
|
||||||
@ -114,7 +103,6 @@
|
|||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
this.Controls.Add(this.Button_Create);
|
|
||||||
this.Controls.Add(this.pictureBoxDumpTruck);
|
this.Controls.Add(this.pictureBoxDumpTruck);
|
||||||
this.Name = "FormDumpTruck";
|
this.Name = "FormDumpTruck";
|
||||||
this.Text = "FormDumpTruck";
|
this.Text = "FormDumpTruck";
|
||||||
@ -126,7 +114,6 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxDumpTruck;
|
private PictureBox pictureBoxDumpTruck;
|
||||||
private Button Button_Create;
|
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
@ -7,6 +7,9 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using DumpTruck.DrawningObjects;
|
||||||
|
using DumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
namespace DumpTruck
|
namespace DumpTruck
|
||||||
{
|
{
|
||||||
@ -35,16 +38,9 @@ namespace DumpTruck
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void Button_Create_Click(object sender, EventArgs e)
|
private void Butt1on_Create_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
|
||||||
_drawningDumpTruck = new DrawningDumpTruck();
|
|
||||||
_drawningDumpTruck.Init(130, 1000,
|
|
||||||
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)), true,
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
|
|
||||||
_drawningDumpTruck.SetPosition(random.Next(30, 100), random.Next(30, 100));
|
|
||||||
Draw();
|
|
||||||
}
|
}
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
||||||
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOwAAADsABataJCQAAGRlJREFUeNrt3Vt26jy2huHg
|
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOvgAADr4B6kKxwAAAGRlJREFUeNrt3Vt26jy2huHg
|
||||||
dCDC1QCTsu+jobUaALQgofrflkIHOySLEA4+aE69vvH49kX9yM/WXIEpyU/pql7jRZQaeRziI49DfORx
|
dCDC1QCTsu+jobUaALQgofrflkIHOySLEA4+aE69vvH49kX9yM/WXIEpyU/pql7jRZQaeRziI49DfORx
|
||||||
iI88DvGRxyE+8jjERx6H+MjjEB95HOIjj0N85HGIjzwO8ZHHIT7yOATHdG/S/50oLvI4xEfVI6z+10Ao
|
iI88DvGRxyE+8jjERx6H+MjjEB95HOIjj0N85HGIjzwO8ZHHIT7yOATHdG/S/50oLvI4xEfVI6z+10Ao
|
||||||
Ozb1B4SyY2teGgglx+q9/gOh6FgZaz8glBxbU7s1hILjsY66YyXVO8AntUPq47GOumMl1TvAJ7VD6mNn
|
Ozb1B4SyY2teGgglx+q9/gOh6FgZaz8glBxbU7s1hILjsY66YyXVO8AntUPq47GOumMl1TvAJ7VD6mNn
|
||||||
@ -175,7 +175,7 @@
|
|||||||
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
||||||
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOvgAADr4B6kKxwAAAFy1JREFUeNrtnV2S6ka2RkFB
|
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOvAAADrwBlbxySQAAFy1JREFUeNrtnV2S6ka2RkFB
|
||||||
v7ese98VCmkA6hwBlzsB4tjzn0qTPxLC5lBCKH++qsVDVy932yf5VmxD1lbmPnT+1R78C5RD4pBH4pBH
|
v7ese98VCmkA6hwBlzsB4tjzn0qTPxLC5lBCKH++qsVDVy932yf5VmxD1lbmPnT+1R78C5RD4pBH4pBH
|
||||||
4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pDH6VWFvw6qInHII3HII3HII3HII3HII3HI
|
4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pDH6VWFvw6qInHII3HII3HII3HII3HII3HI
|
||||||
I3HII3HII3HII3HII3HII3HII3HII3EIY/hJ700WiUMeiUMeiUMeiUMeiUMeiUMeiUMeiUMeiUMeiUMe
|
I3HII3HII3HII3HII3HII3HII3HII3EIY/hJ700WiUMeiUMeiUMeiUMeiUMeiUMeiUMeiUMeiUMeiUMe
|
||||||
@ -280,7 +280,7 @@
|
|||||||
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
||||||
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOwAAADsABataJCQAAFlpJREFUeNrtndFy47h2RT36
|
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOvgAADr4B6kKxwAAAFlpJREFUeNrtndFy47h2RT36
|
||||||
ArNov8tKfgAF3XdHlfueuCr//ysRQJCy3W7LkkUSC1p80aypm+45e+W0dRoE8LAbnu3D8Ig4NA48Ggce
|
ArNov8tKfgAF3XdHlfueuCr//ysRQJCy3W7LkkUSC1p80aypm+45e+W0dRoE8LAbnu3D8Ig4NA48Ggce
|
||||||
jQOPxoFH48CjceDROPBoHHg0DjwaBx6NA4/GgUfjwKNx4HF8NuXfi1Q0DjwaBx6NA4/GgUfjwKNx4NE4
|
jQOPxoFH48CjceDROPBoHHg0DjwaBx6NA4/GgUfjwKNx4HF8NuXfi1Q0DjwaBx6NA4/GgUfjwKNx4NE4
|
||||||
8GgceDQOPBoHHo0Dj8aBR+PAo3GAsXy69oZF48CjceDROPBoHHg0DjwaBx6NA4/GgUfjwKNx4NE48Ggc
|
8GgceDQOPBoHHo0Dj8aBR+PAo3GAsXy69oZF48CjceDROPBoHHg0DjwaBx6NA4/GgUfjwKNx4NE48Ggc
|
||||||
@ -382,7 +382,7 @@
|
|||||||
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
||||||
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOwAAADsABataJCQAAGBNJREFUeNrt3V9y+r7Vx3Fj
|
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOvgAADr4B6kKxwAAAGBNJREFUeNrt3V9y+r7Vx3Fj
|
||||||
NoARuTeacB9VYQGPM92A2f9eimTZSb5PSAD/05Hens7QTy/6i/WqjqFHkotwlbq7oosf1fWy3WWq7lo+
|
NoARuTeacB9VYQGPM92A2f9eimTZSb5PSAD/05Hens7QTy/6i/WqjqFHkotwlbq7oosf1fWy3WWq7lo+
|
||||||
WvsW4+B8jRBCmDahglA6oYUQQgghhBBCCCGEEEIIIRwT+V0IIYQQQjg2KgilE1bqJV7C8FmH/zy2WH5c
|
WvsW4+B8jRBCmDahglA6oYUQQgghhBBCCCGEEEIIIRwT+V0IIYQQQjg2KgilE1bqJV7C8FmH/zy2WH5c
|
||||||
i5gNI6rCkK4Qq5e6iHSsIIQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGE8K+oIJROaM/xEoaLfuGvka49
|
i5gNI6rCkK4Qq5e6iHSsIIQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGE8K+oIJROaM/xEoaLfuGvka49
|
||||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using static DumpTruck.DrawningDumpTruck;
|
|
||||||
|
|
||||||
|
|
||||||
namespace DumpTruck.MovementStrategy
|
namespace DumpTruck.MovementStrategy
|
||||||
|
58
DumpTruck/DumpTruck/MoveToBorder.cs
Normal file
58
DumpTruck/DumpTruck/MoveToBorder.cs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DumpTruck.MovementStrategy
|
||||||
|
{
|
||||||
|
internal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
DumpTruck/DumpTruck/MoveToCenter.cs
Normal file
54
DumpTruck/DumpTruck/MoveToCenter.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DumpTruck.MovementStrategy
|
||||||
|
{
|
||||||
|
internal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user