Добавление родителей и ввод конструкторов
This commit is contained in:
parent
8861b13b44
commit
527d87741a
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectTrolleybus;
|
namespace ProjectTrolleybus.Drawnings;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
@ -1,14 +1,18 @@
|
|||||||
namespace ProjectTrolleybus;
|
using ProjectTrolleybus.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
/// <summary>
|
namespace ProjectTrolleybus.Drawnings;
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
|
||||||
/// </summary>
|
public class DrawningTrolleyB
|
||||||
public class DrawningTrolleybus
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityTrolleybus? EntityTrolleybus { get; private set; }
|
public EntityTrolleyB? EntityTrolleyB { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
@ -23,42 +27,57 @@ public class DrawningTrolleybus
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки транспорта
|
/// Левая координата прорисовки транспорта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosX;
|
protected int? _startPosX;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя координата прорисовки транспорта
|
/// Верхняя координата прорисовки транспорта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosY;
|
protected int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки транспорта
|
/// Ширина прорисовки транспорта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningVehicleWidth = 100;
|
private readonly int _drawningVehicleWidth = 90;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки транспорта
|
/// Высота прорисовки транспорта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningVehicleHeight = 48;
|
private readonly int _drawningVehicleHeight = 33;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Пустой конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed"></param>
|
private DrawningTrolleyB()
|
||||||
/// <param name="weight"></param>
|
|
||||||
/// <param name="bodyColor"></param>
|
|
||||||
/// <param name="additionalColor"></param>
|
|
||||||
/// <param name="batteryCompartment"></param>
|
|
||||||
/// <param name="horns"></param>
|
|
||||||
///
|
|
||||||
public void Init(EntityTrolleybus _Tr)
|
|
||||||
{
|
{
|
||||||
EntityTrolleybus = _Tr;
|
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = null;
|
_startPosY = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public DrawningTrolleyB(int speed, double weight, Color bodyColor) : this()
|
||||||
|
{
|
||||||
|
EntityTrolleyB = new EntityTrolleyB(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор для наследников
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningVehicleWidth">Ширина прорисовки транспорта</param>
|
||||||
|
/// <param name="drawningVehicleHeight">Высота прорисовки транспорта</param>
|
||||||
|
protected DrawningTrolleyB(int drawningVehicleWidth, int drawningVehicleHeight) : this()
|
||||||
|
{
|
||||||
|
_drawningVehicleWidth = drawningVehicleWidth;
|
||||||
|
_drawningVehicleHeight = drawningVehicleHeight;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -102,7 +121,6 @@ public class DrawningTrolleybus
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
|
||||||
//то надо изменить координаты, чтобы он оставался в этих границах
|
//то надо изменить координаты, чтобы он оставался в этих границах
|
||||||
if (x + _drawningVehicleWidth > _pictureWidth)
|
if (x + _drawningVehicleWidth > _pictureWidth)
|
||||||
{
|
{
|
||||||
@ -127,7 +145,7 @@ public class DrawningTrolleybus
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool MoveVehicle(DirectionType direction)
|
public bool MoveVehicle(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityTrolleybus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityTrolleyB == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -136,33 +154,33 @@ public class DrawningTrolleybus
|
|||||||
{
|
{
|
||||||
// влево
|
// влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntityTrolleybus.Step > 0)
|
if (_startPosX.Value - EntityTrolleyB.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityTrolleybus.Step;
|
_startPosX -= (int)EntityTrolleyB.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
// вверх
|
// вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntityTrolleybus.Step > 0)
|
if (_startPosY.Value - EntityTrolleyB.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityTrolleybus.Step;
|
_startPosY -= (int)EntityTrolleyB.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
{
|
{
|
||||||
if (_startPosX.Value + _drawningVehicleWidth + EntityTrolleybus.Step < _pictureWidth)
|
if (_startPosX.Value + _drawningVehicleWidth + EntityTrolleyB.Step < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityTrolleybus.Step;
|
_startPosX += (int)EntityTrolleyB.Step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
// вниз
|
// вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
{
|
{
|
||||||
if (_startPosY.Value + _drawningVehicleHeight + EntityTrolleybus.Step < _pictureHeight)
|
if (_startPosY.Value + _drawningVehicleHeight + EntityTrolleyB.Step < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityTrolleybus.Step;
|
_startPosY += (int)EntityTrolleyB.Step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -175,9 +193,9 @@ public class DrawningTrolleybus
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityTrolleybus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityTrolleyB == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -186,68 +204,44 @@ public class DrawningTrolleybus
|
|||||||
|
|
||||||
//Колёса
|
//Колёса
|
||||||
pen.Width = 2;
|
pen.Width = 2;
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 36, 12, 12);
|
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 21, 12, 12);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 36, 12, 12);
|
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 21, 12, 12);
|
||||||
pen.Width = 1;
|
pen.Width = 1;
|
||||||
Brush brBlackWheel = new SolidBrush(Color.Black);
|
Brush brBlackWheel = new SolidBrush(Color.Black);
|
||||||
g.FillEllipse(brBlackWheel, _startPosX.Value + 20, _startPosY.Value + 36, 12, 12);
|
g.FillEllipse(brBlackWheel, _startPosX.Value + 10, _startPosY.Value + 21, 12, 12);
|
||||||
g.FillEllipse(brBlackWheel, _startPosX.Value + 80, _startPosY.Value + 36, 12, 12);
|
g.FillEllipse(brBlackWheel, _startPosX.Value + 70, _startPosY.Value + 21, 12, 12);
|
||||||
Brush brYelWheel = new SolidBrush(Color.Goldenrod);
|
Brush brYelWheel = new SolidBrush(Color.Goldenrod);
|
||||||
g.FillEllipse(brYelWheel, _startPosX.Value + 22, _startPosY.Value + 38, 8, 8);
|
g.FillEllipse(brYelWheel, _startPosX.Value + 12, _startPosY.Value + 23, 8, 8);
|
||||||
g.FillEllipse(brYelWheel, _startPosX.Value + 82, _startPosY.Value + 38, 8, 8);
|
g.FillEllipse(brYelWheel, _startPosX.Value + 72, _startPosY.Value + 23, 8, 8);
|
||||||
|
|
||||||
//Кузов
|
//Кузов
|
||||||
Brush br = new SolidBrush(EntityTrolleybus.BodyColor);
|
Brush br = new SolidBrush(EntityTrolleyB.BodyColor);
|
||||||
g.FillRectangle(br, _startPosX.Value + 11, _startPosY.Value + 16, 89, 24);
|
g.FillRectangle(br, _startPosX.Value + 1, _startPosY.Value + 1, 89, 24);
|
||||||
|
|
||||||
//Границы Автомобиля
|
//Границы Автомобиля
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, 90, 25);
|
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 90, 25);
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 36, _startPosY.Value + 25, 10, 15);
|
g.DrawRectangle(pen, _startPosX.Value + 26, _startPosY.Value + 10, 10, 15);
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 88, _startPosY.Value + 19, 12, 12);
|
g.DrawRectangle(pen, _startPosX.Value + 78, _startPosY.Value + 4, 12, 12);
|
||||||
pen.Width = 2;
|
pen.Width = 2;
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 12, _startPosY.Value + 20, 8, 10);
|
g.DrawEllipse(pen, _startPosX.Value + 2, _startPosY.Value + 5, 8, 10);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 24, _startPosY.Value + 20, 8, 10);
|
g.DrawEllipse(pen, _startPosX.Value + 14, _startPosY.Value + 5, 8, 10);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 20, 8, 10);
|
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 5, 8, 10);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 62, _startPosY.Value + 20, 8, 10);
|
g.DrawEllipse(pen, _startPosX.Value + 52, _startPosY.Value + 5, 8, 10);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 74, _startPosY.Value + 20, 8, 10);
|
g.DrawEllipse(pen, _startPosX.Value + 64, _startPosY.Value + 5, 8, 10);
|
||||||
pen.Width = 1;
|
pen.Width = 1;
|
||||||
|
|
||||||
//Стекла и кабина
|
//Стекла и кабина
|
||||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||||
g.FillRectangle(brBlue, _startPosX.Value + 89, _startPosY.Value + 20, 11, 11);
|
g.FillRectangle(brBlue, _startPosX.Value + 79, _startPosY.Value + 5, 11, 11);
|
||||||
g.FillEllipse(brBlue, _startPosX.Value + 12, _startPosY.Value + 20, 8, 10);
|
g.FillEllipse(brBlue, _startPosX.Value + 2, _startPosY.Value + 5, 8, 10);
|
||||||
g.FillEllipse(brBlue, _startPosX.Value + 24, _startPosY.Value + 20, 8, 10);
|
g.FillEllipse(brBlue, _startPosX.Value + 14, _startPosY.Value + 5, 8, 10);
|
||||||
g.FillEllipse(brBlue, _startPosX.Value + 50, _startPosY.Value + 20, 8, 10);
|
g.FillEllipse(brBlue, _startPosX.Value + 40, _startPosY.Value + 5, 8, 10);
|
||||||
g.FillEllipse(brBlue, _startPosX.Value + 62, _startPosY.Value + 20, 8, 10);
|
g.FillEllipse(brBlue, _startPosX.Value + 52, _startPosY.Value + 5, 8, 10);
|
||||||
g.FillEllipse(brBlue, _startPosX.Value + 74, _startPosY.Value + 20, 8, 10);
|
g.FillEllipse(brBlue, _startPosX.Value + 64, _startPosY.Value + 5, 8, 10);
|
||||||
|
|
||||||
//Дверь
|
//Дверь
|
||||||
Brush brBlack = new SolidBrush(Color.LightGray);
|
Brush brBlack = new SolidBrush(Color.LightGray);
|
||||||
g.FillRectangle(brBlack, _startPosX.Value + 37, _startPosY.Value + 26, 9, 14);
|
g.FillRectangle(brBlack, _startPosX.Value + 27, _startPosY.Value + 11, 9, 14);
|
||||||
|
|
||||||
Brush additBrush = new SolidBrush(EntityTrolleybus.AdditionalColor);
|
|
||||||
|
|
||||||
// "Рога" для проводов
|
|
||||||
if (EntityTrolleybus.Horns)
|
|
||||||
{
|
|
||||||
pen.Width = 2;
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 15, _startPosX.Value + 52, _startPosY.Value + 2);
|
|
||||||
pen.Width = 1;
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 34, _startPosY.Value, 20, 5);
|
|
||||||
|
|
||||||
g.FillRectangle(additBrush, _startPosX.Value + 35, _startPosY.Value + 1, 19, 4);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Отсек под батареи
|
|
||||||
if (EntityTrolleybus.BatteryCompartment)
|
|
||||||
{
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 24, 10, 12);
|
|
||||||
|
|
||||||
g.FillRectangle(additBrush, _startPosX.Value + 1, _startPosY.Value + 25, 9, 11);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
using ProjectTrolleybus.Entities;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace ProjectTrolleybus.Drawnings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningTrolleybus : DrawningTrolleyB
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed"></param>
|
||||||
|
/// <param name="weight"></param>
|
||||||
|
/// <param name="bodyColor"></param>
|
||||||
|
/// <param name="additionalColor"></param>
|
||||||
|
/// <param name="batteryCompartment"></param>
|
||||||
|
/// <param name="horns"></param>
|
||||||
|
///
|
||||||
|
public DrawningTrolleybus(int speed, double weight, Color bodyColor, Color additionalColor, bool batteryCompartment, bool horns) : base(100, 48)
|
||||||
|
{
|
||||||
|
EntityTrolleyB = new EntityTrolleybus(speed, weight, bodyColor, additionalColor, batteryCompartment, horns);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (EntityTrolleyB == null || EntityTrolleyB is not EntityTrolleybus trolleybus || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additBrush = new SolidBrush(trolleybus.AdditionalColor);
|
||||||
|
|
||||||
|
// "Рога" для проводов
|
||||||
|
if (trolleybus.Horns)
|
||||||
|
{
|
||||||
|
pen.Width = 2;
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 15, _startPosX.Value + 52, _startPosY.Value + 2);
|
||||||
|
pen.Width = 1;
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 34, _startPosY.Value, 20, 5);
|
||||||
|
|
||||||
|
g.FillRectangle(additBrush, _startPosX.Value + 35, _startPosY.Value + 1, 19, 4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Отсек под батареи
|
||||||
|
if (trolleybus .BatteryCompartment)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 24, 10, 12);
|
||||||
|
|
||||||
|
g.FillRectangle(additBrush, _startPosX.Value + 1, _startPosY.Value + 25, 9, 11);
|
||||||
|
}
|
||||||
|
|
||||||
|
_startPosX += 10;
|
||||||
|
_startPosY += 15;
|
||||||
|
base.DrawTransport(g);
|
||||||
|
_startPosX -= 10;
|
||||||
|
_startPosY -= 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
namespace ProjectTrolleybus.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-Сущность "Троллейбус"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityTrolleyB
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Основной цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения автомобиля
|
||||||
|
/// </summary>
|
||||||
|
public double Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор сущности
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed"></param>
|
||||||
|
/// <param name="weight"></param>
|
||||||
|
/// <param name="bodyColor"></param>
|
||||||
|
|
||||||
|
public EntityTrolleyB(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +1,9 @@
|
|||||||
namespace ProjectTrolleybus;
|
namespace ProjectTrolleybus.Entities;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-Сущность "Троллейбус"
|
/// Класс-Сущность "Троллейбус"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityTrolleybus
|
public class EntityTrolleybus : EntityTrolleyB
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Скорость
|
|
||||||
/// </summary>
|
|
||||||
public int Speed { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Вес
|
|
||||||
/// </summary>
|
|
||||||
public double Weight { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Основной цвет
|
|
||||||
/// </summary>
|
|
||||||
public Color BodyColor { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дополнительный цвет
|
/// Дополнительный цвет
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -34,8 +19,6 @@ public class EntityTrolleybus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Horns { get; private set; }
|
public bool Horns { get; private set; }
|
||||||
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -45,11 +28,8 @@ public class EntityTrolleybus
|
|||||||
/// <param name="additionalColor"></param>
|
/// <param name="additionalColor"></param>
|
||||||
/// <param name="batteryCompartment"></param>
|
/// <param name="batteryCompartment"></param>
|
||||||
/// <param name="horns"></param>
|
/// <param name="horns"></param>
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool batteryCompartment, bool horns)
|
public EntityTrolleybus(int speed, double weight, Color bodyColor, Color additionalColor, bool batteryCompartment, bool horns) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
BatteryCompartment = batteryCompartment;
|
BatteryCompartment = batteryCompartment;
|
||||||
Horns = horns;
|
Horns = horns;
|
@ -34,6 +34,7 @@
|
|||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
|
buttonCreateTrolleyB = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxTrolleybus).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxTrolleybus).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -51,9 +52,9 @@
|
|||||||
buttonCreateTrolleybus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateTrolleybus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateTrolleybus.Location = new Point(22, 406);
|
buttonCreateTrolleybus.Location = new Point(22, 406);
|
||||||
buttonCreateTrolleybus.Name = "buttonCreateTrolleybus";
|
buttonCreateTrolleybus.Name = "buttonCreateTrolleybus";
|
||||||
buttonCreateTrolleybus.Size = new Size(75, 23);
|
buttonCreateTrolleybus.Size = new Size(204, 23);
|
||||||
buttonCreateTrolleybus.TabIndex = 1;
|
buttonCreateTrolleybus.TabIndex = 1;
|
||||||
buttonCreateTrolleybus.Text = "Создать";
|
buttonCreateTrolleybus.Text = "Создать улучшенный троллейбус";
|
||||||
buttonCreateTrolleybus.UseVisualStyleBackColor = true;
|
buttonCreateTrolleybus.UseVisualStyleBackColor = true;
|
||||||
buttonCreateTrolleybus.Click += ButtonCreateTrolleybus_Click;
|
buttonCreateTrolleybus.Click += ButtonCreateTrolleybus_Click;
|
||||||
//
|
//
|
||||||
@ -105,11 +106,23 @@
|
|||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
buttonUp.Click += ButtonMove_Click;
|
buttonUp.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreateTrolleyB
|
||||||
|
//
|
||||||
|
buttonCreateTrolleyB.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateTrolleyB.Location = new Point(246, 406);
|
||||||
|
buttonCreateTrolleyB.Name = "buttonCreateTrolleyB";
|
||||||
|
buttonCreateTrolleyB.Size = new Size(130, 23);
|
||||||
|
buttonCreateTrolleyB.TabIndex = 6;
|
||||||
|
buttonCreateTrolleyB.Text = "Создать троллейбус";
|
||||||
|
buttonCreateTrolleyB.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateTrolleyB.Click += ButtonCreateTrolleyB_Click;
|
||||||
|
//
|
||||||
// FormTrolleybus
|
// FormTrolleybus
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(buttonCreateTrolleyB);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
@ -130,5 +143,6 @@
|
|||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
|
private Button buttonCreateTrolleyB;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,11 @@
|
|||||||
namespace ProjectTrolleybus
|
using ProjectTrolleybus.Drawnings;
|
||||||
{
|
using ProjectTrolleybus.Entities;
|
||||||
public partial class FormTrolleybus : Form
|
|
||||||
{
|
|
||||||
private DrawningTrolleybus? _drawningTrolleybus;
|
|
||||||
|
|
||||||
EntityTrolleybus? _Trolleybus;
|
namespace ProjectTrolleybus;
|
||||||
|
|
||||||
|
public partial class FormTrolleybus : Form
|
||||||
|
{
|
||||||
|
private DrawningTrolleyB? _drawningTrolleyB;
|
||||||
|
|
||||||
public FormTrolleybus()
|
public FormTrolleybus()
|
||||||
{
|
{
|
||||||
@ -15,34 +16,57 @@
|
|||||||
{
|
{
|
||||||
Bitmap bmp = new(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
Bitmap bmp = new(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningTrolleybus.DrawTransport(gr);
|
_drawningTrolleyB.DrawTransport(gr);
|
||||||
pictureBoxTrolleybus.Image = bmp;
|
pictureBoxTrolleybus.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningTrolleyB):
|
||||||
|
_drawningTrolleyB = new DrawningTrolleyB(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||||
|
break;
|
||||||
|
case nameof(DrawningTrolleybus):
|
||||||
|
_drawningTrolleyB = new DrawningTrolleybus(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)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawningTrolleyB.SetPictureSize(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
||||||
|
_drawningTrolleyB.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия создать улучшеный троллейбус
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
private void ButtonCreateTrolleybus_Click(object sender, EventArgs e)
|
private void ButtonCreateTrolleybus_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
CreateObject(nameof(DrawningTrolleybus));
|
||||||
|
}
|
||||||
|
|
||||||
Random random = new();
|
/// <summary>
|
||||||
_Trolleybus = new EntityTrolleybus();
|
/// Обработка нажатия создать троллейбус
|
||||||
_Trolleybus.Init(random.Next(100, 300), random.Next(1000, 3000),
|
/// </summary>
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
/// <param name="sender"></param>
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
/// <param name="e"></param>
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
private void ButtonCreateTrolleyB_Click(object sender, EventArgs e)
|
||||||
_drawningTrolleybus = new DrawningTrolleybus();
|
{
|
||||||
_drawningTrolleybus.Init(_Trolleybus);
|
CreateObject(nameof(DrawningTrolleyB));
|
||||||
//_drawningTrolleybus.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)));
|
|
||||||
_drawningTrolleybus.SetPictureSize(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
|
||||||
_drawningTrolleybus.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
|
||||||
Draw();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningTrolleybus == null)
|
if (_drawningTrolleyB == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -52,16 +76,16 @@
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result = _drawningTrolleybus.MoveVehicle(DirectionType.Up);
|
result = _drawningTrolleyB.MoveVehicle(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result = _drawningTrolleybus.MoveVehicle(DirectionType.Down);
|
result = _drawningTrolleyB.MoveVehicle(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result = _drawningTrolleybus.MoveVehicle(DirectionType.Left);
|
result = _drawningTrolleyB.MoveVehicle(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result = _drawningTrolleybus.MoveVehicle(DirectionType.Right);
|
result = _drawningTrolleyB.MoveVehicle(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +94,6 @@
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user