LabWork04 #5
@ -1,27 +0,0 @@
|
||||
namespace ProjectSportCar;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
@ -1,237 +0,0 @@
|
||||
namespace ProjectSportCar;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningSportCar
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntitySportCar? EntitySportCar { 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 _drawningCarWidth = 110;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningCarHeight = 60;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
{
|
||||
EntitySportCar = new EntitySportCar();
|
||||
EntitySportCar.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntitySportCar == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntitySportCar.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntitySportCar.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntitySportCar.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntitySportCar.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига в право
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
//TODO прописать логику сдвига в вниз
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntitySportCar == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntitySportCar.AdditionalColor);
|
||||
|
||||
// обвесы
|
||||
if (EntitySportCar.BodyKit)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 10, 20, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 45, 15, 15);
|
||||
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 40, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 10, 20, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 1, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 45, 15, 15);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10, 20, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value, 14, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 14, 15);
|
||||
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 40, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 1, _startPosY.Value + 10, 25, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 1, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 45, 15, 15);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value, 39, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 45, 39, 15);
|
||||
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 1, 40, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 45, 40, 15);
|
||||
}
|
||||
|
||||
//границы автомобиля
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 9, _startPosY.Value + 15, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 15, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 4, 70, 52);
|
||||
|
||||
//задние фары
|
||||
Brush brRed = new SolidBrush(Color.Red);
|
||||
g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 5, 20, 20);
|
||||
g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20);
|
||||
|
||||
//передние фары
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 5, 20, 20);
|
||||
g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 35, 20, 20);
|
||||
|
||||
//кузов
|
||||
Brush br = new SolidBrush(EntitySportCar.BodyColor);
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 15, 10, 30);
|
||||
g.FillRectangle(br, _startPosX.Value + 90, _startPosY.Value + 15, 10, 30);
|
||||
g.FillRectangle(br, _startPosX.Value + 20, _startPosY.Value + 5, 70, 50);
|
||||
|
||||
//стекла
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 70, _startPosY.Value + 10, 5, 40);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 30, _startPosY.Value + 10, 5, 40);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 8, 35, 2);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 51, 35, 2);
|
||||
|
||||
//выделяем рамкой крышу
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 10, 35, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 75, _startPosY.Value + 15, 25, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, 15, 30);
|
||||
|
||||
// спортивная линия
|
||||
if (EntitySportCar.SportLine)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 23, 25, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 23, 35, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 23, 20, 15);
|
||||
}
|
||||
|
||||
// крыло
|
||||
if (EntitySportCar.Wing)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 5, 10, 50);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5, 10, 50);
|
||||
}
|
||||
}
|
||||
}
|
27
ProjectSportCar/ProjectSportCar/Drawnings/DirectionType.cs
Normal file
27
ProjectSportCar/ProjectSportCar/Drawnings/DirectionType.cs
Normal file
@ -0,0 +1,27 @@
|
||||
namespace ProjectSportCar.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
199
ProjectSportCar/ProjectSportCar/Drawnings/DrawningCar.cs
Normal file
199
ProjectSportCar/ProjectSportCar/Drawnings/DrawningCar.cs
Normal file
@ -0,0 +1,199 @@
|
||||
using ProjectSportCar.Entities;
|
||||
|
||||
namespace ProjectSportCar.Drawnings;
|
||||
|
||||
public class DrawningCar
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityCar? EntityCar { 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 _drawningCarWidth = 90;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningCarHeight = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningCar()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningCar(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityCar = new EntityCar(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningCarWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="drawningCarHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawningCar(int drawningCarWidth, int drawningCarHeight) : this()
|
||||
{
|
||||
_drawningCarWidth = drawningCarWidth;
|
||||
_pictureHeight = drawningCarHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityCar == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityCar.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityCar.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityCar.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityCar.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига в право
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
//TODO прописать логику сдвига в вниз
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCar == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
//границы автомобиля
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 30, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 30, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value - 1, _startPosY.Value + 10, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 10, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value - 1, 70, 52);
|
||||
|
||||
//задние фары
|
||||
Brush brRed = new SolidBrush(Color.Red);
|
||||
g.FillEllipse(brRed, _startPosX.Value, _startPosY.Value, 20, 20);
|
||||
g.FillEllipse(brRed, _startPosX.Value, _startPosY.Value + 30, 20, 20);
|
||||
|
||||
//передние фары
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
g.FillEllipse(brYellow, _startPosX.Value + 70, _startPosY.Value, 20, 20);
|
||||
g.FillEllipse(brYellow, _startPosX.Value + 70, _startPosY.Value + 30, 20, 20);
|
||||
|
||||
//кузов
|
||||
Brush br = new SolidBrush(EntityCar.BodyColor);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 10, 10, 30);
|
||||
g.FillRectangle(br, _startPosX.Value + 80, _startPosY.Value + 10, 10, 30);
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value, 70, 50);
|
||||
|
||||
//стекла
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 60, _startPosY.Value + 5, 5, 40);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 20, _startPosY.Value + 5, 5, 40);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 25, _startPosY.Value + 3, 35, 2);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 25, _startPosY.Value + 46, 35, 2);
|
||||
|
||||
//выделяем рамкой крышу
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 5, 35, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 10, 25, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10, 15, 30);
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
using ProjectSportCar.Entities;
|
||||
|
||||
namespace ProjectSportCar.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningSportCar : DrawningCar
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public DrawningSportCar(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine) : base(110, 60)
|
||||
{
|
||||
EntityCar = new EntitySportCar(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCar == null || EntityCar is not EntitySportCar sportCar || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(sportCar.AdditionalColor);
|
||||
|
||||
// обвесы
|
||||
if (sportCar.BodyKit)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 10, 20, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 45, 15, 15);
|
||||
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 40, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 10, 20, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 1, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 45, 15, 15);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10, 20, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value, 14, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 14, 15);
|
||||
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 40, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 1, _startPosY.Value + 10, 25, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 1, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 45, 15, 15);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value, 39, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 45, 39, 15);
|
||||
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 1, 40, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 45, 40, 15);
|
||||
}
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
|
||||
// спортивная линия
|
||||
if (sportCar.SportLine)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 23, 25, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 23, 35, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 23, 20, 15);
|
||||
}
|
||||
|
||||
// крыло
|
||||
if (sportCar.Wing)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 5, 10, 50);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5, 10, 50);
|
||||
}
|
||||
}
|
||||
}
|
40
ProjectSportCar/ProjectSportCar/Entities/EntityCar.cs
Normal file
40
ProjectSportCar/ProjectSportCar/Entities/EntityCar.cs
Normal file
@ -0,0 +1,40 @@
|
||||
namespace ProjectSportCar.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Автомобиль"
|
||||
/// </summary>
|
||||
public class EntityCar
|
||||
{
|
||||
/// <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 EntityCar(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -1,25 +1,10 @@
|
||||
namespace ProjectSportCar;
|
||||
namespace ProjectSportCar.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Спортивный автомобиль"
|
||||
/// </summary>
|
||||
public class EntitySportCar
|
||||
public class EntitySportCar : EntityCar
|
||||
{
|
||||
/// <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>
|
||||
@ -40,11 +25,6 @@ public class EntitySportCar
|
||||
/// </summary>
|
||||
public bool SportLine { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// </summary>
|
||||
@ -57,9 +37,6 @@ public class EntitySportCar
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Wing = wing;
|
@ -34,6 +34,7 @@
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonCreateCar = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxSportCar).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -51,9 +52,9 @@
|
||||
buttonCreateSportCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateSportCar.Location = new Point(12, 562);
|
||||
buttonCreateSportCar.Name = "buttonCreateSportCar";
|
||||
buttonCreateSportCar.Size = new Size(75, 23);
|
||||
buttonCreateSportCar.Size = new Size(223, 23);
|
||||
buttonCreateSportCar.TabIndex = 1;
|
||||
buttonCreateSportCar.Text = "Создать";
|
||||
buttonCreateSportCar.Text = "Создать спортивный автомобиль";
|
||||
buttonCreateSportCar.UseVisualStyleBackColor = true;
|
||||
buttonCreateSportCar.Click += ButtonCreateSportCar_Click;
|
||||
//
|
||||
@ -105,11 +106,23 @@
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateCar
|
||||
//
|
||||
buttonCreateCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateCar.Location = new Point(250, 562);
|
||||
buttonCreateCar.Name = "buttonCreateCar";
|
||||
buttonCreateCar.Size = new Size(223, 23);
|
||||
buttonCreateCar.TabIndex = 6;
|
||||
buttonCreateCar.Text = "Создать автомобиль";
|
||||
buttonCreateCar.UseVisualStyleBackColor = true;
|
||||
buttonCreateCar.Click += ButtonCreateCar_Click;
|
||||
//
|
||||
// FormSportCar
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(923, 597);
|
||||
Controls.Add(buttonCreateCar);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
@ -130,5 +143,6 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateCar;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
namespace ProjectSportCar;
|
||||
using ProjectSportCar.Drawnings;
|
||||
|
||||
namespace ProjectSportCar;
|
||||
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Спортивный автомобиль"
|
||||
@ -8,7 +10,7 @@ public partial class FormSportCar : Form
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningSportCar? _drawningSportCar;
|
||||
private DrawningCar? _drawningCar;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
@ -23,34 +25,58 @@ public partial class FormSportCar : Form
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningSportCar == null)
|
||||
if (_drawningCar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxSportCar.Width, pictureBoxSportCar.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningSportCar.DrawTransport(gr);
|
||||
_drawningCar.DrawTransport(gr);
|
||||
pictureBoxSportCar.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningCar):
|
||||
_drawningCar = new DrawningCar(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(DrawningSportCar):
|
||||
_drawningCar = new DrawningSportCar(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)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawningCar.SetPictureSize(pictureBoxSportCar.Width, pictureBoxSportCar.Height);
|
||||
_drawningCar.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать спортивный автомобиль"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateSportCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningSportCar = new DrawningSportCar();
|
||||
_drawningSportCar.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)));
|
||||
_drawningSportCar.SetPictureSize(pictureBoxSportCar.Width, pictureBoxSportCar.Height);
|
||||
_drawningSportCar.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateSportCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSportCar));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать автомобиль"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCar));
|
||||
|
||||
/// <summary>
|
||||
/// Перемешение объекта по форме (нажатие кнопок навигации)
|
||||
@ -59,7 +85,7 @@ public partial class FormSportCar : Form
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningSportCar == null)
|
||||
if (_drawningCar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -69,16 +95,16 @@ public partial class FormSportCar : Form
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningSportCar.MoveTransport(DirectionType.Up);
|
||||
result = _drawningCar.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningSportCar.MoveTransport(DirectionType.Down);
|
||||
result = _drawningCar.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningSportCar.MoveTransport(DirectionType.Left);
|
||||
result = _drawningCar.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningSportCar.MoveTransport(DirectionType.Right);
|
||||
result = _drawningCar.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user