start
This commit is contained in:
parent
f08466a718
commit
1bacab8f18
@ -1,44 +1,20 @@
|
||||
using Cruiser;
|
||||
using DumpTruck.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
using Monorail.DrawningObjects;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
namespace Monorail.MovementStrategy
|
||||
{
|
||||
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)
|
||||
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
@ -50,9 +26,7 @@ namespace DumpTruck.MovementStrategy
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
@ -66,35 +40,18 @@ namespace DumpTruck.MovementStrategy
|
||||
}
|
||||
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>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
@ -103,20 +60,11 @@ namespace DumpTruck.MovementStrategy
|
||||
}
|
||||
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)
|
||||
@ -130,5 +78,7 @@ namespace DumpTruck.MovementStrategy
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,147 +1 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Cruiser.Generics;
|
||||
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.Entities;
|
||||
using DumpTruck.MovementStrategy;
|
||||
|
||||
namespace DumpTruck.Generics
|
||||
{
|
||||
internal class CarsGenericCollection<T, U>
|
||||
where T : DrawningCar
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public CarsGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(CarsGenericCollection<T, U> collect, T?
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(obj) ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(CarsGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowCars()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
DrawningCar car;
|
||||
int numPlacesInRow = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
// TODO получение объекта
|
||||
// TODO установка позиции
|
||||
// TODO прорисовка объекта
|
||||
car = _collection.Get(i);
|
||||
if (car != null)
|
||||
{
|
||||
car.SetPosition((i % numPlacesInRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / numPlacesInRow) + _placeSizeHeight / 10);
|
||||
//car.SetPosition(_placeSizeWidth * (i/ numPlacesInColumn) + _placeSizeWidth / 20, (i % numPlacesInColumn ) *_placeSizeHeight + _placeSizeHeight / 10);
|
||||
car.DrawTransport(g);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.Entities
|
||||
namespace Monorail.Entities
|
||||
{
|
||||
public class EntityCar
|
||||
public class EntityMonorail
|
||||
{
|
||||
/// <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 WheelColor { get; private set; }
|
||||
|
||||
public Color TireColor { get; private set; }
|
||||
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Конструктор с параметрами
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityCar(int speed, double weight, Color bodyColor)
|
||||
|
||||
|
||||
public EntityMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
WheelColor = wheelColor;
|
||||
TireColor = tireColor;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -4,27 +4,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Cruiser
|
||||
namespace Monorail
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
||||
/// Вверх
|
||||
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,204 +1,217 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using DumpTruck.Entities;
|
||||
using DumpTruck.MovementStrategy;
|
||||
using Cruiser;
|
||||
using Monorail.Entities;
|
||||
using Monorail.MovementStrategy;
|
||||
|
||||
|
||||
namespace DumpTruck.DrawningObjects
|
||||
namespace Monorail.DrawningObjects
|
||||
{
|
||||
public class DrawningCar
|
||||
public class DrawningMonorail
|
||||
{
|
||||
public EntityCar? EntityCar { get; protected set; }
|
||||
public EntityMonorail? EntityMonorail { get; protected set; }
|
||||
|
||||
public int GetPosX => _startPosX;
|
||||
|
||||
public int GetPosY => _startPosY;
|
||||
|
||||
public int GetWidth => _monoRailWidth;
|
||||
|
||||
public int GetHeight => _monoRailHeight;
|
||||
|
||||
private int _pictureWidth;
|
||||
|
||||
private int _pictureHeight;
|
||||
|
||||
protected int _startPosX;
|
||||
protected int _startPosX = 0;
|
||||
|
||||
protected int _startPosY;
|
||||
protected int _startPosY = 0;
|
||||
|
||||
private readonly int _carWidth = 110;
|
||||
protected int _monoRailWidth = 133;
|
||||
|
||||
private readonly int _carHeight = 60;
|
||||
protected int _monoRailHeight = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _carWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _carHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectCar(this);
|
||||
|
||||
public DrawningCar(int speed, double weight, Color bodyColor, int width, int height)
|
||||
protected int wheelSz;
|
||||
public DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int width, int height)
|
||||
{
|
||||
if (width < _carWidth || height < _carHeight)
|
||||
{
|
||||
if (width <= _monoRailWidth || height <= _monoRailHeight)
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
|
||||
EntityCar = new EntityCar(speed, weight, bodyColor);
|
||||
|
||||
|
||||
|
||||
wheelSz = _monoRailHeight - _monoRailHeight * 7 / 10;
|
||||
EntityMonorail = new EntityMonorail(speed, weight, bodyColor, wheelColor, tireColor);
|
||||
}
|
||||
|
||||
protected DrawningCar(int speed, double weight, Color bodyColor, int
|
||||
width, int height, int carWidth, int carHeight)
|
||||
protected DrawningMonorail(int speed, double weight, Color bodyColor, int width, int height, Color wheelColor, Color tireColor, int monoRailWidth, int monoRailHeight)
|
||||
{
|
||||
if (width <= _carWidth || height <= _carHeight)
|
||||
{
|
||||
if (width <= _monoRailWidth || height <= _monoRailHeight)
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_carWidth = carWidth;
|
||||
_carHeight = carHeight;
|
||||
EntityCar = new EntityCar(speed, weight, bodyColor);
|
||||
_monoRailHeight = monoRailHeight;
|
||||
_monoRailWidth = monoRailWidth;
|
||||
wheelSz = _monoRailHeight - _monoRailHeight * 7 / 10;
|
||||
EntityMonorail = new EntityMonorail(speed, weight, bodyColor, wheelColor, tireColor);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x >= _pictureWidth || y < 0 || y >= _pictureHeight)
|
||||
{
|
||||
_startPosX = 0;
|
||||
_startPosY = 0;
|
||||
}
|
||||
if (EntityMonorail == null)
|
||||
return;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityCar == null)
|
||||
if (x + _monoRailWidth >= _pictureWidth || y + _monoRailHeight >= _pictureHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
_startPosX -= (int)EntityCar.Step;
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
_startPosY -= (int)EntityCar.Step;
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
_startPosX += (int)EntityCar.Step;
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
_startPosY += (int)EntityCar.Step;
|
||||
break;
|
||||
_startPosX = 1;
|
||||
_startPosY = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public IMoveableObject GetMoveableObject => new
|
||||
DrawningObjectMonorail(this);
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityCar == null)
|
||||
{
|
||||
if (EntityMonorail == null)
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityCar.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityCar.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + EntityCar.Step + _carWidth < _pictureWidth,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + EntityCar.Step + _carHeight < _pictureHeight,
|
||||
_ => false,
|
||||
DirectionType.Left => _startPosX - EntityMonorail.Step > 0,
|
||||
DirectionType.Up => _startPosY - EntityMonorail.Step > 0,
|
||||
DirectionType.Right => _startPosX + EntityMonorail.Step < _pictureWidth,
|
||||
DirectionType.Down => _startPosY - +EntityMonorail.Step < _pictureHeight
|
||||
};
|
||||
}
|
||||
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityMonorail == null)
|
||||
return;
|
||||
switch (direction)
|
||||
{
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityMonorail.Step >= 0)
|
||||
_startPosX -= (int)EntityMonorail.Step;
|
||||
break;
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityMonorail.Step >= 0)
|
||||
_startPosY -= (int)EntityMonorail.Step;
|
||||
break;
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntityMonorail.Step + _monoRailWidth < _pictureWidth)
|
||||
_startPosX += (int)EntityMonorail.Step;
|
||||
break;
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntityMonorail.Step + _monoRailHeight < _pictureHeight)
|
||||
_startPosY += (int)EntityMonorail.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCar == null)
|
||||
{
|
||||
if (EntityMonorail == null)
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush brush = new SolidBrush(EntityCar.BodyColor);
|
||||
|
||||
//границы автомобиля
|
||||
|
||||
//SolidBrush(Cruiser.AdditionalColor);
|
||||
int dif = _monoRailWidth / 10;
|
||||
_monoRailWidth -= dif;
|
||||
Pen pen = new(Color.Black);
|
||||
Brush cartBrush = new SolidBrush(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(EntityMonorail.BodyColor);
|
||||
Pen windowPen = new(Color.Blue);
|
||||
Brush wheelBrush = new SolidBrush(EntityMonorail.WheelColor);
|
||||
Brush windowBrush = new SolidBrush(Color.White);
|
||||
Pen tirePen = new Pen(EntityMonorail.TireColor);
|
||||
if (_monoRailWidth - _monoRailWidth / 20 * 17 < wheelSz)
|
||||
wheelSz = _monoRailWidth - _monoRailWidth / 20 * 17;
|
||||
|
||||
|
||||
//границы автомобиля
|
||||
//нижняя часть локомотива
|
||||
Point[] pointsArrLow = { new Point(_startPosX + _monoRailWidth / 10 * 4, _startPosY + _monoRailHeight / 5 * 2),
|
||||
new Point(_startPosX + _monoRailWidth / 10, _startPosY + _monoRailHeight / 5 * 2),
|
||||
new Point(_startPosX + _monoRailWidth / 10, _startPosY + _monoRailHeight / 10 * 7),
|
||||
new Point(_startPosX + _monoRailWidth / 20 * 19, _startPosY + _monoRailHeight / 10 * 7),
|
||||
new Point(_startPosX + _monoRailWidth / 20 * 19, _startPosY + _monoRailHeight / 5 * 2),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 5, _startPosY + _monoRailHeight / 5 * 2),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 4, _startPosY + _monoRailHeight / 5 * 2)};
|
||||
|
||||
g.FillPolygon(bodyBrush, pointsArrLow);
|
||||
g.DrawPolygon(pen, pointsArrLow);
|
||||
|
||||
|
||||
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 35, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
|
||||
30);
|
||||
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
|
||||
|
||||
//если есть доп.фонари
|
||||
/* if (Cruiser.Headlights)
|
||||
{
|
||||
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
|
||||
20);
|
||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
|
||||
20);
|
||||
}*/
|
||||
//основание лодки!!!
|
||||
Brush br = new SolidBrush(EntityCar.BodyColor);
|
||||
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
|
||||
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
|
||||
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
|
||||
Point[] points = new Point[3];// нос лодки
|
||||
points[0] = new Point(_startPosX + 100, _startPosY + 5);
|
||||
points[1] = new Point(_startPosX + 100, _startPosY + 55);
|
||||
points[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
|
||||
g.FillPolygon(Brushes.Pink, points);
|
||||
//границы носа лодки
|
||||
Point[] points1 = new Point[3];// нос лодки
|
||||
points1[0] = new Point(_startPosX + 100, _startPosY + 5);
|
||||
points1[1] = new Point(_startPosX + 100, _startPosY + 55);
|
||||
points1[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
|
||||
g.DrawPolygon(pen, points1);
|
||||
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 15, 10, 10);
|
||||
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 35, 10, 10);
|
||||
//крыша локомотива
|
||||
Point[] pointsArrRoof = { new Point(_startPosX + _monoRailWidth / 10, _startPosY + _monoRailHeight / 5 * 2),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 2, _startPosY + _monoRailHeight / 10),
|
||||
new Point(_startPosX + _monoRailWidth /20 * 19, _startPosY + _monoRailHeight / 10),
|
||||
new Point(_startPosX + _monoRailWidth /20 * 19, _startPosY + _monoRailHeight / 5 * 2),
|
||||
new Point(_startPosX + _monoRailWidth / 10, _startPosY + _monoRailHeight / 5 * 2)};
|
||||
g.FillPolygon(bodyBrush, pointsArrRoof);
|
||||
g.DrawPolygon(pen, pointsArrRoof);
|
||||
|
||||
//если есть ракетные шахты, добавить условие
|
||||
g.DrawRectangle(Pens.Black, _startPosX + 35,
|
||||
_startPosY + 23, 15, 15);
|
||||
g.DrawRectangle(Pens.Black, _startPosX + 50,
|
||||
_startPosY + 19, 30, 25);
|
||||
//дверь локомотива
|
||||
Point[] pointsArrDoor = { new Point(_startPosX + _monoRailWidth / 10 * 4, _startPosY + _monoRailHeight / 5 * 2),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 4, _startPosY + _monoRailHeight / 5),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 5, _startPosY + _monoRailHeight / 5),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 5, _startPosY + _monoRailHeight / 5 * 3),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 4, _startPosY + _monoRailHeight / 5 * 3) };
|
||||
g.DrawPolygon(pen, pointsArrDoor);
|
||||
g.FillPolygon(cartBrush, pointsArrDoor);
|
||||
|
||||
|
||||
//передняя часть тележки
|
||||
Point[] pointsArrFrontCart = { new Point(_startPosX + _monoRailWidth / 10 * 4, _startPosY + _monoRailHeight / 10 * 7),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 2, _startPosY + _monoRailHeight / 10 * 7),
|
||||
new Point(_startPosX, _startPosY + _monoRailHeight / 10 * 9),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 4, _startPosY + _monoRailHeight / 10 * 9),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 4, _startPosY + _monoRailHeight / 10 * 7)};
|
||||
|
||||
g.FillPolygon(cartBrush, pointsArrFrontCart);
|
||||
|
||||
//задняя часть тележки
|
||||
Point[] pointsArrBackCart = { new Point(_startPosX + _monoRailWidth / 10 * 6, _startPosY + _monoRailHeight / 10 * 7),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 9, _startPosY + _monoRailHeight / 10 * 7),
|
||||
new Point(_startPosX + _monoRailWidth, _startPosY + _monoRailHeight / 10 * 9),
|
||||
new Point(_startPosX + _monoRailWidth / 10 * 6, _startPosY + _monoRailHeight / 10 * 9)
|
||||
};
|
||||
|
||||
g.FillPolygon(cartBrush, pointsArrBackCart);
|
||||
|
||||
//левое окно
|
||||
Rectangle leftRect = new();
|
||||
leftRect.X = _startPosX + _monoRailWidth / 10 * 2;
|
||||
leftRect.Y = _startPosY + _monoRailHeight / 25 * 4;
|
||||
leftRect.Width = _monoRailWidth / 120 * 8;
|
||||
leftRect.Height = _monoRailHeight / 50 * 10;
|
||||
g.DrawRectangle(windowPen, leftRect);
|
||||
g.FillRectangle(windowBrush, leftRect);
|
||||
|
||||
//среднее окно
|
||||
Rectangle midRect = new();
|
||||
midRect.X = _startPosX + _monoRailWidth / 10 * 3;
|
||||
midRect.Y = _startPosY + _monoRailHeight / 25 * 4;
|
||||
midRect.Width = _monoRailWidth / 120 * 8;
|
||||
midRect.Height = _monoRailHeight / 50 * 10;
|
||||
g.DrawRectangle(windowPen, midRect);
|
||||
g.FillRectangle(windowBrush, midRect);
|
||||
|
||||
//правое окно
|
||||
Rectangle rightRect = new();
|
||||
rightRect.X = _startPosX + _monoRailWidth / 20 * 17;
|
||||
rightRect.Y = _startPosY + _monoRailHeight / 25 * 4;
|
||||
rightRect.Width = _monoRailWidth / 120 * 8;
|
||||
rightRect.Height = _monoRailHeight / 50 * 10;
|
||||
g.DrawRectangle(windowPen, rightRect);
|
||||
g.FillRectangle(windowBrush, rightRect);
|
||||
|
||||
g.FillEllipse(wheelBrush, _startPosX + _monoRailWidth / 10, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
|
||||
g.DrawEllipse(tirePen, _startPosX + _monoRailWidth / 10, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
|
||||
g.FillEllipse(wheelBrush, _startPosX + _monoRailWidth / 10 * 8, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
|
||||
g.DrawEllipse(tirePen, _startPosX + _monoRailWidth / 10 * 8, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
|
||||
|
||||
_monoRailWidth += dif;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,37 +3,37 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Cruiser;
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.MovementStrategy;
|
||||
using Monorail.DrawningObjects;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
namespace Monorail.MovementStrategy
|
||||
{
|
||||
internal class DrawningObjectCar : IMoveableObject
|
||||
public class DrawningObjectMonorail : IMoveableObject
|
||||
{
|
||||
private readonly DrawningCar? _drawningCar = null;
|
||||
public DrawningObjectCar(DrawningCar drawningCar)
|
||||
private readonly DrawningMonorail? _drawningMonorail = null;
|
||||
|
||||
public DrawningObjectMonorail(DrawningMonorail drawningMonorail)
|
||||
{
|
||||
_drawningCar = drawningCar;
|
||||
_drawningMonorail = drawningMonorail;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningCar == null || _drawningCar.EntityCar ==
|
||||
null)
|
||||
if (_drawningMonorail == null || _drawningMonorail.EntityMonorail == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningCar.GetPosX,
|
||||
_drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight);
|
||||
return new ObjectParameters(_drawningMonorail.GetPosX,
|
||||
_drawningMonorail.GetPosY, _drawningMonorail.GetWidth, _drawningMonorail.GetHeight);
|
||||
}
|
||||
|
||||
}
|
||||
public int GetStep => (int)(_drawningCar?.EntityCar?.Step ?? 0);
|
||||
public int GetStep => (int)(_drawningMonorail?.EntityMonorail?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawningCar?.CanMove(direction) ?? false;
|
||||
_drawningMonorail?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawningCar?.MoveTransport(direction);
|
||||
_drawningMonorail?.MoveTransport(direction);
|
||||
}
|
||||
}
|
@ -1,60 +1,79 @@
|
||||
using DumpTruck;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DumpTruck.Entities;
|
||||
using Monorail.Entities;
|
||||
|
||||
|
||||
namespace DumpTruck.DrawningObjects
|
||||
namespace Monorail.DrawningObjects
|
||||
{
|
||||
public class DrawningDumpTruck : DrawningCar
|
||||
public class DrawningLocomotive : DrawningMonorail
|
||||
{
|
||||
|
||||
|
||||
public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tent, int width, int height) : base(speed, weight, bodyColor, width, height, 110, 60)
|
||||
public DrawningLocomotive(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int width, int height, int addWheelsNumb,
|
||||
Color additionalColor, bool secondCabine, bool magniteRail) : base(speed, weight, bodyColor, wheelColor, tireColor, width, height)
|
||||
{
|
||||
if (EntityCar != null)
|
||||
if (EntityMonorail != null)
|
||||
{
|
||||
EntityCar = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, bodyKit, tent);
|
||||
EntityMonorail = new EntityLocomotive(speed, weight, bodyColor, wheelColor, tireColor,
|
||||
addWheelsNumb, additionalColor, secondCabine, magniteRail);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCar is not EntityDumpTruck dumpTruck)
|
||||
base.DrawTransport(g);
|
||||
int dif = _monoRailWidth / 10;
|
||||
_monoRailWidth -= dif;
|
||||
Pen windowPen = new(Color.Blue);
|
||||
Brush wheelBrush = new SolidBrush(EntityMonorail.WheelColor);
|
||||
Brush windowBrush = new SolidBrush(Color.White);
|
||||
if (EntityMonorail == null)
|
||||
return;
|
||||
if (EntityMonorail is not EntityLocomotive advancedMonorail)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen additionalPen = new(advancedMonorail.AdditionalColor);
|
||||
Brush additionalBrush = new SolidBrush(advancedMonorail.AdditionalColor);
|
||||
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush addBrush = new SolidBrush(dumpTruck.AdditionalColor);
|
||||
Brush brush = new SolidBrush(dumpTruck.BodyColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
if (dumpTruck.Tent)
|
||||
//3 колеса
|
||||
if (advancedMonorail.AddWheelsNumb >= 3)
|
||||
{
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
|
||||
20);
|
||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
|
||||
20);
|
||||
g.FillEllipse(additionalBrush, _startPosX + _monoRailWidth / 10 * 6, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
|
||||
g.DrawEllipse(additionalPen, _startPosX + _monoRailWidth / 10 * 6, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
|
||||
}
|
||||
|
||||
if (dumpTruck.BodyKit)
|
||||
{
|
||||
g.FillEllipse(Brushes.Green, _startPosX + 90, _startPosY + 20, 20, 20);
|
||||
//4 колеса
|
||||
|
||||
if (advancedMonorail.AddWheelsNumb >= 4)
|
||||
{
|
||||
g.FillEllipse(additionalBrush, _startPosX + _monoRailWidth / 10 * 3, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
|
||||
g.DrawEllipse(additionalPen, _startPosX + _monoRailWidth / 10 * 3, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
|
||||
}
|
||||
|
||||
|
||||
if (advancedMonorail.SecondCabine)
|
||||
{
|
||||
Point[] pointsSecondCabine = { new Point(_startPosX + _monoRailWidth / 20 * 19, _startPosY + _monoRailHeight / 10),
|
||||
new Point(_startPosX + _monoRailWidth + dif, _startPosY + _monoRailHeight / 5 * 2),
|
||||
new Point(_startPosX + _monoRailWidth + dif, _startPosY + _monoRailHeight / 10 * 7),
|
||||
new Point(_startPosX + _monoRailWidth / 20 * 19, _startPosY + _monoRailHeight / 10 * 7),};
|
||||
g.FillPolygon(additionalBrush, pointsSecondCabine);
|
||||
g.DrawPolygon(additionalPen, pointsSecondCabine);
|
||||
Rectangle Rect = new();
|
||||
Rect.X = _startPosX + _monoRailWidth / 20 * 19;
|
||||
Rect.Y = _startPosY + _monoRailHeight / 25 * 4 + _monoRailHeight / 50 * 3;
|
||||
Rect.Width = _monoRailWidth / 120 * 6;
|
||||
Rect.Height = _monoRailHeight / 50 * 7;
|
||||
g.DrawRectangle(windowPen, Rect);
|
||||
g.FillRectangle(windowBrush, Rect);
|
||||
}
|
||||
_monoRailWidth += dif;
|
||||
//магнитная линия
|
||||
if (advancedMonorail.MagniteRail)
|
||||
{
|
||||
g.DrawLine(additionalPen, new Point(_startPosX, _startPosY + _monoRailHeight - 1), new Point(_startPosX + _monoRailWidth, _startPosY + _monoRailHeight - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
1
Cruiser/Cruiser/Form1.Designer.cs
generated
1
Cruiser/Cruiser/Form1.Designer.cs
generated
@ -136,6 +136,7 @@
|
||||
this.comboBox1.Name = "comboBox1";
|
||||
this.comboBox1.Size = new System.Drawing.Size(182, 33);
|
||||
this.comboBox1.TabIndex = 7;
|
||||
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
|
||||
//
|
||||
// ButtonStep
|
||||
//
|
||||
|
@ -1,20 +1,29 @@
|
||||
using System;
|
||||
using Cruiser;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.Entities;
|
||||
using Monorail.DrawningObjects;
|
||||
using Monorail.MovementStrategy;
|
||||
using Monorail;
|
||||
|
||||
using DumpTruck.MovementStrategy;
|
||||
|
||||
namespace Cruiser
|
||||
{
|
||||
|
||||
public partial class CruiserForm : Form
|
||||
{
|
||||
private DrawningCar? _drawningCar;
|
||||
private DrawningMonorail? _drawningMonorail;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public DrawningCar? SelectedCar { get; private set; }
|
||||
public DrawningMonorail? SelectedCar { get; private set; }
|
||||
|
||||
public CruiserForm()
|
||||
{
|
||||
@ -24,18 +33,18 @@ namespace Cruiser
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningCar == null)
|
||||
if (_drawningMonorail == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningCar.DrawTransport(gr);
|
||||
_drawningMonorail.DrawTransport(gr);
|
||||
pictureBox1.Image = bmp;
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCar == null)
|
||||
if (_drawningMonorail == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -43,16 +52,16 @@ namespace Cruiser
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningCar.MoveTransport(DirectionType.Up);
|
||||
_drawningMonorail.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningCar.MoveTransport(DirectionType.Down);
|
||||
_drawningMonorail.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningCar.MoveTransport(DirectionType.Left);
|
||||
_drawningMonorail.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningCar.MoveTransport(DirectionType.Right);
|
||||
_drawningMonorail.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
@ -61,28 +70,17 @@ namespace Cruiser
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color wheelColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color tireColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
bodyColor = dialog.Color;
|
||||
}
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialog.Color;
|
||||
}
|
||||
|
||||
_drawningCar = new DrawningDumpTruck(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
color,
|
||||
dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBox1.Width, pictureBox1.Height);
|
||||
_drawningCar.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
_drawningMonorail = new DrawningMonorail(random.Next(100, 300), random.Next(1000, 3000),
|
||||
bodyColor, wheelColor, tireColor,
|
||||
pictureBox1.Width, pictureBox1.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
@ -92,7 +90,7 @@ namespace Cruiser
|
||||
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCar == null)
|
||||
if (_drawningMonorail == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -102,14 +100,14 @@ namespace Cruiser
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
1 => new MoveToEdge(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawningObjectCar(_drawningCar), pictureBox1.Width,
|
||||
_abstractStrategy.SetData(new DrawningObjectMonorail(_drawningMonorail), pictureBox1.Width,
|
||||
pictureBox1.Height);
|
||||
comboBox1.Enabled = false;
|
||||
}
|
||||
@ -129,28 +127,33 @@ namespace Cruiser
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color wheelColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color tireColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawningCar = new DrawningCar(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
color,
|
||||
pictureBox1.Width, pictureBox1.Height);
|
||||
_drawningCar.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
bodyColor = dialog.Color;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
additionalColor = dialog.Color;
|
||||
int addWheelNumb = random.Next(3, 5);
|
||||
_drawningMonorail = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000),
|
||||
bodyColor, wheelColor, tireColor,
|
||||
pictureBox1.Width, pictureBox1.Height, addWheelNumb,
|
||||
additionalColor, random.Next(0, 2) > 0, random.Next(0, 2) > 0);
|
||||
Draw();
|
||||
}
|
||||
|
||||
public void SelectedCruiser_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedCar = _drawningCar;
|
||||
SelectedCar = _drawningMonorail;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
75
Cruiser/Cruiser/FormCruiserCollection.Designer.cs
generated
75
Cruiser/Cruiser/FormCruiserCollection.Designer.cs
generated
@ -30,6 +30,11 @@
|
||||
{
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.textBox2 = new System.Windows.Forms.TextBox();
|
||||
this.addStorageButton = new System.Windows.Forms.Button();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.updateCollectionButton = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveCar = new System.Windows.Forms.Button();
|
||||
this.ButtonAddCruiser = new System.Windows.Forms.Button();
|
||||
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||
@ -42,7 +47,7 @@
|
||||
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(800, 450);
|
||||
this.pictureBox1.Size = new System.Drawing.Size(971, 544);
|
||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBox1.TabIndex = 0;
|
||||
this.pictureBox1.TabStop = false;
|
||||
@ -50,17 +55,68 @@
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.textBox2);
|
||||
this.panel1.Controls.Add(this.addStorageButton);
|
||||
this.panel1.Controls.Add(this.listBoxStorages);
|
||||
this.panel1.Controls.Add(this.button2);
|
||||
this.panel1.Controls.Add(this.updateCollectionButton);
|
||||
this.panel1.Controls.Add(this.ButtonRemoveCar);
|
||||
this.panel1.Controls.Add(this.ButtonAddCruiser);
|
||||
this.panel1.Controls.Add(this.textBox1);
|
||||
this.panel1.Location = new System.Drawing.Point(589, 12);
|
||||
this.panel1.Location = new System.Drawing.Point(692, 12);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(211, 438);
|
||||
this.panel1.Size = new System.Drawing.Size(267, 520);
|
||||
this.panel1.TabIndex = 1;
|
||||
//
|
||||
// textBox2
|
||||
//
|
||||
this.textBox2.Location = new System.Drawing.Point(60, 36);
|
||||
this.textBox2.Name = "textBox2";
|
||||
this.textBox2.Size = new System.Drawing.Size(150, 31);
|
||||
this.textBox2.TabIndex = 2;
|
||||
//
|
||||
// addStorageButton
|
||||
//
|
||||
this.addStorageButton.Location = new System.Drawing.Point(79, 88);
|
||||
this.addStorageButton.Name = "addStorageButton";
|
||||
this.addStorageButton.Size = new System.Drawing.Size(112, 34);
|
||||
this.addStorageButton.TabIndex = 2;
|
||||
this.addStorageButton.Text = "Добавить";
|
||||
this.addStorageButton.UseVisualStyleBackColor = true;
|
||||
this.addStorageButton.Click += new System.EventHandler(this.addStorageButton_Click);
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.ItemHeight = 25;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(60, 128);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(152, 104);
|
||||
this.listBoxStorages.TabIndex = 4;
|
||||
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged);
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(60, 264);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(159, 36);
|
||||
this.button2.TabIndex = 2;
|
||||
this.button2.Text = "Удалить набор";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// updateCollectionButton
|
||||
//
|
||||
this.updateCollectionButton.Location = new System.Drawing.Point(79, 469);
|
||||
this.updateCollectionButton.Name = "updateCollectionButton";
|
||||
this.updateCollectionButton.Size = new System.Drawing.Size(112, 34);
|
||||
this.updateCollectionButton.TabIndex = 2;
|
||||
this.updateCollectionButton.Text = "Обновить";
|
||||
this.updateCollectionButton.UseVisualStyleBackColor = true;
|
||||
this.updateCollectionButton.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// ButtonRemoveCar
|
||||
//
|
||||
this.ButtonRemoveCar.Location = new System.Drawing.Point(31, 168);
|
||||
this.ButtonRemoveCar.Location = new System.Drawing.Point(60, 429);
|
||||
this.ButtonRemoveCar.Name = "ButtonRemoveCar";
|
||||
this.ButtonRemoveCar.Size = new System.Drawing.Size(150, 34);
|
||||
this.ButtonRemoveCar.TabIndex = 2;
|
||||
@ -70,7 +126,7 @@
|
||||
//
|
||||
// ButtonAddCruiser
|
||||
//
|
||||
this.ButtonAddCruiser.Location = new System.Drawing.Point(31, 37);
|
||||
this.ButtonAddCruiser.Location = new System.Drawing.Point(60, 317);
|
||||
this.ButtonAddCruiser.Name = "ButtonAddCruiser";
|
||||
this.ButtonAddCruiser.Size = new System.Drawing.Size(150, 34);
|
||||
this.ButtonAddCruiser.TabIndex = 3;
|
||||
@ -80,7 +136,7 @@
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
this.textBox1.Location = new System.Drawing.Point(31, 104);
|
||||
this.textBox1.Location = new System.Drawing.Point(60, 381);
|
||||
this.textBox1.Name = "textBox1";
|
||||
this.textBox1.Size = new System.Drawing.Size(150, 31);
|
||||
this.textBox1.TabIndex = 2;
|
||||
@ -90,7 +146,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.ClientSize = new System.Drawing.Size(971, 544);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Name = "FormCruiserCollection";
|
||||
@ -110,5 +166,10 @@
|
||||
private Button ButtonRemoveCar;
|
||||
private Button ButtonAddCruiser;
|
||||
private TextBox textBox1;
|
||||
private Button updateCollectionButton;
|
||||
private TextBox textBox2;
|
||||
private Button addStorageButton;
|
||||
private ListBox listBoxStorages;
|
||||
private Button button2;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
|
||||
using DumpTruck.Generics;
|
||||
using Monorail.DrawningObjects;
|
||||
using Monorail.Generics;
|
||||
using Monorail.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -9,22 +10,18 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Cruiser;
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.Generics;
|
||||
using DumpTruck.MovementStrategy;
|
||||
|
||||
|
||||
namespace Cruiser
|
||||
{
|
||||
public partial class FormCruiserCollection : Form
|
||||
{
|
||||
private readonly CarsGenericCollection<DrawningCar, DrawningObjectCar> _cars;
|
||||
private readonly MonorailGenericStorage _storage;
|
||||
|
||||
public FormCruiserCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_cars = new CarsGenericCollection<DrawningCar, DrawningObjectCar>(pictureBox1.Width, pictureBox1.Height);
|
||||
_storage = new MonorailGenericStorage(pictureBox1.Width, pictureBox1.Height);
|
||||
}
|
||||
|
||||
private void pictureBox1_Click(object sender, EventArgs e)
|
||||
@ -32,8 +29,19 @@ namespace Cruiser
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void ButtonAddCruiser_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CruiserForm form = new();
|
||||
|
||||
|
||||
@ -41,10 +49,10 @@ namespace Cruiser
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_cars + form.SelectedCar != null)
|
||||
if (obj + form.SelectedCar != null)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox1.Image = _cars.ShowCars();
|
||||
pictureBox1.Image = obj.ShowMonorails();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -52,10 +60,40 @@ namespace Cruiser
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||
>= listBoxStorages.Items.Count))
|
||||
{
|
||||
listBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
||||
index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
@ -68,10 +106,10 @@ namespace Cruiser
|
||||
return;
|
||||
}
|
||||
|
||||
if (_cars - pos != null)
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox1.Image = _cars.ShowCars();
|
||||
pictureBox1.Image = obj.ShowMonorails();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -82,7 +120,7 @@ namespace Cruiser
|
||||
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox1.Image = _cars.ShowCars();
|
||||
// pictureBox1.Image = obj.ShowMonorails();
|
||||
}
|
||||
|
||||
private void maskedTextBoxNumber_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
|
||||
@ -94,6 +132,59 @@ namespace Cruiser
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox1.Image = obj.ShowMonorails();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox1.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
|
||||
}
|
||||
|
||||
private void delStorageButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
||||
?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addStorageButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBox1.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBox1.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,38 +1,16 @@
|
||||
using DumpTruck;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DumpTruck.MovementStrategy;
|
||||
using Cruiser;
|
||||
using Monorail.DrawningObjects;
|
||||
|
||||
using Cruiser;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
namespace Monorail.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);
|
||||
|
||||
}
|
||||
|
100
Cruiser/Cruiser/MonorailGenericCollection.cs
Normal file
100
Cruiser/Cruiser/MonorailGenericCollection.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using Monorail.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Monorail.DrawningObjects;
|
||||
using System.Drawing;
|
||||
|
||||
|
||||
namespace Monorail.Generics
|
||||
{
|
||||
internal class MonorailGenericCollection<T, U>
|
||||
where T : DrawningMonorail
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
private readonly int _placeSizeWidth = 133;
|
||||
|
||||
private readonly int _placeSizeHeight = 50;
|
||||
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
public MonorailGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
public static bool operator +(MonorailGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
}
|
||||
|
||||
public static T? operator -(MonorailGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
collect._collection.Remove(pos);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
|
||||
public Bitmap ShowMonorails()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var monorail in _collection.GetMonorails())
|
||||
{
|
||||
if (monorail != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
monorail.SetPosition(i % inRow * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / inRow + 1) * _placeSizeHeight);
|
||||
monorail.DrawTransport(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
51
Cruiser/Cruiser/MonorailGenericStorage.cs
Normal file
51
Cruiser/Cruiser/MonorailGenericStorage.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using Monorail.DrawningObjects;
|
||||
using Monorail.Generics;
|
||||
using Monorail.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Monorail.Generics
|
||||
{
|
||||
internal class MonorailGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>> _monorailStorages;
|
||||
public List<string> Keys => _monorailStorages.Keys.ToList();
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
public MonorailGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_monorailStorages = new Dictionary<string,
|
||||
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_monorailStorages.Add(name, new MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_monorailStorages.ContainsKey(name))
|
||||
return;
|
||||
_monorailStorages.Remove(name);
|
||||
}
|
||||
|
||||
public MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_monorailStorages.ContainsKey(ind))
|
||||
return _monorailStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
using DumpTruck.MovementStrategy;
|
||||
|
||||
using Monorail.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
namespace Monorail.MovementStrategy
|
||||
{
|
||||
internal class MoveToBorder : AbstractStrategy
|
||||
public class MoveToEdge : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
@ -16,10 +17,8 @@ namespace DumpTruck.MovementStrategy
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
return objParams.RightBorder < FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder < FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
@ -29,22 +28,22 @@ namespace DumpTruck.MovementStrategy
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = FieldWidth - objParams.ObjectMiddleHorizontal;
|
||||
var diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
|
||||
MoveRight();
|
||||
|
||||
if (diffX < 0)
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = FieldHeight - objParams.ObjectMiddleVertical;
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
|
||||
MoveDown();
|
||||
|
||||
if (diffY < 0)
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
using DumpTruck.MovementStrategy;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
namespace Monorail.MovementStrategy
|
||||
{
|
||||
internal class MoveToCenter : AbstractStrategy
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
@ -16,12 +16,12 @@ namespace DumpTruck.MovementStrategy
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2);
|
||||
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
@ -54,5 +54,6 @@ namespace DumpTruck.MovementStrategy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,51 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
namespace Monorail.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;
|
||||
@ -53,5 +27,6 @@ namespace DumpTruck.MovementStrategy
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -2,41 +2,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DumpTruck.Entities
|
||||
namespace Monorail.Entities
|
||||
{
|
||||
public class EntityDumpTruck : EntityCar
|
||||
public class EntityLocomotive : EntityMonorail
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
public int AddWheelsNumb { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия кузова
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
public bool SecondCabine { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия tent
|
||||
/// </summary>
|
||||
public bool Tent { get; private set; }
|
||||
|
||||
|
||||
public EntityDumpTruck(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool tent) : base(speed, weight, bodyColor)
|
||||
public bool MagniteRail { get; private set; }
|
||||
public EntityLocomotive(int speed, double weight, Color bodyColor, Color wheelColor,
|
||||
Color tireColor, int addWheelsNumb, Color secondCabineColor, bool secondCabine, bool magniteRail) : base(speed, weight, bodyColor, wheelColor, tireColor)
|
||||
{
|
||||
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Tent = tent;
|
||||
AdditionalColor = secondCabineColor;
|
||||
AddWheelsNumb = addWheelsNumb;
|
||||
SecondCabine = secondCabine;
|
||||
MagniteRail = magniteRail;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
namespace Cruiser
|
||||
{
|
||||
// пока не меняю
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -4,99 +4,73 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Cruiser.Generics
|
||||
namespace Monorail.Generics
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T?[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
///
|
||||
public int startPointer = 0;
|
||||
private readonly List<T?> _places;
|
||||
|
||||
public int Count => _places.Count;
|
||||
|
||||
private readonly int _maxCount;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T car)
|
||||
|
||||
public bool Insert(T monorail)
|
||||
{
|
||||
if (_places[Count - 1] != null)
|
||||
return -1;
|
||||
return Insert(car, 0);
|
||||
if (_places.Count == _maxCount)
|
||||
return false;
|
||||
Insert(monorail, 0);
|
||||
return true;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T car, int position)
|
||||
|
||||
public bool Insert(T monorail, int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return -1;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int indexEnd = position + 1;
|
||||
while (_places[indexEnd] != null)
|
||||
{
|
||||
indexEnd++;
|
||||
}
|
||||
for (int i = indexEnd + 1; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
|
||||
}
|
||||
_places[position] = car;
|
||||
return position;
|
||||
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||
return false;
|
||||
_places.Insert(position, monorail);
|
||||
return true;
|
||||
}
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < Count && position >= 0)
|
||||
{
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
if (!(position >= 0 && position < Count))
|
||||
return false;
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
public T? this[int position]
|
||||
{
|
||||
if (position < Count && position >= 0) { return _places[position]; }
|
||||
return null;
|
||||
|
||||
get
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||
return;
|
||||
_places.Insert(position, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetMonorails(int? maxMonorails = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxMonorails.HasValue && i == maxMonorails.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -4,12 +4,12 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
namespace Monorail
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
NotInit = 1,
|
||||
InProgress = 2,
|
||||
Finish = 3
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user