1 часть 2 лабы
This commit is contained in:
parent
19049b7467
commit
f8b0e3baa1
@ -1,202 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus;
|
||||
public class DrawningAccordionBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAccordionBus? EntityAccordionBus { get; private set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningAccordionBusWidth = 180;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningAccordionBusHeight = 40;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyGlass">Признак наличия стёкол</param>
|
||||
/// <param name="door">Признак наличия дверей</param>
|
||||
/// <param name="disk">Признак наличия дисков</param>
|
||||
/// /// <param name="garmoshka">Признак наличия гармошки</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyGlass, bool door, bool disk, bool garmoshka)
|
||||
{
|
||||
EntityAccordionBus = new EntityAccordionBus();
|
||||
EntityAccordionBus.Init(speed, weight, bodyColor, additionalColor,
|
||||
bodyGlass, door, disk, garmoshka);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_drawningAccordionBusWidth <= width && _drawningAccordionBusHeight <= height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
if (_startPosX + _drawningAccordionBusWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningAccordionBusWidth;
|
||||
}
|
||||
|
||||
if (_startPosY + _drawningAccordionBusHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningAccordionBusHeight;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (x < 0) x = 0;
|
||||
else if (x + _drawningAccordionBusWidth > _pictureWidth) x = _pictureWidth.Value - _drawningAccordionBusWidth;
|
||||
|
||||
if (y < 0) y = 0;
|
||||
else if (y + _drawningAccordionBusHeight > _pictureHeight) y = _pictureHeight.Value - _drawningAccordionBusHeight;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
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)
|
||||
_startPosX += (int)EntityAccordionBus.Step;
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningAccordionBusHeight+EntityAccordionBus.Step < _pictureHeight)
|
||||
_startPosY += (int)EntityAccordionBus.Step;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAccordionBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
return;
|
||||
//кузов
|
||||
Brush br = new SolidBrush(EntityAccordionBus.BodyColor);
|
||||
g.FillRectangle(br,_startPosX.Value, _startPosY.Value, 70, 30);
|
||||
g.FillRectangle(br, _startPosX.Value+110, _startPosY.Value, 70, 30);
|
||||
if (EntityAccordionBus.bodyGarmoshka)
|
||||
{
|
||||
g.DrawRectangle(new Pen(Color.Black), _startPosX.Value + 70, _startPosY.Value, 40, 30);
|
||||
g.FillRectangle(new HatchBrush(HatchStyle.Vertical,Color.Black,EntityAccordionBus.BodyColor), _startPosX.Value+70, _startPosY.Value, 40, 30);
|
||||
}
|
||||
|
||||
g.DrawRectangle(new Pen(Color.Black), _startPosX.Value, _startPosY.Value, 70, 30);
|
||||
g.DrawRectangle(new Pen(Color.Black), _startPosX.Value+110, _startPosY.Value, 70, 30);
|
||||
|
||||
//колёса
|
||||
if (EntityAccordionBus.bodyDisk)
|
||||
{
|
||||
//диски
|
||||
Brush brWhite = new SolidBrush(Color.White);
|
||||
g.FillEllipse(brWhite, _startPosX.Value, _startPosY.Value + 25, 20, 15);
|
||||
g.FillEllipse(brWhite, _startPosX.Value + 50, _startPosY.Value + 25, 20, 15);
|
||||
Brush brWheel = new SolidBrush(EntityAccordionBus.AdditionalColor);
|
||||
g.FillEllipse(brWheel, _startPosX.Value, _startPosY.Value + 25, 20, 15);
|
||||
g.FillEllipse(brWheel, _startPosX.Value + 50, _startPosY.Value + 25, 20, 15);
|
||||
g.FillEllipse(brWheel, _startPosX.Value + 110, _startPosY.Value + 25, 20, 15);
|
||||
g.FillEllipse(brWheel, _startPosX.Value + 160, _startPosY.Value + 25, 20, 15);
|
||||
}
|
||||
Pen penWheel = new Pen(Color.Black);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value, _startPosY.Value + 25, 20, 15);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value + 50, _startPosY.Value + 25, 20, 15);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value + 110, _startPosY.Value + 25, 20, 15);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value + 160, _startPosY.Value + 25, 20, 15);
|
||||
//стекла
|
||||
if (EntityAccordionBus.bodyGlass)
|
||||
{
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 10, _startPosY.Value + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 55, _startPosY.Value + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 115, _startPosY.Value + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 165, _startPosY.Value + 5, 10, 15);
|
||||
Pen penGlass = new Pen(Color.Black);
|
||||
g.DrawEllipse(penGlass, _startPosX.Value + 10, _startPosY.Value + 5, 10, 15);
|
||||
g.DrawEllipse(penGlass, _startPosX.Value + 55, _startPosY.Value + 5, 10, 15);
|
||||
g.DrawEllipse(penGlass, _startPosX.Value + 115, _startPosY.Value + 5, 10, 15);
|
||||
g.DrawEllipse(penGlass, _startPosX.Value + 165, _startPosY.Value + 5, 10, 15);
|
||||
}
|
||||
//двери
|
||||
if (EntityAccordionBus.bodyDoor)
|
||||
{
|
||||
Brush brDoor = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brDoor, _startPosX.Value + 45, _startPosY.Value + 10, 5, 20);
|
||||
g.FillRectangle(brDoor, _startPosX.Value + 25, _startPosY.Value + 10, 5, 20);
|
||||
g.FillRectangle(brDoor, _startPosX.Value + 135, _startPosY.Value + 10, 5, 20);
|
||||
g.FillRectangle(brDoor, _startPosX.Value + 155, _startPosY.Value + 10, 5, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus;
|
||||
namespace AccordionBus.Drawnings;
|
||||
|
||||
public enum DirectionType
|
||||
{
|
90
AccordionBus/AccordionBus/Drawnings/DrawningAccordionBus.cs
Normal file
90
AccordionBus/AccordionBus/Drawnings/DrawningAccordionBus.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AccordionBus.Drawnings;
|
||||
using AccordionBus.Entities;
|
||||
|
||||
namespace AccordionBus.Drawnings;
|
||||
public class DrawningAccordionBus:DrawningBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyGlass">Признак наличия стёкол</param>
|
||||
/// <param name="door">Признак наличия дверей</param>
|
||||
/// <param name="disk">Признак наличия дисков</param>
|
||||
/// /// <param name="garmoshka">Признак наличия гармошки</param>
|
||||
|
||||
public DrawningAccordionBus(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyGlass, bool door, bool disk, bool garmoshka):base(180,40)
|
||||
{
|
||||
EntityBus = new EntityAccordionBus(speed, weight, bodyColor, additionalColor,
|
||||
bodyGlass, door, disk, garmoshka);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if(EntityBus == null || EntityBus is not EntityAccordionBus accordionBus || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
return;
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (accordionBus.BodyGarmoshka)
|
||||
{
|
||||
g.DrawRectangle(new Pen(Color.Black), _startPosX.Value + 70, _startPosY.Value, 40, 30);
|
||||
g.FillRectangle(new HatchBrush(HatchStyle.Vertical, Color.Black, EntityBus.BodyColor), _startPosX.Value + 70, _startPosY.Value, 40, 30);
|
||||
}
|
||||
|
||||
g.DrawRectangle(new Pen(Color.Black), _startPosX.Value, _startPosY.Value, 70, 30);
|
||||
g.DrawRectangle(new Pen(Color.Black), _startPosX.Value + 110, _startPosY.Value, 70, 30);
|
||||
|
||||
//колёса
|
||||
if (accordionBus.BodyDisk)
|
||||
{
|
||||
//диски
|
||||
Brush brWhite = new SolidBrush(Color.White);
|
||||
g.FillEllipse(brWhite, _startPosX.Value, _startPosY.Value + 25, 20, 15);
|
||||
g.FillEllipse(brWhite, _startPosX.Value + 50, _startPosY.Value + 25, 20, 15);
|
||||
Brush brWheel = new SolidBrush(accordionBus.AdditionalColor);
|
||||
g.FillEllipse(brWheel, _startPosX.Value, _startPosY.Value + 25, 20, 15);
|
||||
g.FillEllipse(brWheel, _startPosX.Value + 50, _startPosY.Value + 25, 20, 15);
|
||||
g.FillEllipse(brWheel, _startPosX.Value + 110, _startPosY.Value + 25, 20, 15);
|
||||
g.FillEllipse(brWheel, _startPosX.Value + 160, _startPosY.Value + 25, 20, 15);
|
||||
}
|
||||
Pen penWheel = new Pen(Color.Black);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value, _startPosY.Value + 25, 20, 15);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value + 50, _startPosY.Value + 25, 20, 15);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value + 110, _startPosY.Value + 25, 20, 15);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value + 160, _startPosY.Value + 25, 20, 15);
|
||||
//стекла
|
||||
if (accordionBus.BodyGlass)
|
||||
{
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 10, _startPosY.Value + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 55, _startPosY.Value + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 115, _startPosY.Value + 5, 10, 15);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 165, _startPosY.Value + 5, 10, 15);
|
||||
Pen penGlass = new Pen(Color.Black);
|
||||
g.DrawEllipse(penGlass, _startPosX.Value + 10, _startPosY.Value + 5, 10, 15);
|
||||
g.DrawEllipse(penGlass, _startPosX.Value + 55, _startPosY.Value + 5, 10, 15);
|
||||
g.DrawEllipse(penGlass, _startPosX.Value + 115, _startPosY.Value + 5, 10, 15);
|
||||
g.DrawEllipse(penGlass, _startPosX.Value + 165, _startPosY.Value + 5, 10, 15);
|
||||
}
|
||||
//двери
|
||||
if (accordionBus.BodyDoor)
|
||||
{
|
||||
Brush brDoor = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brDoor, _startPosX.Value + 45, _startPosY.Value + 10, 5, 20);
|
||||
g.FillRectangle(brDoor, _startPosX.Value + 25, _startPosY.Value + 10, 5, 20);
|
||||
g.FillRectangle(brDoor, _startPosX.Value + 135, _startPosY.Value + 10, 5, 20);
|
||||
g.FillRectangle(brDoor, _startPosX.Value + 155, _startPosY.Value + 10, 5, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
174
AccordionBus/AccordionBus/Drawnings/DrawningBus.cs
Normal file
174
AccordionBus/AccordionBus/Drawnings/DrawningBus.cs
Normal file
@ -0,0 +1,174 @@
|
||||
using AccordionBus.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.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 = 180;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningBusHeight = 40;
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningBus()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningBus(int speed, double weight, Color bodyColor):this()
|
||||
{
|
||||
EntityBus = new EntityBus(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор для наследования
|
||||
/// </summary>
|
||||
/// <param name="drawningBusWidth">ширина автобуса</param>
|
||||
/// <param name="drawningBusHeight">высота автобуса</param>
|
||||
protected DrawningBus(int drawningBusWidth, int drawningBusHeight):this()
|
||||
{
|
||||
_drawningBusWidth = drawningBusWidth;
|
||||
_drawningBusHeight = drawningBusHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_drawningBusWidth <= width && _drawningBusHeight <= height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
if (_startPosX + _drawningBusWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningBusWidth;
|
||||
}
|
||||
|
||||
if (_startPosY + _drawningBusHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningBusHeight;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (x < 0) x = 0;
|
||||
else if (x + _drawningBusWidth > _pictureWidth) x = _pictureWidth.Value - _drawningBusWidth;
|
||||
|
||||
if (y < 0) y = 0;
|
||||
else if (y + _drawningBusHeight > _pictureHeight) y = _pictureHeight.Value - _drawningBusHeight;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
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)
|
||||
_startPosX += (int)EntityBus.Step;
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningBusHeight + EntityBus.Step < _pictureHeight)
|
||||
_startPosY += (int)EntityBus.Step;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
return;
|
||||
//кузов
|
||||
Brush br = new SolidBrush(EntityBus.BodyColor);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value, 70, 30);
|
||||
g.FillRectangle(br, _startPosX.Value + 110, _startPosY.Value, 70, 30);
|
||||
|
||||
g.FillRectangle(br, _startPosX.Value +70, _startPosY.Value, 40, 30);
|
||||
|
||||
g.DrawRectangle(new Pen(Color.Black), _startPosX.Value, _startPosY.Value, 70, 30);
|
||||
g.DrawRectangle(new Pen(Color.Black), _startPosX.Value + 110, _startPosY.Value, 70, 30);
|
||||
|
||||
Pen penWheel = new Pen(Color.Black);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value, _startPosY.Value + 25, 20, 15);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value + 50, _startPosY.Value + 25, 20, 15);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value + 110, _startPosY.Value + 25, 20, 15);
|
||||
g.DrawEllipse(penWheel, _startPosX.Value + 160, _startPosY.Value + 25, 20, 15);
|
||||
|
||||
}
|
||||
}
|
48
AccordionBus/AccordionBus/Entities/EntityAccordionBus.cs
Normal file
48
AccordionBus/AccordionBus/Entities/EntityAccordionBus.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.Entities;
|
||||
public class EntityAccordionBus: EntityBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия стёкол
|
||||
/// </summary>
|
||||
public bool BodyGlass { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) дверей
|
||||
/// </summary>
|
||||
public bool BodyDoor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия дисков
|
||||
/// </summary>
|
||||
public bool BodyDisk { get; private set; }
|
||||
/// <summary>
|
||||
/// признак наличия гармошки
|
||||
/// </summary>
|
||||
public bool BodyGarmoshka { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса автобуса с гармошкой
|
||||
/// </summary>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="glass">наличие стекла</param>
|
||||
/// <param name="door">наличие дверей</param>
|
||||
/// <param name="disk">наличие дисков</param>
|
||||
/// <param name="garmoshka">наличие гармошки</param>
|
||||
|
||||
public EntityAccordionBus(int speed, double weigth, Color bodyColor, Color additionalColor, bool glass, bool door, bool disk, bool garmoshka) : base (speed,weigth,bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
BodyGlass = glass;
|
||||
BodyDoor = door;
|
||||
BodyDisk = disk;
|
||||
BodyGarmoshka = garmoshka;
|
||||
}
|
||||
}
|
45
AccordionBus/AccordionBus/Entities/EntityBus.cs
Normal file
45
AccordionBus/AccordionBus/Entities/EntityBus.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.Entities;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность автобус
|
||||
/// </summary>
|
||||
|
||||
public class EntityBus
|
||||
{
|
||||
/// <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 EntityBus(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus;
|
||||
public class EntityAccordionBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия стёкол
|
||||
/// </summary>
|
||||
public bool bodyGlass { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) дверей
|
||||
/// </summary>
|
||||
public bool bodyDoor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия дисков
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия дисков
|
||||
/// </summary>
|
||||
public bool bodyDisk { get; private set; }
|
||||
public bool bodyGarmoshka { 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>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyGlass">Признак наличия обвеса</param>
|
||||
/// <param name="bodyDoor">Признак наличия антикрыла</param>
|
||||
/// <param name="bodyDisk">Признак наличия гоночной полосы</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool glass, bool door, bool disk, bool garmoshka)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
bodyGlass = glass;
|
||||
bodyDoor = door;
|
||||
bodyDisk = disk;
|
||||
bodyGarmoshka = garmoshka;
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonCreateBus = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAccordionBus).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -48,11 +49,11 @@
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 415);
|
||||
buttonCreate.Location = new Point(12, 421);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.Size = new Size(216, 23);
|
||||
buttonCreate.TabIndex = 6;
|
||||
buttonCreate.Text = "Создать\r\n";
|
||||
buttonCreate.Text = "Создать\r\n автобус с гармошкой";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreateAccordionBus_Click;
|
||||
//
|
||||
@ -108,11 +109,23 @@
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateBus
|
||||
//
|
||||
buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBus.Location = new Point(234, 421);
|
||||
buttonCreateBus.Name = "buttonCreateBus";
|
||||
buttonCreateBus.Size = new Size(216, 23);
|
||||
buttonCreateBus.TabIndex = 11;
|
||||
buttonCreateBus.Text = "Создать\r\n автобус без гармошки";
|
||||
buttonCreateBus.UseVisualStyleBackColor = true;
|
||||
buttonCreateBus.Click += buttonCreateBus_Click;
|
||||
//
|
||||
// FormAccordionBus
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonCreateBus);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
@ -132,5 +145,6 @@
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateBus;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using AccordionBus.Drawnings;
|
||||
|
||||
namespace AccordionBus;
|
||||
public partial class FormAccordionBus : Form
|
||||
@ -14,7 +15,7 @@ public partial class FormAccordionBus : Form
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAccordionBus? _drawningAccordionBus;
|
||||
private DrawningBus? _drawningBus;
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
@ -27,39 +28,62 @@ public partial class FormAccordionBus : Form
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAccordionBus == null)
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAccordionBus.Width,
|
||||
pictureBoxAccordionBus.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAccordionBus.DrawTransport(gr);
|
||||
_drawningBus.DrawTransport(gr);
|
||||
pictureBoxAccordionBus.Image = bmp;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Создание объекта класса-перемещения
|
||||
///</summary>
|
||||
/// <param name="type">Тип создаваемого объётека</param>
|
||||
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBus):
|
||||
_drawningBus = new DrawningBus(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningAccordionBus):
|
||||
_drawningBus = new DrawningAccordionBus(rnd.Next(650, 700), rnd.Next(15760,16130),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_drawningBus.SetPictureSize(pictureBoxAccordionBus.Width,pictureBoxAccordionBus.Height);
|
||||
_drawningBus.SetPosition(rnd.Next(10,100), rnd.Next(10,100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Обработка нажатия кнопки "Создать автобус с гармошкой"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateAccordionBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningAccordionBus = new DrawningAccordionBus();
|
||||
_drawningAccordionBus.Init(random.Next(650, 700), random.Next(15760,
|
||||
16130),
|
||||
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)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningAccordionBus.SetPictureSize(pictureBoxAccordionBus.Width,
|
||||
pictureBoxAccordionBus.Height);
|
||||
_drawningAccordionBus.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateAccordionBus_Click(object sender, EventArgs e) =>CreateObject(nameof(DrawningAccordionBus));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать автобус"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
public void buttonCreateBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
@ -67,7 +91,7 @@ public partial class FormAccordionBus : Form
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAccordionBus == null)
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -77,19 +101,19 @@ public partial class FormAccordionBus : Form
|
||||
{
|
||||
case "buttonUp":
|
||||
result =
|
||||
_drawningAccordionBus.MoveTransport(DirectionType.Up);
|
||||
_drawningBus.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result =
|
||||
_drawningAccordionBus.MoveTransport(DirectionType.Down);
|
||||
_drawningBus.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result =
|
||||
_drawningAccordionBus.MoveTransport(DirectionType.Left);
|
||||
_drawningBus.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawningAccordionBus.MoveTransport(DirectionType.Right);
|
||||
_drawningBus.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
|
@ -121,7 +121,7 @@
|
||||
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAA5gAAAOYBAMAAABC5kGOAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
||||
AQEB////AAAAl5eXUFBQNT5ZuQAAAAlwSFlzAAAOvQAADr0BR/uQrQAAGoFJREFUeNrt3V168riyhmHH
|
||||
AQEB////AAAAl5eXUFBQNT5ZuQAAAAlwSFlzAAAOvAAADrwBlbxySQAAGoFJREFUeNrt3V168riyhmHH
|
||||
7AFE+NrnJss+j7ZWBgCMAJj/XDb6MfnikICDsVXlx0f9+qAb6b5UoSlZLtJVvsWLKDgWzISeWDATemLB
|
||||
TOiJBTOhJxbpTp1uESVHZkJRZCYURWZCUWQmFEVmQlFkJhRFZkJRZCYURWZCUWQmFEVmQlHUP9b/0T7A
|
||||
z6h6cCEa7QP8jKoH56/G7nQPsBcLze2+lXvXPcDPWGgeXLhO7qMuwFQRm8q6XQGmiripnHuvwVQRD9ZV
|
||||
@ -241,7 +241,7 @@
|
||||
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAA5gAAAOYBAMAAABC5kGOAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
||||
AQEB////AAAAl5eXUFBQNT5ZuQAAAAlwSFlzAAAOvQAADr0BR/uQrQAAF5dJREFUeNrtnW1urEjSRinU
|
||||
AQEB////AAAAl5eXUFBQNT5ZuQAAAAlwSFlzAAAOvAAADrwBlbxySQAAF5dJREFUeNrtnW1urEjSRinU
|
||||
LACxAYSoBSDUCyh53gWUav97eZ2ZQJXd/qgPSCIeH/+YmdM98k2eo7hlRyaRRde1Rfrq0hfoFpGJTNAi
|
||||
IhOZoEV8/yqnfwQKIEkIIUkIIUkIIUkIIUkIIUkIIUkIIUkIIUkIIUkIIUkIIUkIIUkIIUnIIJuBOohM
|
||||
ZIIWEZnIBC0iMpEJWkRkIhO0iMhEJmgRkYlM0CIiE5mgRSzYDJRCkhBCkhBCkhBCkhBCkhBCkhBCkhBC
|
||||
@ -348,7 +348,7 @@
|
||||
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAA5gAAAOYBAMAAABC5kGOAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
||||
AQEB////AAAAl5eXUFBQNT5ZuQAAAAlwSFlzAAAOvQAADr0BR/uQrQAAGFFJREFUeNrt3c126jq2hmFj
|
||||
AQEB////AAAAl5eXUFBQNT5ZuQAAAAlwSFlzAAAOvAAADrwBlbxySQAAGFFJREFUeNrt3c126jq2hmFj
|
||||
bgCjpK/4QB+VQr+GuYJi3f+9HCzZJFkrIRj8ozn10qn97UaNSM/QhG1NyUVRlHX8FPGTXtx5710VPz5+
|
||||
FopV1SQ+V2DeGyswwQQzPUwHJphgggkmmGCCCSaYYIIJJphggskTIO2YDkwwZ4t1bbt/1f2b9OLuMomm
|
||||
m9xubpeKrkl5rsAcFD2YYIKZHqYBE0wwwQQTTDDBBBNMMMEEE0wwwQRTOSaP8zRhmrQx2c+8P1ZsToMJ
|
||||
@ -458,7 +458,7 @@
|
||||
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAA5gAAAOYBAMAAABC5kGOAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
|
||||
AQEB////AAAAl5eXUFBQNT5ZuQAAAAlwSFlzAAAOvQAADr0BR/uQrQAAF29JREFUeNrtnV1uG8myBhO9
|
||||
AQEB////AAAAl5eXUFBQNT5ZuQAAAAlwSFlzAAAOvAAADrwBlbxySQAAF29JREFUeNrtnV1uG8myBhO9
|
||||
AjXKfCe4g0Kb7wPhLECQ7/7Xcln9Q8mWZyhKlLozGHw5EwJm3PkF0tSpqq6Mw/TZx/QRM6NJgNAkQGgS
|
||||
IDQJEJoECE0ChCYBQpMAoUmA0CRAaBIgNAkQmgQITQKGp083/0hMjGESHAyT4GCYBAfDJDgYJsHBMAkO
|
||||
hklwMEyCg2ESHAyT4GCYBAfDJDgYJsHBMAkOuhlIQpMAoUmA0CRAaBIgNAkQmgQITQKEJgFCkwChSYDQ
|
||||
|
Loading…
x
Reference in New Issue
Block a user