diff --git a/Cruiser/Cruiser/AbstractStrategy.cs b/Cruiser/Cruiser/AbstractStrategy.cs
index 6560ad1..a775ccc 100644
--- a/Cruiser/Cruiser/AbstractStrategy.cs
+++ b/Cruiser/Cruiser/AbstractStrategy.cs
@@ -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
{
- ///
- /// Перемещаемый объект
- ///
private IMoveableObject? _moveableObject;
- ///
- /// Статус перемещения
- ///
+
private Status _state = Status.NotInit;
- ///
- /// Ширина поля
- ///
+
protected int FieldWidth { get; private set; }
- ///
- /// Высота поля
- ///
+
protected int FieldHeight { get; private set; }
- ///
- /// Статус перемещения
- ///
+
public Status GetStatus() { return _state; }
- ///
- /// Установка данных
- ///
- /// Перемещаемый объект
- /// Ширина поля
- /// Высота поля
- 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;
}
- ///
- /// Шаг перемещения
- ///
+
public void MakeStep()
{
if (_state != Status.InProgress)
@@ -66,35 +40,18 @@ namespace DumpTruck.MovementStrategy
}
MoveToTarget();
}
- ///
- /// Перемещение влево
- ///
- /// Результат перемещения (true - удалось переместиться, false - неудача)
+
protected bool MoveLeft() => MoveTo(DirectionType.Left);
- ///
- /// Перемещение вправо
- ///
- /// Результат перемещения (true - удалось переместиться, false - неудача)
+
protected bool MoveRight() => MoveTo(DirectionType.Right);
- ///
- /// Перемещение вверх
- ///
- /// Результат перемещения (true - удалось переместиться, false - неудача)
+
protected bool MoveUp() => MoveTo(DirectionType.Up);
- ///
- /// Перемещение вниз
- ///
- /// Результат перемещения (true - удалось переместиться,false - неудача)
+
protected bool MoveDown() => MoveTo(DirectionType.Down);
- ///
- /// Параметры объекта
- ///
+
protected ObjectParameters? GetObjectParameters =>
- _moveableObject?.GetObjectPosition;
- ///
- /// Шаг объекта
- ///
- ///
+_moveableObject?.GetObjectPosition;
+
protected int? GetStep()
{
if (_state != Status.InProgress)
@@ -103,20 +60,11 @@ namespace DumpTruck.MovementStrategy
}
return _moveableObject?.GetStep;
}
- ///
- /// Перемещение к цели
- ///
+
protected abstract void MoveToTarget();
- ///
- /// Достигнута ли цель
- ///
- ///
+
protected abstract bool IsTargetDestinaion();
- ///
- /// Попытка перемещения в требуемом направлении
- ///
- /// Направление
- /// Результат попытки (true - удалось переместиться, false - неудача)
+
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
@@ -130,5 +78,7 @@ namespace DumpTruck.MovementStrategy
}
return false;
}
+
+
}
-}
+}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/CarsGenericCollection.cs b/Cruiser/Cruiser/CarsGenericCollection.cs
index dd5c59b..5f28270 100644
--- a/Cruiser/Cruiser/CarsGenericCollection.cs
+++ b/Cruiser/Cruiser/CarsGenericCollection.cs
@@ -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
- where T : DrawningCar
- where U : IMoveableObject
- {
- ///
- /// Ширина окна прорисовки
- ///
- private readonly int _pictureWidth;
- ///
- /// Высота окна прорисовки
- ///
- private readonly int _pictureHeight;
- ///
- /// Размер занимаемого объектом места (ширина)
- ///
- private readonly int _placeSizeWidth = 210;
- ///
- /// Размер занимаемого объектом места (высота)
- ///
- private readonly int _placeSizeHeight = 90;
- ///
- /// Набор объектов
- ///
- private readonly SetGeneric _collection;
- ///
- /// Конструктор
- ///
- ///
- ///
- public CarsGenericCollection(int picWidth, int picHeight)
- {
- int width = picWidth / _placeSizeWidth;
- int height = picHeight / _placeSizeHeight;
- _pictureWidth = picWidth;
- _pictureHeight = picHeight;
- _collection = new SetGeneric(width * height);
- }
- ///
- /// Перегрузка оператора сложения
- ///
- ///
- ///
- ///
- public static int operator +(CarsGenericCollection collect, T?
- obj)
- {
- if (obj == null)
- {
- return -1;
- }
- return collect._collection.Insert(obj) ;
- }
- ///
- /// Перегрузка оператора вычитания
- ///
- ///
- ///
- ///
- public static bool operator -(CarsGenericCollection collect, int
- pos)
- {
- T? obj = collect._collection.Get(pos);
- if (obj != null)
- {
- collect._collection.Remove(pos);
- }
- return true;
- }
- ///
- /// Получение объекта IMoveableObject
- ///
- ///
- ///
- public U? GetU(int pos)
- {
- return (U?)_collection.Get(pos)?.GetMoveableObject;
- }
- ///
- /// Вывод всего набора объектов
- ///
- ///
- public Bitmap ShowCars()
- {
- 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)
- {
- 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);
-
- }
- }
- }
- }
-}
\ No newline at end of file
+
\ No newline at end of file
diff --git a/Cruiser/Cruiser/Cruiser.cs b/Cruiser/Cruiser/Cruiser.cs
index 5ba615d..9877dd3 100644
--- a/Cruiser/Cruiser/Cruiser.cs
+++ b/Cruiser/Cruiser/Cruiser.cs
@@ -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
{
- ///
- /// Скорость
- ///
public int Speed { get; private set; }
- ///
- /// Вес
- ///
public double Weight { get; private set; }
- ///
- /// Основной цвет
- ///
+
public Color BodyColor { get; private set; }
- ///
- /// Шаг перемещения автомобиля
- ///
+ public Color WheelColor { get; private set; }
+
+ public Color TireColor { get; private set; }
+
public double Step => (double)Speed * 100 / Weight;
- ///
- /// Конструктор с параметрами
- ///
- /// Скорость
- /// Вес автомобиля
- /// Основной цвет
- 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;
}
-
}
}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/Direction.cs b/Cruiser/Cruiser/Direction.cs
index 5ead1ba..c67099a 100644
--- a/Cruiser/Cruiser/Direction.cs
+++ b/Cruiser/Cruiser/Direction.cs
@@ -4,27 +4,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Cruiser
+namespace Monorail
{
public enum DirectionType
{
- /// Вверх
-
- ///
Up = 1,
- ///
- /// Вниз
- ///
Down = 2,
- ///
- /// Влево
- ///
Left = 3,
- ///
- /// Вправо
- ///
Right = 4
+
}
-}
-
-
+}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/DrawningCruiser.cs b/Cruiser/Cruiser/DrawningCruiser.cs
index 3f3a953..f46b5e5 100644
--- a/Cruiser/Cruiser/DrawningCruiser.cs
+++ b/Cruiser/Cruiser/DrawningCruiser.cs
@@ -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;
- ///
- /// Координата X объекта
- ///
- public int GetPosX => _startPosX;
- ///
- /// Координата Y объекта
- ///
- public int GetPosY => _startPosY;
- ///
- /// Ширина объекта
- ///
- public int GetWidth => _carWidth;
- ///
- /// Высота объекта
- ///
- public int GetHeight => _carHeight;
-
- ///
- /// Получение объекта IMoveableObject из объекта DrawningCar
- ///
- 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;
+
}
-
}
-}
\ No newline at end of file
+
+}
+
diff --git a/Cruiser/Cruiser/DrawningObjectCar.cs b/Cruiser/Cruiser/DrawningObjectCar.cs
index 6f38dbe..e5d7161 100644
--- a/Cruiser/Cruiser/DrawningObjectCar.cs
+++ b/Cruiser/Cruiser/DrawningObjectCar.cs
@@ -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);
}
}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/DrawningPro.cs b/Cruiser/Cruiser/DrawningPro.cs
index 6128653..73aaeab 100644
--- a/Cruiser/Cruiser/DrawningPro.cs
+++ b/Cruiser/Cruiser/DrawningPro.cs
@@ -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));
}
}
}
-
+}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/Form1.Designer.cs b/Cruiser/Cruiser/Form1.Designer.cs
index 4f12c6c..c100641 100644
--- a/Cruiser/Cruiser/Form1.Designer.cs
+++ b/Cruiser/Cruiser/Form1.Designer.cs
@@ -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
//
diff --git a/Cruiser/Cruiser/Form1.cs b/Cruiser/Cruiser/Form1.cs
index 2bcfb90..ac40e3b 100644
--- a/Cruiser/Cruiser/Form1.cs
+++ b/Cruiser/Cruiser/Form1.cs
@@ -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)
+ {
+
+ }
}
}
diff --git a/Cruiser/Cruiser/FormCruiserCollection.Designer.cs b/Cruiser/Cruiser/FormCruiserCollection.Designer.cs
index 9680b89..fb8fb85 100644
--- a/Cruiser/Cruiser/FormCruiserCollection.Designer.cs
+++ b/Cruiser/Cruiser/FormCruiserCollection.Designer.cs
@@ -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;
}
}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/FormCruiserCollection.cs b/Cruiser/Cruiser/FormCruiserCollection.cs
index 1a2e08c..dc47de6 100644
--- a/Cruiser/Cruiser/FormCruiserCollection.cs
+++ b/Cruiser/Cruiser/FormCruiserCollection.cs
@@ -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 _cars;
+ private readonly MonorailGenericStorage _storage;
public FormCruiserCollection()
{
InitializeComponent();
- _cars = new CarsGenericCollection(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();
+ }
+ }
+ }
+
+
diff --git a/Cruiser/Cruiser/IMoveableObject.cs b/Cruiser/Cruiser/IMoveableObject.cs
index 3c9b842..150a3b2 100644
--- a/Cruiser/Cruiser/IMoveableObject.cs
+++ b/Cruiser/Cruiser/IMoveableObject.cs
@@ -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
{
- ///
- /// Интерфейс для работы с перемещаемым объектом
- ///
public interface IMoveableObject
{
- ///
- /// Получение координаты X объекта
- ///
ObjectParameters? GetObjectPosition { get; }
- ///
- /// Шаг объекта
- ///
+
int GetStep { get; }
- ///
- /// Проверка, можно ли переместиться по нужному направлению
- ///
- ///
- ///
+
bool CheckCanMove(DirectionType direction);
- ///
- /// Изменение направления пермещения объекта
- ///
- /// Направление
+
void MoveObject(DirectionType direction);
}
diff --git a/Cruiser/Cruiser/MonorailGenericCollection.cs b/Cruiser/Cruiser/MonorailGenericCollection.cs
new file mode 100644
index 0000000..cf90744
--- /dev/null
+++ b/Cruiser/Cruiser/MonorailGenericCollection.cs
@@ -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
+ 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 _collection;
+
+ public MonorailGenericCollection(int picWidth, int picHeight)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = new SetGeneric(width * height);
+ }
+
+ public static bool operator +(MonorailGenericCollection collect, T? obj)
+ {
+ if (obj == null)
+ return false;
+
+ return collect?._collection.Insert(obj) ?? false;
+ }
+
+ public static T? operator -(MonorailGenericCollection 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++;
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/MonorailGenericStorage.cs b/Cruiser/Cruiser/MonorailGenericStorage.cs
new file mode 100644
index 0000000..55ef868
--- /dev/null
+++ b/Cruiser/Cruiser/MonorailGenericStorage.cs
@@ -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> _monorailStorages;
+ public List Keys => _monorailStorages.Keys.ToList();
+
+ private readonly int _pictureWidth;
+
+ private readonly int _pictureHeight;
+
+ public MonorailGenericStorage(int pictureWidth, int pictureHeight)
+ {
+ _monorailStorages = new Dictionary>();
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ }
+
+ public void AddSet(string name)
+ {
+ _monorailStorages.Add(name, new MonorailGenericCollection(_pictureWidth, _pictureHeight));
+ }
+
+ public void DelSet(string name)
+ {
+ if (!_monorailStorages.ContainsKey(name))
+ return;
+ _monorailStorages.Remove(name);
+ }
+
+ public MonorailGenericCollection? this[string ind]
+ {
+ get
+ {
+ if (_monorailStorages.ContainsKey(ind))
+ return _monorailStorages[ind];
+ return null;
+ }
+ }
+ }
+}
diff --git a/Cruiser/Cruiser/MoveToBorder.cs b/Cruiser/Cruiser/MoveToBorder.cs
index 48787b1..d2d6d04 100644
--- a/Cruiser/Cruiser/MoveToBorder.cs
+++ b/Cruiser/Cruiser/MoveToBorder.cs
@@ -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();
+ }
}
}
-
-
}
}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/MoveToCenter.cs b/Cruiser/Cruiser/MoveToCenter.cs
index 44f0176..7be5b0a 100644
--- a/Cruiser/Cruiser/MoveToCenter.cs
+++ b/Cruiser/Cruiser/MoveToCenter.cs
@@ -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
}
}
}
+
}
}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/ObjectParameters.cs b/Cruiser/Cruiser/ObjectParameters.cs
index 2d3032c..7745212 100644
--- a/Cruiser/Cruiser/ObjectParameters.cs
+++ b/Cruiser/Cruiser/ObjectParameters.cs
@@ -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
{
- ///
- /// Параметры-координаты объекта
- ///
+
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
- ///
- /// Левая граница
- ///
+
public int LeftBorder => _x;
- ///
- /// Верхняя граница
- ///
+
public int TopBorder => _y;
- ///
- /// Правая граница
- ///
+
public int RightBorder => _x + _width;
- ///
- /// Нижняя граница
- ///
+
public int DownBorder => _y + _height;
- ///
- /// Середина объекта
- ///
+
public int ObjectMiddleHorizontal => _x + _width / 2;
- ///
- /// Середина объекта
- ///
+
public int ObjectMiddleVertical => _y + _height / 2;
- ///
- /// Конструктор
- ///
- /// Координата X
- /// Координата Y
- /// Ширина
- /// Высота
+
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
@@ -53,5 +27,6 @@ namespace DumpTruck.MovementStrategy
_width = width;
_height = height;
}
+
}
}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/Pro.cs b/Cruiser/Cruiser/Pro.cs
index f43600e..3d34488 100644
--- a/Cruiser/Cruiser/Pro.cs
+++ b/Cruiser/Cruiser/Pro.cs
@@ -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
{
-
- ///
- /// Дополнительный цвет (для опциональных элементов)
- ///
public Color AdditionalColor { get; private set; }
+ public int AddWheelsNumb { get; private set; }
- ///
- /// Признак (опция) наличия кузова
- ///
- public bool BodyKit { get; private set; }
+ public bool SecondCabine { get; private set; }
- ///
- /// Признак (опция) наличия tent
- ///
- 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;
}
+
}
-
-}
-
+}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/Program.cs b/Cruiser/Cruiser/Program.cs
index 2672862..10cfd7d 100644
--- a/Cruiser/Cruiser/Program.cs
+++ b/Cruiser/Cruiser/Program.cs
@@ -1,5 +1,6 @@
namespace Cruiser
{
+ //
internal static class Program
{
///
diff --git a/Cruiser/Cruiser/SetGeneric.cs b/Cruiser/Cruiser/SetGeneric.cs
index 214eb3f..06f50a9 100644
--- a/Cruiser/Cruiser/SetGeneric.cs
+++ b/Cruiser/Cruiser/SetGeneric.cs
@@ -4,99 +4,73 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Cruiser.Generics
+namespace Monorail.Generics
{
internal class SetGeneric
where T : class
{
- ///
- /// Массив объектов, которые храним
- ///
- private readonly T?[] _places;
- ///
- /// Количество объектов в массиве
- ///
- public int Count => _places.Length;
- ///
- /// Конструктор
- ///
- ///
- ///
- public int startPointer = 0;
+ private readonly List _places;
+
+ public int Count => _places.Count;
+
+ private readonly int _maxCount;
public SetGeneric(int count)
{
- _places = new T?[count];
+ _maxCount = count;
+ _places = new List(count);
}
- ///
- /// Добавление объекта в набор
- ///
- /// Добавляемый автомобиль
- ///
- 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;
+
}
- ///
- /// Добавление объекта в набор на конкретную позицию
- ///
- /// Добавляемый автомобиль
- /// Позиция
- ///
- 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 вставка по позиции
-
-
-
- ///
- /// Удаление объекта из набора с конкретной позиции
- ///
- ///
- ///
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;
}
- ///
- /// Получение объекта из набора по позиции
- ///
- ///
- ///
- 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 GetMonorails(int? maxMonorails = null)
+ {
+ for (int i = 0; i < _places.Count; ++i)
+ {
+ yield return _places[i];
+ if (maxMonorails.HasValue && i == maxMonorails.Value)
+ {
+ yield break;
+ }
+ }
+ }
+
}
}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/Status.cs b/Cruiser/Cruiser/Status.cs
index ed02976..089a1e6 100644
--- a/Cruiser/Cruiser/Status.cs
+++ b/Cruiser/Cruiser/Status.cs
@@ -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
}
-}
+}
\ No newline at end of file