PIBD-13_Baryshev_D.A._LabWork02_Base #2
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectDumpTruck
|
||||
namespace ProjectDumpTruck.Drawnings
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
121
ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTruck.cs
Normal file
121
ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTruck.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectDumpTruck.Entities;
|
||||
|
||||
namespace ProjectDumpTruck.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningDumpTruck : DrawningTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="awning">Признак наличия обвеса</param>
|
||||
/// <param name="tent">Признак наличия антикрыла</param>
|
||||
public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, bool awning, bool tent) : base(135, 85)
|
||||
{
|
||||
EntityTruck = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, awning, tent);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTruck == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
}
|
||||
|
||||
//public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityDumpTruck == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityDumpTruck.AdditionalColor);
|
||||
|
||||
//Кабина и основа
|
||||
Brush body = new SolidBrush(EntityDumpTruck.BodyColor);
|
||||
g.FillRectangle(body, _startPosX.Value + 100, _startPosY.Value, 30, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value, 30, 40);
|
||||
|
||||
g.FillRectangle(body, _startPosX.Value, _startPosY.Value + 40, 130, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 40, 130, 20);
|
||||
|
||||
//Фары
|
||||
Brush light = new SolidBrush(Color.Yellow);
|
||||
g.FillRectangle(light, _startPosX.Value + 130, _startPosY.Value + 40, 4, 5);
|
||||
g.FillRectangle(light, _startPosX.Value - 5, _startPosY.Value + 40, 4, 5);
|
||||
|
||||
Brush light1 = new SolidBrush(Color.DarkOrange);
|
||||
g.FillRectangle(light1, _startPosX.Value + 125, _startPosY.Value + 40, 5, 5);
|
||||
g.FillRectangle(light1, _startPosX.Value, _startPosY.Value + 40, 5, 5);
|
||||
|
||||
//Стекло
|
||||
Brush glass = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(glass, _startPosX.Value + 110, _startPosY.Value + 5, 20, 25);
|
||||
|
||||
//Отрисовка колёс
|
||||
Brush wheels = new SolidBrush(Color.Black);
|
||||
g.FillEllipse(wheels, _startPosX.Value, _startPosY.Value + 60, 30, 30);
|
||||
g.FillEllipse(wheels, _startPosX.Value + 30, _startPosY.Value + 60, 30, 30);
|
||||
g.FillEllipse(wheels, _startPosX.Value + 100, _startPosY.Value + 60, 30, 30);
|
||||
|
||||
Brush kolpac = new SolidBrush(Color.Gray);
|
||||
g.FillEllipse(kolpac, _startPosX.Value + 6, _startPosY.Value + 66, 17, 17);
|
||||
g.FillEllipse(kolpac, _startPosX.Value + 36, _startPosY.Value + 66, 17, 17);
|
||||
g.FillEllipse(kolpac, _startPosX.Value + 106, _startPosY.Value + 66, 17, 17);
|
||||
|
||||
//Отрисовка границ
|
||||
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 40, 130, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 60, 30, 30);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 60, 30, 30);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 60, 30, 30);
|
||||
|
||||
Pen glass_ = new(Color.DarkGray);
|
||||
g.DrawRectangle(glass_, _startPosX.Value + 110, _startPosY.Value + 5, 20, 25);
|
||||
|
||||
Pen light_ = new(Color.LightBlue);
|
||||
g.DrawRectangle(light_, _startPosX.Value + 130, _startPosY.Value + 40, 4, 5);
|
||||
g.DrawRectangle(light_, _startPosX.Value + 125, _startPosY.Value + 40, 5, 5);
|
||||
g.DrawRectangle(light_, _startPosX.Value - 5, _startPosY.Value + 40, 4, 5);
|
||||
g.DrawRectangle(light_, _startPosX.Value, _startPosY.Value + 40, 5, 5);
|
||||
|
||||
//Отрисовка кузова
|
||||
if (EntityDumpTruck.Awning)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 90, 35);
|
||||
}
|
||||
|
||||
//Отрисовка тента
|
||||
if (EntityDumpTruck.Awning & EntityDumpTruck.Tent)
|
||||
{
|
||||
Brush tent = new SolidBrush(EntityDumpTruck.AdditionalColor);
|
||||
g.FillRectangle(tent, _startPosX.Value, _startPosY.Value, 95, 10);
|
||||
g.FillRectangle(tent, _startPosX.Value, _startPosY.Value, 95, 3);
|
||||
g.FillRectangle(tent, _startPosX.Value + 30, _startPosY.Value, 3, 40);
|
||||
g.FillRectangle(tent, _startPosX.Value + 70, _startPosY.Value, 3, 40);
|
||||
|
||||
Pen t = new(Color.Black);
|
||||
g.DrawRectangle(t, _startPosX.Value, _startPosY.Value, 95, 10);
|
||||
g.DrawRectangle(t, _startPosX.Value + 30, _startPosY.Value, 3, 40);
|
||||
g.DrawRectangle(t, _startPosX.Value + 70, _startPosY.Value, 3, 40);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,18 @@
|
||||
using System;
|
||||
using ProjectDumpTruck.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectDumpTruck;
|
||||
namespace ProjectDumpTruck.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
internal class DrawningDumpTruck
|
||||
public class DrawningTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityDumpTruck? EntityDumpTruck { get; private set; }
|
||||
public EntityTruck? EntityTruck { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -26,11 +24,11 @@ internal class DrawningDumpTruck
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
@ -39,32 +37,44 @@ internal class DrawningDumpTruck
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningTruckHeight = 85;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="awning">Признак наличия обвеса</param>
|
||||
/// <param name="tent">Признак наличия антикрыла</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool awning, bool tent)
|
||||
private DrawningTruck()
|
||||
{
|
||||
EntityDumpTruck = new EntityDumpTruck();
|
||||
EntityDumpTruck.Init(speed, weight, bodyColor, additionalColor, awning, tent);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningTruck(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityTruck = new EntityTruck(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningTruckWidth">Ширина прорисовки самосвала</param>
|
||||
/// <param name="drawningTruckHeight">Высота прорисовки самосвала</param>
|
||||
public DrawningTruck(int drawningTruckWidth, int drawningTruckHeight) : this()
|
||||
{
|
||||
_drawningTruckWidth = drawningTruckWidth;
|
||||
_drawningTruckHeight= drawningTruckHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена
|
||||
public bool SetPictureSize(int width, int height)
|
||||
|
||||
{
|
||||
@ -124,7 +134,7 @@ internal class DrawningDumpTruck
|
||||
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityDumpTruck == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityTruck == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -132,30 +142,30 @@ internal class DrawningDumpTruck
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityDumpTruck.Step > 0)
|
||||
if (_startPosX.Value - EntityTruck.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityDumpTruck.Step;
|
||||
_startPosX -= (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityDumpTruck.Step > 0)
|
||||
if (_startPosY.Value - EntityTruck.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityDumpTruck.Step;
|
||||
_startPosY -= (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityDumpTruck.Step + _drawningTruckHeight < _pictureHeight)
|
||||
if (_startPosY.Value + EntityTruck.Step + _drawningTruckHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityDumpTruck.Step;
|
||||
_startPosY += (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
//вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityDumpTruck.Step + _drawningTruckWidth < _pictureWidth)
|
||||
if (_startPosX.Value + EntityTruck.Step + _drawningTruckWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityDumpTruck.Step;
|
||||
_startPosX += (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -163,18 +173,17 @@ internal class DrawningDumpTruck
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityDumpTruck == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityTruck == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityDumpTruck.AdditionalColor);
|
||||
|
||||
//Кабина и основа
|
||||
Brush body = new SolidBrush(EntityDumpTruck.BodyColor);
|
||||
Brush body = new SolidBrush(EntityTruck.BodyColor);
|
||||
g.FillRectangle(body, _startPosX.Value + 100, _startPosY.Value, 30, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value, 30, 40);
|
||||
|
||||
@ -222,28 +231,5 @@ internal class DrawningDumpTruck
|
||||
g.DrawRectangle(light_, _startPosX.Value - 5, _startPosY.Value + 40, 4, 5);
|
||||
g.DrawRectangle(light_, _startPosX.Value, _startPosY.Value + 40, 5, 5);
|
||||
|
||||
//Отрисовка кузова
|
||||
if (EntityDumpTruck.Awning)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 90, 35);
|
||||
}
|
||||
|
||||
//Отрисовка тента
|
||||
if (EntityDumpTruck.Awning & EntityDumpTruck.Tent)
|
||||
{
|
||||
Brush tent = new SolidBrush(EntityDumpTruck.AdditionalColor);
|
||||
g.FillRectangle(tent, _startPosX.Value, _startPosY.Value, 95, 10);
|
||||
g.FillRectangle(tent, _startPosX.Value, _startPosY.Value, 95, 3);
|
||||
g.FillRectangle(tent, _startPosX.Value + 30, _startPosY.Value, 3, 40);
|
||||
g.FillRectangle(tent, _startPosX.Value + 70, _startPosY.Value, 3, 40);
|
||||
|
||||
Pen t = new(Color.Black);
|
||||
g.DrawRectangle(t, _startPosX.Value, _startPosY.Value, 95, 10);
|
||||
g.DrawRectangle(t, _startPosX.Value + 30, _startPosY.Value, 3, 40);
|
||||
g.DrawRectangle(t, _startPosX.Value + 70, _startPosY.Value, 3, 40);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,8 @@
|
||||
|
||||
namespace ProjectDumpTruck;
|
||||
namespace ProjectDumpTruck.Entities;
|
||||
|
||||
public class EntityDumpTruck
|
||||
public class EntityDumpTruck : EntityTruck
|
||||
{
|
||||
|
||||
/// <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>
|
||||
@ -28,10 +15,7 @@ public class EntityDumpTruck
|
||||
/// Признак (опция) наличия тента
|
||||
/// </summary>
|
||||
public bool Tent { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса самосвала
|
||||
/// </summary>
|
||||
@ -44,9 +28,6 @@ public class EntityDumpTruck
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool awning, bool tent)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Awning = awning;
|
||||
Tent = tent;
|
42
ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTruck.cs
Normal file
42
ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTruck.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace ProjectDumpTruck.Entities;
|
||||
/// <summary>
|
||||
/// Класс-сущность самосвал без кузова
|
||||
/// </summary>
|
||||
public class EntityTruck
|
||||
{
|
||||
/// <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 EntityTruck(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectDumpTruck.Drawnings;
|
||||
|
||||
namespace ProjectDumpTruck
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user