Лабораторная работа №3
This commit is contained in:
parent
fc34842ef1
commit
8b33c79a8b
@ -2,7 +2,7 @@
|
||||
|
||||
namespace ProjectCleaningCar.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Абстракция компании, хранящая коллекцию автомобилей
|
||||
/// Абстракция компании, хранящая коллекцию грузовиков
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
@ -25,18 +25,18 @@ public abstract class AbstractCompany
|
||||
/// <summary>
|
||||
/// Коллекция машин
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawningCar>? _collection = null;
|
||||
protected ICollectionGenericObjects<DrawningTruck>? _collection = null;
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
private int GetMaxCount => _pictureWidth / _placeSizeWidth * (_pictureHeight / _placeSizeHeight / 2);
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth">Ширина окна</param>
|
||||
/// <param name="picHeight">Высота окна</param>
|
||||
/// <param name="collection">Коллекция машин</param>
|
||||
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningCar> collection)
|
||||
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTruck> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
@ -49,9 +49,9 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="car">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(AbstractCompany company, DrawningCar car)
|
||||
public static int operator +(AbstractCompany company, DrawningTruck car)
|
||||
{
|
||||
return company._collection?.Insert(car) ?? false;
|
||||
return company._collection.Insert(car);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
@ -59,15 +59,15 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(AbstractCompany company, int position)
|
||||
public static DrawningTruck operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position) ?? false;
|
||||
return company._collection.Remove(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawningCar? GetRandomObject()
|
||||
public DrawningTruck? GetRandomObject()
|
||||
{
|
||||
Random random = new();
|
||||
return _collection?.Get(random.Next(GetMaxCount));
|
||||
@ -84,7 +84,7 @@ public abstract class AbstractCompany
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
DrawningCar? obj = _collection?.Get(i);
|
||||
DrawningTruck? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
return bitmap;
|
||||
|
@ -4,9 +4,9 @@ using System.Drawing;
|
||||
|
||||
namespace ProjectCleaningCar.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Реализация абстрактной компании каршеринг
|
||||
/// Реализация абстрактной компании автопарк
|
||||
/// </summary>
|
||||
public class CarSharingService : AbstractCompany
|
||||
public class AutoParkService : AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -14,7 +14,7 @@ public class CarSharingService : AbstractCompany
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="collection"></param>
|
||||
public CarSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningCar> collection) : base(picWidth, picHeight, collection)
|
||||
public AutoParkService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTruck> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
|
||||
}
|
@ -19,20 +19,20 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
bool Insert(T obj);
|
||||
int Insert(T obj);
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
bool Insert(T obj, int position);
|
||||
int Insert(T obj, int position);
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
bool Remove(int position);
|
||||
T? Remove(int position);
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
/// </summary>
|
||||
|
@ -35,60 +35,61 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (position < 0 || position >= Count) return null;
|
||||
return _collection[position];
|
||||
}
|
||||
public bool Insert(T obj)
|
||||
public int Insert(T obj)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
// TODO вставка в свободное место набора
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
public bool Insert(T obj, int position)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// если нет после, ищем до
|
||||
// TODO вставка
|
||||
if (position >= Count || position < 0) return false;
|
||||
if (position >= Count || position < 0) return -1;
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return true;
|
||||
return position;
|
||||
}
|
||||
int temp = position + 1;
|
||||
while(temp < Count)
|
||||
while(temp < Count)
|
||||
{
|
||||
if (_collection[temp] == null)
|
||||
{
|
||||
_collection[temp] = obj;
|
||||
return true;
|
||||
return temp;
|
||||
}
|
||||
++temp;
|
||||
}
|
||||
temp = position - 1;
|
||||
while(temp > 0)
|
||||
while(temp >= 0)
|
||||
{
|
||||
if (_collection[temp] == null)
|
||||
{
|
||||
_collection[temp] = obj;
|
||||
return true;
|
||||
return temp;
|
||||
}
|
||||
--temp;
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (position >= Count || position < 0) return false;
|
||||
if (position >= Count || position < 0) return null;
|
||||
T? myObject = _collection[position];
|
||||
_collection[position] = null;
|
||||
return true;
|
||||
return myObject;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace ProjectCleaningCar.Drawning;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningCleaningCar : DrawningCar
|
||||
public class DrawningCleaningCar : DrawningTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -18,7 +18,7 @@ public class DrawningCleaningCar : DrawningCar
|
||||
/// <param name="flashlight">Проблескового маячок</param>
|
||||
public DrawningCleaningCar(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool sweepingBrush, bool flashlight) : base(132, 65)
|
||||
{
|
||||
EntityCar = new EntityCleaningCar(speed, weight, bodyColor, additionalColor, tank, sweepingBrush, flashlight);
|
||||
EntityTruck = new EntityCleaningCar(speed, weight, bodyColor, additionalColor, tank, sweepingBrush, flashlight);
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовка объекта
|
||||
@ -26,13 +26,13 @@ public class DrawningCleaningCar : DrawningCar
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCar == null || EntityCar is not EntityCleaningCar cleaningCar || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityTruck == null || EntityTruck is not EntityCleaningCar cleaningCar || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(EntityCar.BodyColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityTruck.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(cleaningCar.AdditionalColor);
|
||||
//бак
|
||||
if (cleaningCar.Tank)
|
||||
|
@ -4,12 +4,12 @@ namespace ProjectCleaningCar.Drawning;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку базового объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningCar
|
||||
public class DrawningTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityCar? EntityCar { get; protected set; }
|
||||
public EntityTruck? EntityTruck { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -29,11 +29,11 @@ public class DrawningCar
|
||||
/// <summary>
|
||||
/// Ширина прорисовки машины
|
||||
/// </summary>
|
||||
private readonly int _drawningCarWidth = 130;
|
||||
private readonly int _drawningTruckWidth = 130;
|
||||
/// <summary>
|
||||
/// Высота прорисовки машины
|
||||
/// </summary>
|
||||
private readonly int _drawningCarHeight = 65;
|
||||
private readonly int _drawningTruckHeight = 65;
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
@ -45,15 +45,15 @@ public class DrawningCar
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningCarWidth;
|
||||
public int GetWidth => _drawningTruckWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningCarHeight;
|
||||
public int GetHeight => _drawningTruckHeight;
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningCar()
|
||||
private DrawningTruck()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
@ -66,19 +66,19 @@ public class DrawningCar
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningCar(int speed, double weight, Color bodyColor) : this()
|
||||
public DrawningTruck(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityCar = new EntityCar(speed, weight, bodyColor);
|
||||
EntityTruck = new EntityTruck(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningCarWidth">Ширина прорисовки машины</param>
|
||||
/// <param name="drawningCarHeight">Высота прорисовки машины</param>
|
||||
protected DrawningCar(int drawningCarWidth, int drawningCarHeight) : this()
|
||||
/// <param name="drawningTruckWidth">Ширина прорисовки машины</param>
|
||||
/// <param name="drawningTruckHeight">Высота прорисовки машины</param>
|
||||
protected DrawningTruck(int drawningTruckWidth, int drawningTruckHeight) : this()
|
||||
{
|
||||
_drawningCarWidth = drawningCarWidth;
|
||||
_drawningCarHeight = drawningCarHeight;
|
||||
_drawningTruckWidth = drawningTruckWidth;
|
||||
_drawningTruckHeight = drawningTruckHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
@ -90,22 +90,22 @@ public class DrawningCar
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
|
||||
if (width < _drawningCarWidth || height < _drawningCarHeight) { return false; };
|
||||
if (width < _drawningTruckWidth || height < _drawningTruckHeight) { return false; };
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX != null || _startPosY != null)
|
||||
{
|
||||
if (_startPosX + _drawningCarWidth > _pictureWidth)
|
||||
if (_startPosX + _drawningTruckWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = -_drawningCarWidth + _pictureWidth;
|
||||
_startPosX = -_drawningTruckWidth + _pictureWidth;
|
||||
}
|
||||
else if (_startPosX < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_startPosY + _drawningCarHeight > _pictureHeight)
|
||||
if (_startPosY + _drawningTruckHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = -_drawningCarHeight + _pictureHeight;
|
||||
_startPosY = -_drawningTruckHeight + _pictureHeight;
|
||||
}
|
||||
else if (_startPosY < 0)
|
||||
{
|
||||
@ -127,9 +127,9 @@ public class DrawningCar
|
||||
return;
|
||||
}
|
||||
|
||||
if (x + _drawningCarWidth > _pictureWidth)
|
||||
if (x + _drawningTruckWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningCarWidth;
|
||||
_startPosX = _pictureWidth - _drawningTruckWidth;
|
||||
}
|
||||
else if (x < 0)
|
||||
{
|
||||
@ -140,9 +140,9 @@ public class DrawningCar
|
||||
_startPosX = x;
|
||||
}
|
||||
|
||||
if (y + _drawningCarHeight > _pictureHeight)
|
||||
if (y + _drawningTruckHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningCarHeight;
|
||||
_startPosY = _pictureHeight - _drawningTruckHeight;
|
||||
}
|
||||
else if (y < 0)
|
||||
{
|
||||
@ -161,7 +161,7 @@ public class DrawningCar
|
||||
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityCar == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityTruck == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -169,30 +169,30 @@ public class DrawningCar
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityCar.Step > 0)
|
||||
if (_startPosX.Value - EntityTruck.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityCar.Step;
|
||||
_startPosX -= (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
//вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningCarWidth + EntityCar.Step < _pictureWidth)
|
||||
if (_startPosX.Value + _drawningTruckWidth + EntityTruck.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityCar.Step;
|
||||
_startPosX += (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityCar.Step > 0)
|
||||
if (_startPosY.Value - EntityTruck.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityCar.Step;
|
||||
_startPosY -= (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningCarHeight + EntityCar.Step < _pictureHeight)
|
||||
if (_startPosY.Value + _drawningTruckHeight + EntityTruck.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityCar.Step;
|
||||
_startPosY += (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -206,12 +206,12 @@ public class DrawningCar
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCar == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityTruck == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(EntityCar.BodyColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityTruck.BodyColor);
|
||||
//основание
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value, _startPosY.Value + 35, 120, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 35, 120, 10);
|
@ -2,7 +2,7 @@
|
||||
/// <summary>
|
||||
/// Класс-сущность "Подметательно-уборочная машина"
|
||||
/// </summary>
|
||||
public class EntityCleaningCar : EntityCar
|
||||
public class EntityCleaningCar : EntityTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
|
@ -1,8 +1,8 @@
|
||||
namespace ProjectCleaningCar.Entities;
|
||||
/// <summary>
|
||||
/// Класс-сущность "Машина"
|
||||
/// Класс-сущность "Грузовик"
|
||||
/// </summary>
|
||||
public class EntityCar
|
||||
public class EntityTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -17,17 +17,17 @@ public class EntityCar
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения подметательно-уборочной машины
|
||||
/// Шаг перемещения грузовика
|
||||
/// </summary>
|
||||
public double Step => Speed * 200 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса подметально-уборочной машины
|
||||
/// Инициализация полей объекта-класса грузовик
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityCar(int speed, double weight, Color bodyColor)
|
||||
public EntityTruck(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
@ -10,7 +10,7 @@ public partial class FormCleaningCar : Form
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningCar? _drawningCar;
|
||||
private DrawningTruck? _drawningTruck;
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
@ -18,12 +18,12 @@ public partial class FormCleaningCar : Form
|
||||
/// <summary>
|
||||
/// Получение объекта
|
||||
/// </summary>
|
||||
public DrawningCar SetCar
|
||||
public DrawningTruck SetCar
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawningCar = value;
|
||||
_drawningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
|
||||
_drawningTruck = value;
|
||||
_drawningTruck.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
@ -42,14 +42,14 @@ public partial class FormCleaningCar : Form
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningCar == null)
|
||||
if (_drawningTruck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxCleaningCar.Width,
|
||||
pictureBoxCleaningCar.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningCar.DrawTransport(gr);
|
||||
_drawningTruck.DrawTransport(gr);
|
||||
pictureBoxCleaningCar.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
@ -59,7 +59,7 @@ public partial class FormCleaningCar : Form
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCar == null)
|
||||
if (_drawningTruck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -68,16 +68,16 @@ public partial class FormCleaningCar : Form
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningCar.MoveTransport(DirectionType.Up);
|
||||
result = _drawningTruck.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningCar.MoveTransport(DirectionType.Down);
|
||||
result = _drawningTruck.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningCar.MoveTransport(DirectionType.Left);
|
||||
result = _drawningTruck.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningCar.MoveTransport(DirectionType.Right);
|
||||
result = _drawningTruck.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
@ -92,7 +92,7 @@ public partial class FormCleaningCar : Form
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCar == null)
|
||||
if (_drawningTruck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -108,7 +108,7 @@ public partial class FormCleaningCar : Form
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableCar(_drawningCar),
|
||||
_strategy.SetData(new MoveableCar(_drawningTruck),
|
||||
pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
|
||||
}
|
||||
if (_strategy == null)
|
||||
|
@ -34,7 +34,7 @@
|
||||
buttonDelCar = new Button();
|
||||
maskedTextBoxPosition = new MaskedTextBox();
|
||||
buttonAddCleaningCar = new Button();
|
||||
buttonAddCar = new Button();
|
||||
buttonAddTruck = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
tools.SuspendLayout();
|
||||
@ -48,7 +48,7 @@
|
||||
tools.Controls.Add(buttonDelCar);
|
||||
tools.Controls.Add(maskedTextBoxPosition);
|
||||
tools.Controls.Add(buttonAddCleaningCar);
|
||||
tools.Controls.Add(buttonAddCar);
|
||||
tools.Controls.Add(buttonAddTruck);
|
||||
tools.Controls.Add(comboBoxSelectorCompany);
|
||||
tools.Dock = DockStyle.Right;
|
||||
tools.Location = new Point(752, 0);
|
||||
@ -108,23 +108,23 @@
|
||||
buttonAddCleaningCar.UseVisualStyleBackColor = true;
|
||||
buttonAddCleaningCar.Click += ButtonAddCleaningCar_Click;
|
||||
//
|
||||
// buttonAddCar
|
||||
// buttonAddTruck
|
||||
//
|
||||
buttonAddCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddCar.Location = new Point(24, 70);
|
||||
buttonAddCar.Name = "buttonAddCar";
|
||||
buttonAddCar.Size = new Size(163, 38);
|
||||
buttonAddCar.TabIndex = 1;
|
||||
buttonAddCar.Text = "Добавление машины";
|
||||
buttonAddCar.UseVisualStyleBackColor = true;
|
||||
buttonAddCar.Click += ButtonAddCar_Click;
|
||||
buttonAddTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddTruck.Location = new Point(24, 70);
|
||||
buttonAddTruck.Name = "buttonAddTruck";
|
||||
buttonAddTruck.Size = new Size(163, 38);
|
||||
buttonAddTruck.TabIndex = 1;
|
||||
buttonAddTruck.Text = "Добавление грузовика";
|
||||
buttonAddTruck.UseVisualStyleBackColor = true;
|
||||
buttonAddTruck.Click += ButtonAddTruck_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Автопарк" });
|
||||
comboBoxSelectorCompany.Location = new Point(24, 22);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(163, 23);
|
||||
@ -158,7 +158,7 @@
|
||||
#endregion
|
||||
|
||||
private GroupBox tools;
|
||||
private Button buttonAddCar;
|
||||
private Button buttonAddTruck;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonAddCleaningCar;
|
||||
|
@ -27,18 +27,18 @@ public partial class FormCleaningCarCollection : Form
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new CarSharingService(pictureBox.Width,
|
||||
pictureBox.Height, new MassiveGenericObjects<DrawningCar>());
|
||||
case "Автопарк":
|
||||
_company = new AutoParkService(pictureBox.Width,
|
||||
pictureBox.Height, new MassiveGenericObjects<DrawningTruck>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление спортивного автомобиля
|
||||
/// Добавление грузовика
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCar));
|
||||
private void ButtonAddTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck));
|
||||
/// <summary>
|
||||
/// Добавление подметательно-уборочной машины
|
||||
/// </summary>
|
||||
@ -56,16 +56,16 @@ public partial class FormCleaningCarCollection : Form
|
||||
return;
|
||||
}
|
||||
Random random = new();
|
||||
DrawningCar drawningCar;
|
||||
DrawningTruck drawningTruck;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningCar):
|
||||
drawningCar = new DrawningCar(random.Next(100, 300),
|
||||
case nameof(DrawningTruck):
|
||||
drawningTruck = new DrawningTruck(random.Next(100, 300),
|
||||
random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawningCleaningCar):
|
||||
// TODO вызов диалогового окна для выбора цвета
|
||||
drawningCar = new DrawningCleaningCar(random.Next(100, 300), random.Next(1000, 3000),
|
||||
drawningTruck = new DrawningCleaningCar(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)));
|
||||
@ -73,7 +73,7 @@ public partial class FormCleaningCarCollection : Form
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (_company + drawningCar)
|
||||
if (_company + drawningTruck != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -115,7 +115,7 @@ public partial class FormCleaningCarCollection : Form
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_company - pos)
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -137,20 +137,20 @@ public partial class FormCleaningCarCollection : Form
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawningCar? car = null;
|
||||
DrawningTruck? truck = null;
|
||||
int counter = 100;
|
||||
while (car == null)
|
||||
while (truck == null)
|
||||
{
|
||||
car = _company.GetRandomObject();
|
||||
truck = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0) break;
|
||||
}
|
||||
if (car == null)
|
||||
if (truck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormCleaningCar form = new FormCleaningCar();
|
||||
form.SetCar = car;
|
||||
form.SetCar = truck;
|
||||
form.ShowDialog();
|
||||
}
|
||||
/// <summary>
|
||||
@ -164,24 +164,24 @@ public partial class FormCleaningCarCollection : Form
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawningCar? car = null;
|
||||
DrawningTruck? truck = null;
|
||||
int counter = 100;
|
||||
while (car == null)
|
||||
while (truck == null)
|
||||
{
|
||||
car = _company.GetRandomObject();
|
||||
truck = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (car == null)
|
||||
if (truck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormCleaningCar form = new()
|
||||
{
|
||||
SetCar = car
|
||||
SetCar = truck
|
||||
};
|
||||
form.ShowDialog();
|
||||
|
||||
|
@ -2,41 +2,41 @@
|
||||
|
||||
namespace ProjectCleaningCar.MovementStrategy;
|
||||
/// <summary>
|
||||
/// Класс-реализация IMoveableObject с использованием DrawningCar
|
||||
/// Класс-реализация IMoveableObject с использованием DrawningTruck
|
||||
/// </summary>
|
||||
public class MoveableCar : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningCar или его наследника
|
||||
/// Поле-объект класса DrawningTruck или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningCar? _car = null;
|
||||
private readonly DrawningTruck? _truck = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="car">Объект класса DrawningCar</param>
|
||||
public MoveableCar(DrawningCar car)
|
||||
/// <param name="truck">Объект класса DrawningTruck</param>
|
||||
public MoveableCar(DrawningTruck truck)
|
||||
{
|
||||
_car = car;
|
||||
_truck = truck;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_car == null || _car.EntityCar == null || !_car.GetPosX.HasValue || !_car.GetPosY.HasValue)
|
||||
if (_truck == null || _truck.EntityTruck == null || !_truck.GetPosX.HasValue || !_truck.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_car.GetPosX.Value, _car.GetPosY.Value, _car.GetWidth, _car.GetHeight);
|
||||
return new ObjectParameters(_truck.GetPosX.Value, _truck.GetPosY.Value, _truck.GetWidth, _truck.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_car?.EntityCar?.Step ?? 0);
|
||||
public int GetStep => (int)(_truck?.EntityTruck?.Step ?? 0);
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_car == null || _car.EntityCar == null)
|
||||
if (_truck == null || _truck.EntityTruck == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _car.MoveTransport(GetDirectionType(direction));
|
||||
return _truck.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
|
Loading…
x
Reference in New Issue
Block a user