PIbd-21. Kryukov A.I. Lab work 02 #15
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectExcavator.Entities;
|
||||
|
||||
namespace ProjectExcavator.DrawningObjects
|
||||
{
|
||||
public class DrawningExcavarorBodyKits : DrawningExcavator
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="bucket">Признак наличия антикрыла</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawningExcavarorBodyKits(int speed, double weight,
|
||||
Color bodyColor, Color additionalColor,
|
||||
bool bodyKit, bool bucket,
|
||||
int width, int height) :
|
||||
base(speed, weight, bodyColor, width, height, 110, 60)
|
||||
{
|
||||
if(EntityExcavator != null)
|
||||
{
|
||||
EntityExcavator = new EntityExcavatorBodyKits(speed, weight,
|
||||
bodyColor, additionalColor, bodyKit, bucket);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if(EntityExcavator is not EntityExcavatorBodyKits excavator)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(excavator.AdditionalColor);
|
||||
//ыспомогательные опоры
|
||||
if (excavator.BodyKit)
|
||||
{
|
||||
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
//ковш
|
||||
if (excavator.Bucket)
|
||||
{
|
||||
Point[] pointsBacket = {
|
||||
new Point(_startPosX + 150, _startPosY + 75),
|
||||
new Point(_startPosX + 150, _startPosY + 135),
|
||||
new Point(_startPosX + 195, _startPosY + 135),
|
||||
};
|
||||
g.FillPolygon(additionalBrush, pointsBacket);
|
||||
g.DrawPolygon(pen, pointsBacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,18 @@
|
||||
using System;
|
||||
using ProjectExcavator.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
namespace ProjectExcavator.DrawningObjects
|
||||
{
|
||||
internal class DrawningExcavator
|
||||
public class DrawningExcavator
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityExcavator? EntityExcavator { get; private set; }
|
||||
public EntityExcavator? EntityExcavator { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -31,32 +32,48 @@ namespace ProjectExcavator
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _excavatorWidth = 190;
|
||||
private readonly int _excavatorWidth = 100;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _excavatorHeight = 170;
|
||||
private readonly int _excavatorHeight = 55;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия вспомогательных опор</param>
|
||||
/// <param name="backet">Признак наличия ковша</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool backet, int width, int height)
|
||||
public DrawningExcavator(int speed, double weight, Color bodyColor, int
|
||||
width, int height)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityExcavator = new EntityExcavator();
|
||||
EntityExcavator.Init(speed, weight, bodyColor, additionalColor, bodyKit, backet);
|
||||
return true;
|
||||
EntityExcavator = new EntityExcavator(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <param name="excavatorWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="excavatorHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawningExcavator(int speed, double weight,
|
||||
Color bodyColor,
|
||||
int width, int height,
|
||||
int excavatorWidth, int excavatorHeight)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_excavatorWidth = excavatorWidth;
|
||||
_excavatorHeight = excavatorHeight;
|
||||
EntityExcavator = new EntityExcavator(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
@ -68,8 +85,6 @@ namespace ProjectExcavator
|
||||
// TODO: Изменение x, y
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
@ -92,7 +107,7 @@ namespace ProjectExcavator
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityExcavator.Step > -50)
|
||||
if (_startPosY - EntityExcavator.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityExcavator.Step;
|
||||
}
|
||||
@ -117,20 +132,13 @@ namespace ProjectExcavator
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityExcavator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
Brush additionalBrush = new SolidBrush(EntityExcavator.AdditionalColor);
|
||||
if (EntityExcavator.BodyKit)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 20, _startPosY + 120, 130, 10);
|
||||
g.DrawLine(pen, _startPosX + 20, _startPosY + 120, _startPosX + 150, _startPosY + 120);
|
||||
}
|
||||
//корпус
|
||||
Brush bodyBrush = new SolidBrush(Color.Red);
|
||||
g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 110, 130, 20);
|
||||
@ -156,17 +164,7 @@ namespace ProjectExcavator
|
||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 130, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 100, _startPosY + 130, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 130, 20, 20);
|
||||
//ковш
|
||||
if (EntityExcavator.Backet)
|
||||
{
|
||||
Point[] pointsBacket = {
|
||||
new Point(_startPosX + 150, _startPosY + 75),
|
||||
new Point(_startPosX + 150, _startPosY + 135),
|
||||
new Point(_startPosX + 195, _startPosY + 135),
|
||||
};
|
||||
g.FillPolygon(additionalBrush, pointsBacket);
|
||||
g.DrawPolygon(pen, pointsBacket);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
namespace ProjectExcavator.Entities
|
||||
{
|
||||
internal class EntityExcavator
|
||||
public class EntityExcavator
|
||||
{
|
||||
// <summary>
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
@ -20,42 +20,21 @@ namespace ProjectExcavator
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия вспомогательных опор
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия ковша
|
||||
/// </summary>
|
||||
public bool Backet { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// Конструктор с параметрами
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="backet">Признак наличия антикрыла</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool backet)
|
||||
public EntityExcavator(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Backet = backet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
47
ProjectExcavator/ProjectExcavator/EntityExcavatorBodyKits.cs
Normal file
47
ProjectExcavator/ProjectExcavator/EntityExcavatorBodyKits.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Спортивный автомобиль"
|
||||
/// </summary>
|
||||
public class EntityExcavatorBodyKits : EntityExcavator
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// признак наличия вспомогательных опор
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия ковша
|
||||
/// </summary>
|
||||
public bool Bucket { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса экскаватора
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес экскаватора</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="bucket">Признак наличия ковша</param>
|
||||
public EntityExcavatorBodyKits(int speed, double weight,
|
||||
Color bodyColor, Color additionalColor,
|
||||
bool bodyKit, bool bucket)
|
||||
{
|
||||
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Bucket = bucket;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user