СМЭРТЬ
This commit is contained in:
parent
0d0d57578e
commit
b6e2b79297
136
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/AbstractStrategy.cs
Normal file
136
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/AbstractStrategy.cs
Normal file
@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RPP_FirstLaba_Tractor.DrawningObjects;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private Status _state = Status.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public Status GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int
|
||||
height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false -неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="directionType">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false -неудача)</returns>
|
||||
private bool MoveTo(DirectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Спортивный автомобиль"
|
||||
/// </summary>
|
||||
public class EntityBuldoserTractor : EntityTractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// </summary>
|
||||
public bool Wing { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool SportLine { 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="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public EntityBuldoserTractor(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool wing, bool sportLine):
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Wing = wing;
|
||||
SportLine = sportLine;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RPP_FirstLaba_Tractor.Entities;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningBuldoserTractor : DrawningTractor
|
||||
{
|
||||
/// <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>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawningBuldoserTractor(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) :
|
||||
base(speed, weight, bodyColor, width, height, 110, 60)
|
||||
{
|
||||
if (EntityTractor != null)
|
||||
{
|
||||
EntityTractor = new EntityBuldoserTractor(speed, weight, bodyColor,
|
||||
additionalColor, bodyKit, wing, sportLine);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTractor is not EntityBuldoserTractor sportCar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(sportCar.AdditionalColor);
|
||||
// обвесы
|
||||
if (sportCar.BodyKit)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20,
|
||||
20);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10,
|
||||
20, 40);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15,
|
||||
15);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45,
|
||||
15, 15);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 90,
|
||||
_startPosY, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 90,
|
||||
_startPosY + 40, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 90,
|
||||
_startPosY + 10, 20, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 90,
|
||||
_startPosY + 1, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 90,
|
||||
_startPosY + 45, 15, 15);
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20,
|
||||
40);
|
||||
g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14,
|
||||
15);
|
||||
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45,
|
||||
14, 15);
|
||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY,
|
||||
20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY +
|
||||
40, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 1,
|
||||
_startPosY + 10, 25, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 5,
|
||||
_startPosY + 1, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 5,
|
||||
_startPosY + 45, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39,
|
||||
15);
|
||||
g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45,
|
||||
39, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 35,
|
||||
_startPosY + 1, 40, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 35,
|
||||
_startPosY + 45, 40, 15);
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
// спортивная линия
|
||||
if (sportCar.SportLine)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 75,
|
||||
_startPosY + 23, 25, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 35,
|
||||
_startPosY + 23, 35, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 10,
|
||||
_startPosY + 23, 20, 15);
|
||||
}
|
||||
// крыло
|
||||
if (sportCar.Wing)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX, _startPosY
|
||||
+ 5, 10, 50);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10,
|
||||
50);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RPP_FirstLaba_Tractor.DrawningObjects;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{
|
||||
public class DrawingObjectTractor : IMoveableObject
|
||||
{
|
||||
private readonly DrawningTractor? _drawningCar = null;
|
||||
public DrawingObjectTractor(DrawningTractor drawningTractor)
|
||||
{
|
||||
_drawningCar = drawningTractor;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningCar == null || _drawningCar.EntityTractor ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningCar.GetPosX,
|
||||
_drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningCar?.EntityTractor?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawningCar?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawningCar?.MoveTransport(direction);
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,19 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RPP_FirstLaba_Tractor.Entities;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor
|
||||
namespace RPP_FirstLaba_Tractor.DrawningObjects
|
||||
{
|
||||
internal class DrawningTractor
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningTractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityTractor? EntityTractor { get; private set; }
|
||||
public EntityTractor? EntityTractor { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -23,46 +27,54 @@ namespace RPP_FirstLaba_Tractor
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int _startPosX;
|
||||
protected int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int _startPosY;
|
||||
protected int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _tractorWidth = 80;
|
||||
protected readonly int _tractorWidth = 100;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _tractorHeight = 60;
|
||||
protected readonly int _tractorHeight = 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="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</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, int width, int height)
|
||||
public DrawningTractor(int speed, double weight, Color bodyColor, int
|
||||
width, int height)
|
||||
{
|
||||
|
||||
// TODO: Продумать проверки
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_tractorWidth > _pictureHeight || _tractorHeight > _pictureHeight)
|
||||
{
|
||||
_pictureWidth = 2 * _tractorWidth;
|
||||
_pictureHeight = 2 * _tractorHeight;
|
||||
|
||||
}
|
||||
EntityTractor = new EntityTractor();
|
||||
EntityTractor.Init(speed, weight, bodyColor);
|
||||
return true;
|
||||
EntityTractor = new EntityTractor(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="carWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="carHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawningTractor(int speed, double weight, Color bodyColor, int
|
||||
width, int height, int carWidth, int carHeight)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_tractorWidth = carWidth;
|
||||
_tractorHeight = carHeight;
|
||||
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
@ -71,25 +83,61 @@ namespace RPP_FirstLaba_Tractor
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
// TODO: Изменение x, y, если при установке объект выходит заграницы
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
if ((x + _tractorWidth > _pictureWidth) || (y + _pictureHeight > _pictureHeight))
|
||||
{
|
||||
Random random = new();
|
||||
x = random.Next(0, _pictureWidth);
|
||||
x = random.Next(0, _pictureHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
///
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _tractorWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _tractorHeight;
|
||||
|
||||
public void MoveTransport(DirectionType direction)
|
||||
/// <summary>
|
||||
/// Проверка, что объект может переместится по указанному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - можно переместится по указанномунаправлению</returns>
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityTractor == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityTractor.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityTractor.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + EntityTractor.Step + _tractorWidth < _pictureWidth,
|
||||
DirectionType.Down => _startPosY + EntityTractor.Step + _tractorHeight < _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityTractor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -97,84 +145,73 @@ namespace RPP_FirstLaba_Tractor
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityTractor.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityTractor.Step;
|
||||
}
|
||||
_startPosX -= (int)EntityTractor.Step;
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityTractor.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityTractor.Step;
|
||||
}
|
||||
_startPosY -= (int)EntityTractor.Step;
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + _tractorWidth + EntityTractor.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityTractor.Step;
|
||||
}
|
||||
_startPosX += (int)EntityTractor.Step;
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + _tractorHeight + EntityTractor.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityTractor.Step;
|
||||
}
|
||||
_startPosY += (int)EntityTractor.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTractor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brGray = new SolidBrush(Color.Gray);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(EntityTractor.BodyColor);
|
||||
|
||||
//Гусеницы
|
||||
g.FillEllipse(brGray, _startPosX, _startPosY + 41, 25, 25);
|
||||
g.FillEllipse(brGray, _startPosX + 55, _startPosY + 41, 25, 25);
|
||||
g.FillRectangle(brGray, _startPosX + 13, _startPosY + 41, 54, 25);
|
||||
//колеса
|
||||
g.FillEllipse(brBlack, _startPosX, _startPosY + 45, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 45, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 55, 10, 10);
|
||||
g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 55, 10, 10);
|
||||
g.FillEllipse(brBlack, _startPosX + 50, _startPosY + 55, 10, 10);
|
||||
g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 40, 10, 10);
|
||||
g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 40, 10, 10);
|
||||
//границы автомобиля
|
||||
g.DrawEllipse(pen, _startPosX + 10, _startPosY + 5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,30);
|
||||
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
|
||||
//задние фары
|
||||
Brush brRed = new SolidBrush(Color.Red);
|
||||
g.FillEllipse(brRed, _startPosX + 10, _startPosY + 5, 20, 20);
|
||||
g.FillEllipse(brRed, _startPosX + 10, _startPosY + 35, 20,20);
|
||||
//передние фары
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,20);
|
||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
|
||||
20);
|
||||
//кузов
|
||||
g.FillRectangle(additionalBrush, _startPosX, _startPosY + 20, 80, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 60, _startPosY, 10, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX, _startPosY, 40, 20);
|
||||
|
||||
//Окно
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
g.FillRectangle(brBlue, _startPosX + 10, _startPosY + 3, 25, 15);
|
||||
|
||||
//Колеса
|
||||
g.FillEllipse(additionalBrush, _startPosX + 2, _startPosY + 47, 11, 11);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 67, _startPosY + 47, 11, 11);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 37, _startPosY + 57, 6, 6);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 22, _startPosY + 57, 6, 6);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 52, _startPosY + 57, 6, 6);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 27, _startPosY + 42, 6, 6);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 47, _startPosY + 42, 6, 6);
|
||||
|
||||
//границы трактора
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 20, 80, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 60, _startPosY, 10, 20);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY, 40, 20);
|
||||
Brush br = new SolidBrush(EntityTractor.BodyColor);
|
||||
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
|
||||
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
|
||||
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
|
||||
//стекла
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 10, 5,
|
||||
40);
|
||||
g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 10, 5,
|
||||
40);
|
||||
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 8, 35,
|
||||
2);
|
||||
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 51, 35,
|
||||
2);
|
||||
//выделяем рамкой крышу
|
||||
g.DrawRectangle(pen, _startPosX + 35, _startPosY + 10, 35,
|
||||
40);
|
||||
g.DrawRectangle(pen, _startPosX + 75, _startPosY + 15, 25,
|
||||
30);
|
||||
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 15, 15,
|
||||
30);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
using RPP_FirstLaba_Tractor.MovementStrategy;
|
||||
using RPP_FirstLaba_Tractor.DrawningObjects;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor
|
||||
{
|
||||
/// <summary>
|
||||
@ -6,12 +9,20 @@ namespace RPP_FirstLaba_Tractor
|
||||
public partial class FormTractor : Form
|
||||
{
|
||||
private PictureBox pictureBoxTractor;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreateTractor;
|
||||
private Button buttonTop;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateBulldoserTractor;
|
||||
private Button buttonStep;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonRight;
|
||||
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
public int getPictureWidth()
|
||||
{
|
||||
return pictureBoxTractor.Width;
|
||||
@ -55,8 +66,7 @@ namespace RPP_FirstLaba_Tractor
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningTractor = new DrawningTractor();
|
||||
_drawningTractor.Init(random.Next(100, 300),
|
||||
_drawningTractor = new DrawningTractor(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
@ -99,11 +109,14 @@ namespace RPP_FirstLaba_Tractor
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxTractor = new System.Windows.Forms.PictureBox();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.buttonCreateTractor = new System.Windows.Forms.Button();
|
||||
this.buttonTop = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonCreateBulldoserTractor = new System.Windows.Forms.Button();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -117,16 +130,16 @@ namespace RPP_FirstLaba_Tractor
|
||||
this.pictureBoxTractor.TabIndex = 0;
|
||||
this.pictureBoxTractor.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
// buttonCreateTractor
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(12, 440);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCreate.TabIndex = 1;
|
||||
this.buttonCreate.Text = "Ñîçäàòü";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
this.buttonCreateTractor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateTractor.Location = new System.Drawing.Point(12, 440);
|
||||
this.buttonCreateTractor.Name = "buttonCreateTractor";
|
||||
this.buttonCreateTractor.Size = new System.Drawing.Size(246, 29);
|
||||
this.buttonCreateTractor.TabIndex = 1;
|
||||
this.buttonCreateTractor.Text = "Ñîçäàòü òðàêòîð";
|
||||
this.buttonCreateTractor.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateTractor.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// buttonTop
|
||||
//
|
||||
@ -176,14 +189,52 @@ namespace RPP_FirstLaba_Tractor
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateBulldoserTractor
|
||||
//
|
||||
this.buttonCreateBulldoserTractor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateBulldoserTractor.Location = new System.Drawing.Point(264, 440);
|
||||
this.buttonCreateBulldoserTractor.Name = "buttonCreateBulldoserTractor";
|
||||
this.buttonCreateBulldoserTractor.Size = new System.Drawing.Size(199, 29);
|
||||
this.buttonCreateBulldoserTractor.TabIndex = 6;
|
||||
this.buttonCreateBulldoserTractor.Text = "Ñîçäàòü áóëüäîçåð";
|
||||
this.buttonCreateBulldoserTractor.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateBulldoserTractor.Click += new System.EventHandler(this.buttonCreateBulldoserTractor_Click);
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonStep.Location = new System.Drawing.Point(785, 46);
|
||||
this.buttonStep.Name = "buttonStep";
|
||||
this.buttonStep.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonStep.TabIndex = 7;
|
||||
this.buttonStep.Text = "button2";
|
||||
this.buttonStep.UseVisualStyleBackColor = true;
|
||||
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
this.comboBoxStrategy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxStrategy.FormattingEnabled = true;
|
||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||
"Öåíòð ",
|
||||
"Ïðàâûé íèæíèé"});
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(728, 12);
|
||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28);
|
||||
this.comboBoxStrategy.TabIndex = 8;
|
||||
//
|
||||
// FormTractor
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(891, 490);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.buttonCreateBulldoserTractor);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonTop);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.buttonCreateTractor);
|
||||
this.Controls.Add(this.pictureBoxTractor);
|
||||
this.Name = "FormTractor";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).EndInit();
|
||||
@ -192,5 +243,59 @@ namespace RPP_FirstLaba_Tractor
|
||||
|
||||
}
|
||||
|
||||
private void buttonCreateBulldoserTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningTractor = new DrawningBuldoserTractor(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)),
|
||||
buttonCreateBulldoserTractor.Width, buttonCreateBulldoserTractor.Height);
|
||||
_drawningTractor.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningTractor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawingObjectTractor(_drawningTractor), pictureBoxTractor.Width,
|
||||
pictureBoxTractor.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
//using RPP_FirstLaba_Tractor.Drawnings;
|
||||
|
||||
|
||||
namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты X объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Проверка, можно ли переместиться по нужному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(DirectionType direction);
|
||||
}
|
||||
|
||||
}
|
41
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/MoveToBorder.cs
Normal file
41
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/MoveToBorder.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{
|
||||
internal class MoveToBorder: AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = FieldWidth - objParams.RightBorder;
|
||||
if (diffX > GetStep())
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
var diffY = FieldHeight - objParams.DownBorder;
|
||||
if (diffY > GetStep())
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/MoveToCenter.cs
Normal file
57
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/MoveToCenter.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{
|
||||
internal class MoveToCenter: AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
/// </summary>
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
18
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Status.cs
Normal file
18
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Status.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum Status
|
||||
{
|
||||
NotInit, InProgress,
|
||||
Finish
|
||||
}
|
||||
|
||||
}
|
@ -4,40 +4,40 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor
|
||||
namespace RPP_FirstLaba_Tractor.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Автомобиль"
|
||||
/// </summary>
|
||||
public class EntityTractor
|
||||
{
|
||||
public class EntityTractor
|
||||
/// <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 => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Конструктор с параметрами
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityTractor(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
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="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public void Init(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user