Compare commits
3 Commits
AccordionB
...
LabWork03
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ae96abc1b | |||
| c9e4d0b039 | |||
| 9c1f576994 |
@@ -0,0 +1,69 @@
|
||||
using ProjectAccordionBus.Drawnings;
|
||||
using ProjectAccordionBus.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.CollectionGenericObjects;
|
||||
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
protected readonly int _placeSizeWidth = 240;
|
||||
|
||||
protected readonly int _placeSizeHeight = 60;
|
||||
|
||||
protected readonly int _pictureWidth;
|
||||
|
||||
protected readonly int _pictureHeight;
|
||||
|
||||
protected ICollectionGenericObjects<DrawningBus?> _collection = null;
|
||||
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
|
||||
public AbstractCompany(int picWidth, int picHeigth, ICollectionGenericObjects<DrawningBus> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeigth;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
public static int operator +(AbstractCompany company, DrawningBus bus)
|
||||
{
|
||||
return company._collection.Insert(bus);
|
||||
}
|
||||
|
||||
public static DrawningBus operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection.Remove(position);
|
||||
}
|
||||
|
||||
public DrawningBus? GetRandomObject()
|
||||
{
|
||||
Random rnd = new();
|
||||
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||
}
|
||||
|
||||
public Bitmap? Show()
|
||||
{
|
||||
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
DrawBackground(graphics);
|
||||
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
DrawningBus? obj = _collection?.Get(i);
|
||||
SetObjectPosition(i, _collection?.Count ?? 0, obj);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
protected abstract void DrawBackground(Graphics g);
|
||||
|
||||
protected abstract void SetObjectPosition(int position, int MaxPos, DrawningBus? bus);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using ProjectAccordionBus.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.CollectionGenericObjects;
|
||||
|
||||
public class BusSharingService : AbstractCompany
|
||||
{
|
||||
public BusSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBus> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected override 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; 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);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectPosition(int position, int MaxPos, DrawningBus? bus)
|
||||
{
|
||||
int n = 0;
|
||||
int m = 0;
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
if (_collection?.Get(i) != null)
|
||||
{
|
||||
int x = 5 + _placeSizeWidth * n;
|
||||
int y = (10 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m;
|
||||
|
||||
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(i)?.SetPosition(x, y);
|
||||
}
|
||||
|
||||
if (n < _pictureWidth / _placeSizeWidth)
|
||||
n++;
|
||||
else
|
||||
{
|
||||
n = 0;
|
||||
m++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс описания действий для набора хранимых объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Кол-во объектов в коллекци
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Установка максимального кол-ва объектов
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллецию
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
int Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
T? Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта из позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Параметризированный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов которые храним
|
||||
/// </summary>
|
||||
private T?[] _collection;
|
||||
|
||||
public int Count => _collection.Length;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_collection = Array.Empty<T?>();
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
|
||||
if (position >= _collection.Length || position < 0)
|
||||
return -1;
|
||||
|
||||
|
||||
if (_collection[position] != null)
|
||||
{
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
int nullIndex = -1;
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
nullIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Если пустого элемента нет, то выходим
|
||||
if (nullIndex < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
int j = nullIndex - 1;
|
||||
while (j >= position)
|
||||
{
|
||||
_collection[j + 1] = _collection[j];
|
||||
j--;
|
||||
}
|
||||
}
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
T temp = _collection[position];
|
||||
_collection[position] = null;
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus;
|
||||
|
||||
public class DrawningAccordionBus
|
||||
{
|
||||
public EntityAccordionBus? EntityAccordionBus { get; private set; }
|
||||
|
||||
private int? _pictureWidth;
|
||||
|
||||
private int? _pictureHeight;
|
||||
|
||||
private int? _startPosX;
|
||||
|
||||
private int? _startPosY;
|
||||
|
||||
private int _drawningAccordionBusWidth = 60;
|
||||
|
||||
private readonly int _drawningAccordionBusHeight = 50;
|
||||
|
||||
public void Init(EntityAccordionBus entity)
|
||||
{
|
||||
EntityAccordionBus = entity;
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_drawningAccordionBusWidth <= width && _drawningAccordionBusHeight <= height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
if (_startPosX + _drawningAccordionBusWidth > width)
|
||||
{
|
||||
_startPosX = width - _drawningAccordionBusWidth;
|
||||
}
|
||||
if (_startPosY + _drawningAccordionBusHeight > height)
|
||||
{
|
||||
_startPosY = height - _drawningAccordionBusHeight;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
if (x < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
|
||||
if (y < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
|
||||
if (x + _drawningAccordionBusWidth > _pictureWidth) {
|
||||
_startPosX = _pictureWidth - _drawningAccordionBusWidth;
|
||||
}
|
||||
|
||||
if (y + _drawningAccordionBusHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningAccordionBusHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAccordionBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityAccordionBus.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityAccordionBus.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityAccordionBus.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAccordionBus.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningAccordionBusWidth + EntityAccordionBus.Step < _pictureWidth.Value)
|
||||
{
|
||||
_startPosX += (int)EntityAccordionBus.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningAccordionBusHeight + EntityAccordionBus.Step < _pictureHeight.Value)
|
||||
{
|
||||
_startPosY += (int)EntityAccordionBus.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAccordionBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityAccordionBus.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityAccordionBus.BodyColor);
|
||||
|
||||
// границы автобуса
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 10, _startPosY.Value + 10, 50, 30);
|
||||
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 10, 50, 30);
|
||||
|
||||
// окна
|
||||
Brush brushBlue = new SolidBrush(Color.Blue);
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 15, _startPosY.Value + 15, 5, 10);
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 50, _startPosY.Value + 15, 5, 10);
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 40, _startPosY.Value + 15, 5, 10);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 15, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 15, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 15, 5, 10);
|
||||
|
||||
|
||||
|
||||
|
||||
// крылья
|
||||
if (EntityAccordionBus.Compartment)
|
||||
{
|
||||
_drawningAccordionBusWidth = 130;
|
||||
// отсек
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 70, _startPosY.Value + 10, 50, 30);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 15, 10, 20);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value + 10, 50, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 15, 10, 20);
|
||||
|
||||
// колеса
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 35, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 105, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 35, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 105, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
if (EntityAccordionBus.Entrance)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 88, _startPosY.Value + 20, 10, 20);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 88, _startPosY.Value + 20, 10, 20);
|
||||
}
|
||||
|
||||
if (EntityAccordionBus.Windows)
|
||||
{
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 75, _startPosY.Value + 15, 5, 10);
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 110, _startPosY.Value + 15, 5, 10);
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 100, _startPosY.Value + 15, 5, 10);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 15, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 110, _startPosY.Value + 15, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 15, 5, 10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// двери
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 28, _startPosY.Value + 20, 10, 20);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 28, _startPosY.Value + 20, 10, 20);
|
||||
|
||||
// колеса
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 15, _startPosY.Value + 35, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 45, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 35, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 35, 10, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,18 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus;
|
||||
namespace ProjectAccordionBus.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
@@ -0,0 +1,62 @@
|
||||
using ProjectAccordionBus.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace ProjectAccordionBus.Drawnings;
|
||||
|
||||
public class DrawningAccordionBus : DrawningBus
|
||||
{
|
||||
public DrawningAccordionBus(int speed, double weight, Color bodyColor, Color additionalColor, bool compartment, bool entrance, bool windows) : base(110, 40)
|
||||
{
|
||||
EntityBus = new EntityAccordionBus(speed, weight, bodyColor, additionalColor, compartment, entrance, windows);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBus == null || EntityBus is not EntityAccordionBus accordionBus || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(accordionBus.AdditionalColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
Brush brushBlue = new SolidBrush(Color.Blue);
|
||||
// отсек
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 60, _startPosY.Value, 50, 30);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 5, 10, 20);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value, 50, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 5, 10, 20);
|
||||
|
||||
// колеса
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 65, _startPosY.Value + 25, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 25, 10, 10);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 65, _startPosY.Value + 25, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 95, _startPosY.Value + 25, 10, 10);
|
||||
|
||||
if (accordionBus.Entrance)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 78, _startPosY.Value + 10, 10, 20);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 78, _startPosY.Value + 10, 10, 20);
|
||||
}
|
||||
|
||||
if (accordionBus.Windows)
|
||||
{
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 65, _startPosY.Value + 5, 5, 10);
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 100, _startPosY.Value + 5, 5, 10);
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 90, _startPosY.Value + 5, 5, 10);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 65, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 5, 5, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
217
ProjectAccordionBus/ProjectAccordionBus/Drawnings/DrawningBus.cs
Normal file
217
ProjectAccordionBus/ProjectAccordionBus/Drawnings/DrawningBus.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
using ProjectAccordionBus.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.Drawnings;
|
||||
public class DrawningBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBus? EntityBus { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки транспорта
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя координата прорисовки транспорта
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки транспорта
|
||||
/// </summary>
|
||||
private readonly int _drawningBusWidth = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки транспорта
|
||||
/// </summary>
|
||||
private readonly int _drawningBusHeight = 35;
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningBusWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHight => _drawningBusHeight;
|
||||
|
||||
// Пустой конструктор
|
||||
private DrawningBus()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
// Конструктор
|
||||
public DrawningBus(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityBus = new EntityBus(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
// Конструктор
|
||||
protected DrawningBus(int drawningBusWidth, int drawningBusHeight) : this()
|
||||
{
|
||||
_drawningBusWidth = drawningBusWidth;
|
||||
_drawningBusHeight = drawningBusHeight;
|
||||
}
|
||||
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_drawningBusWidth <= width && _drawningBusHeight <= height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
if (_startPosX + _drawningBusWidth > width)
|
||||
{
|
||||
_startPosX = width - _drawningBusWidth;
|
||||
}
|
||||
if (_startPosY + _drawningBusHeight > height)
|
||||
{
|
||||
_startPosY = height - _drawningBusHeight;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
if (x < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
|
||||
if (y < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
|
||||
if (x + _drawningBusWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningBusWidth;
|
||||
}
|
||||
|
||||
if (y + _drawningBusHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningBusHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityBus.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityBus.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityBus.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityBus.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningBusWidth + EntityBus.Step < _pictureWidth.Value)
|
||||
{
|
||||
_startPosX += (int)EntityBus.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningBusHeight + EntityBus.Step < _pictureHeight.Value)
|
||||
{
|
||||
_startPosY += (int)EntityBus.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(EntityBus.BodyColor);
|
||||
|
||||
// границы автобуса
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value, _startPosY.Value, 50, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 50, 30);
|
||||
|
||||
// окна
|
||||
Brush brushBlue = new SolidBrush(Color.Blue);
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 5, _startPosY.Value + 5, 5, 10);
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 40, _startPosY.Value + 5, 5, 10);
|
||||
g.FillEllipse(brushBlue, _startPosX.Value + 30, _startPosY.Value + 5, 5, 10);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 5, 5, 10);
|
||||
|
||||
// двери
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 18, _startPosY.Value + 10, 10, 20);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 18, _startPosY.Value + 10, 10, 20);
|
||||
|
||||
// колеса
|
||||
g.FillEllipse(bodyBrush, _startPosX.Value + 5, _startPosY.Value + 25, 10, 10);
|
||||
g.FillEllipse(bodyBrush, _startPosX.Value + 35, _startPosY.Value + 25, 10, 10);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 25, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 25, 10, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,12 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus;
|
||||
namespace ProjectAccordionBus.Entities;
|
||||
|
||||
public class EntityAccordionBus
|
||||
public class EntityAccordionBus : EntityBus
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
|
||||
public double Weight { get; private set; }
|
||||
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
public double Step => Speed * 50 / Weight;
|
||||
|
||||
public bool Compartment { get; private set; }
|
||||
|
||||
public bool Entrance { get; private set; }
|
||||
@@ -25,24 +17,18 @@ public class EntityAccordionBus
|
||||
public bool Windows { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// Инициализация полей объекта-класса accordion bus
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="compartment">Признак наличия доп. отсека с гармошкой</param>
|
||||
/// <param name="entrance">Признак наличия входа у доп. отсека</param>
|
||||
/// <param name="windows">Признак наличия окон у доп. отсека</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool compartment, bool entrance, bool windows)
|
||||
public EntityAccordionBus(int Speed, double Weight, Color bodyColor, Color additionalColor, bool compartment, bool entrance, bool windows) : base(Speed, Weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Compartment = compartment; // отсек
|
||||
Entrance = entrance; // крылья
|
||||
Entrance = entrance;
|
||||
Windows = windows;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace ProjectAccordionBus.Entities;
|
||||
public class EntityBus
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
|
||||
public double Weight { get; private set; }
|
||||
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
public double Step => Speed * 50 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public EntityBus(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
@@ -30,11 +30,12 @@
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormAccordionBus));
|
||||
pictureBoxAccordionBus = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonRight = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAccordionBus).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@@ -48,17 +49,6 @@
|
||||
pictureBoxAccordionBus.TabStop = false;
|
||||
pictureBoxAccordionBus.Click += pictureBoxAccordionBus_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 351);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@@ -107,16 +97,37 @@
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(595, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Location = new Point(641, 41);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(75, 23);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "Шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += buttonStrategyStep_Click;
|
||||
//
|
||||
// FormAccordionBus
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(728, 386);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxAccordionBus);
|
||||
Name = "FormAccordionBus";
|
||||
Text = "Сочленённый автобус";
|
||||
@@ -132,10 +143,11 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxAccordionBus;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using ProjectAccordionBus.Drawnings;
|
||||
using ProjectAccordionBus.Entities;
|
||||
using ProjectAccordionBus.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@@ -10,78 +13,112 @@ using System.Windows.Forms;
|
||||
|
||||
namespace ProjectAccordionBus;
|
||||
public partial class FormAccordionBus : Form
|
||||
{
|
||||
|
||||
private DrawningBus? _drawningBus;
|
||||
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public DrawningBus SetBus
|
||||
{
|
||||
|
||||
private DrawningAccordionBus? _drawningAccordionBus;
|
||||
|
||||
private EntityAccordionBus? _entity;
|
||||
|
||||
|
||||
public FormAccordionBus()
|
||||
set
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAccordionBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAccordionBus.DrawTransport(gr);
|
||||
pictureBoxAccordionBus.Image = bmp;
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningAccordionBus = new DrawningAccordionBus();
|
||||
_entity = new EntityAccordionBus();
|
||||
_entity.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningAccordionBus.Init(_entity);
|
||||
_drawningAccordionBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||
_drawningAccordionBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
|
||||
_drawningBus = value;
|
||||
_drawningBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAccordionBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningAccordionBus.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FormAccordionBus()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningBus.DrawTransport(gr);
|
||||
pictureBoxAccordionBus.Image = bmp;
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningBus.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningBus.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningBus.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningBus.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableBus(_drawningBus), pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
174
ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.Designer.cs
generated
Normal file
174
ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.Designer.cs
generated
Normal file
@@ -0,0 +1,174 @@
|
||||
namespace ProjectAccordionBus
|
||||
{
|
||||
partial class FormBusCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonDeleteBus = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddAccordionBus = new Button();
|
||||
buttonAddBus = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxTools.Controls.Add(buttonDeleteBus);
|
||||
groupBoxTools.Controls.Add(maskedTextBox);
|
||||
groupBoxTools.Controls.Add(buttonAddAccordionBus);
|
||||
groupBoxTools.Controls.Add(buttonAddBus);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(625, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(175, 450);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(6, 393);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(163, 33);
|
||||
buttonRefresh.TabIndex = 7;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += buttonRefresh_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(6, 327);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(163, 33);
|
||||
buttonGoToCheck.TabIndex = 6;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += buttonGoToCheck_Click;
|
||||
//
|
||||
// buttonDeleteBus
|
||||
//
|
||||
buttonDeleteBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonDeleteBus.Location = new Point(6, 269);
|
||||
buttonDeleteBus.Name = "buttonDeleteBus";
|
||||
buttonDeleteBus.Size = new Size(163, 33);
|
||||
buttonDeleteBus.TabIndex = 5;
|
||||
buttonDeleteBus.Text = "Удаление автобуса";
|
||||
buttonDeleteBus.UseVisualStyleBackColor = true;
|
||||
buttonDeleteBus.Click += buttonDeleteBus_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBox.Location = new Point(6, 219);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(163, 23);
|
||||
maskedTextBox.TabIndex = 5;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddAccordionBus
|
||||
//
|
||||
buttonAddAccordionBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddAccordionBus.Location = new Point(6, 141);
|
||||
buttonAddAccordionBus.Name = "buttonAddAccordionBus";
|
||||
buttonAddAccordionBus.Size = new Size(163, 45);
|
||||
buttonAddAccordionBus.TabIndex = 3;
|
||||
buttonAddAccordionBus.Text = "Добавление автобуса-гармошки";
|
||||
buttonAddAccordionBus.UseVisualStyleBackColor = true;
|
||||
buttonAddAccordionBus.Click += buttonAddAccordionBus_Click;
|
||||
//
|
||||
// buttonAddBus
|
||||
//
|
||||
buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddBus.Location = new Point(6, 90);
|
||||
buttonAddBus.Name = "buttonAddBus";
|
||||
buttonAddBus.Size = new Size(163, 45);
|
||||
buttonAddBus.TabIndex = 2;
|
||||
buttonAddBus.Text = "Добавление автобуса";
|
||||
buttonAddBus.UseVisualStyleBackColor = true;
|
||||
buttonAddBus.Click += buttonAddBus_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(6, 22);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(163, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 1;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(625, 450);
|
||||
pictureBox.TabIndex = 4;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormBusCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormBusCollection";
|
||||
Text = "Коллекция автобусов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private Button buttonAddAccordionBus;
|
||||
private Button buttonAddBus;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
private Button buttonDeleteBus;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
}
|
||||
}
|
||||
169
ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.cs
Normal file
169
ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using ProjectAccordionBus.CollectionGenericObjects;
|
||||
using ProjectAccordionBus.Drawnings;
|
||||
using System;
|
||||
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;
|
||||
|
||||
namespace ProjectAccordionBus;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class FormBusCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormBusCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление улучшенного троллейбуса
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddAccordionBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAccordionBus));
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создания объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Random random = new();
|
||||
DrawningBus drawningBus;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBus):
|
||||
drawningBus = new DrawningBus(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawningAccordionBus):
|
||||
drawningBus = new DrawningAccordionBus(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawningBus != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор цвета
|
||||
/// </summary>
|
||||
/// <param name="random"></param>
|
||||
/// <returns></returns>
|
||||
private static Color GetColor(Random random)
|
||||
{
|
||||
Color color = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
private void buttonAddBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningBus));
|
||||
}
|
||||
|
||||
private void buttonAddAccordionBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningAccordionBus));
|
||||
}
|
||||
|
||||
private void buttonDeleteBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удалён");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null) return;
|
||||
|
||||
DrawningBus? bus = null;
|
||||
int counter = 100;
|
||||
while (bus == null || counter > 0)
|
||||
{
|
||||
bus = _company.GetRandomObject();
|
||||
counter--;
|
||||
}
|
||||
|
||||
if (bus == null) return;
|
||||
|
||||
FormAccordionBus form = new()
|
||||
{
|
||||
SetBus = bus
|
||||
};
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
|
||||
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new BusSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningBus>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
120
ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.resx
Normal file
120
ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.MovementStrategy;
|
||||
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsTargetDestination())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместится, false - неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместится, false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместится, false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместится, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
protected abstract bool IsTargetDestination();
|
||||
|
||||
protected bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.MovementStrategy;
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Попытка переместить объект в указанном направлении
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.MovementStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestination()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objParams.RightBorder <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
|
||||
int diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.MovementStrategy;
|
||||
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestination()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using ProjectAccordionBus.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.MovementStrategy;
|
||||
|
||||
public class MoveableBus : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningBus или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningBus? _bus = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="bus">Объект класса DrawningBus</param>
|
||||
public MoveableBus(DrawningBus bus)
|
||||
{
|
||||
_bus = bus;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_bus == null || _bus.EntityBus == null || !_bus.GetPosX.HasValue || !_bus.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_bus.GetPosX.Value, _bus.GetPosY.Value, _bus.GetWidth, _bus.GetHight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_bus?.EntityBus?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_bus == null || _bus.EntityBus == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _bus.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
MovementDirection.Left => DirectionType.Left,
|
||||
MovementDirection.Right => DirectionType.Right,
|
||||
MovementDirection.Up => DirectionType.Up,
|
||||
MovementDirection.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknow,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.MovementStrategy;
|
||||
public enum MovementDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.MovementStrategy;
|
||||
public class ObjectParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Координата x
|
||||
/// </summary>
|
||||
private readonly int _x;
|
||||
|
||||
/// <summary>
|
||||
/// Координата y
|
||||
/// </summary>
|
||||
private readonly int _y;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
private readonly int _width;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAccordionBus.MovementStrategy;
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Все готово к началу
|
||||
NotInit,
|
||||
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace ProjectAccordionBus
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormAccordionBus());
|
||||
Application.Run(new FormBusCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user