PIbd-23 Firsov Kirill LabWork 01 #4
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.2.32602.215
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RPP_FirstLaba_Tractor", "RPP_FirstLaba_Tractor\RPP_FirstLaba_Tractor.csproj", "{EF413F48-FFBF-4510-BA11-FAEBE7C0142A}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RPP_FirstLaba_Tractor", "RPP_FirstLaba_Tractor\RPP_FirstLaba_Tractor.csproj", "{EF413F48-FFBF-4510-BA11-FAEBE7C0142A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -71,7 +71,7 @@ namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false -неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
@ -131,6 +131,5 @@ namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,217 +0,0 @@
|
||||
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 DrawningTractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityTractor? EntityTractor { 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>
|
||||
protected readonly int _tractorWidth = 100;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected readonly int _tractorHeight = 55;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawningTractor(int speed, double weight, Color bodyColor, int
|
||||
width, int height)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
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>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
// TODO: Изменение x, y, если при установке объект выходит заграницы
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
/// <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;
|
||||
|
||||
/// <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;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
_startPosX -= (int)EntityTractor.Step;
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
_startPosY -= (int)EntityTractor.Step;
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
_startPosX += (int)EntityTractor.Step;
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
_startPosY += (int)EntityTractor.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTractor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
//границы автомобиля
|
||||
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);
|
||||
//кузов
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
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 DrawningBulldoser : DrawningTractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="wheelsOrnament">Признак наличия орнамента на колесах</param>
|
||||
/// <param name="blade">Признак наличия отвала</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawningBulldoser(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool wheelsOrnament, bool blade, int width, int height) :
|
||||
base(speed, weight, bodyColor, width, height, 110, 60)
|
||||
{
|
||||
if (EntityTractor != null)
|
||||
{
|
||||
EntityTractor = new EntityBulldoser(speed, weight, bodyColor,
|
||||
additionalColor, wheelsOrnament, blade);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTractor is not EntityBulldoser bulldoser)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(bulldoser.AdditionalColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
if (bulldoser.WheelsOrnament)
|
||||
{
|
||||
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.DrawLine(pen, _startPosX + 7, _startPosY + 47, _startPosX + 7, _startPosY + 58);
|
||||
g.DrawLine(pen, _startPosX + 2, _startPosY + 53, _startPosX + 13, _startPosY + 53);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 73, _startPosY + 47, _startPosX + 73, _startPosY + 58);
|
||||
g.DrawLine(pen, _startPosX + 67, _startPosY + 53, _startPosX + 78, _startPosY + 53);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 40, _startPosY + 57, _startPosX + 40, _startPosY + 62);
|
||||
g.DrawLine(pen, _startPosX + 37, _startPosY + 60, _startPosX + 43, _startPosY + 60);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 25, _startPosY + 57, _startPosX + 25, _startPosY + 62);
|
||||
g.DrawLine(pen, _startPosX + 22, _startPosY + 60, _startPosX + 28, _startPosY + 60);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 55, _startPosY + 57, _startPosX + 55, _startPosY + 62);
|
||||
g.DrawLine(pen, _startPosX + 52, _startPosY + 60, _startPosX + 58, _startPosY + 60);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 30, _startPosY + 42, _startPosX + 30, _startPosY + 48);
|
||||
g.DrawLine(pen, _startPosX + 27, _startPosY + 45, _startPosX + 33, _startPosY + 45);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 50, _startPosY + 42, _startPosX + 50, _startPosY + 48);
|
||||
g.DrawLine(pen, _startPosX + 47, _startPosY + 45, _startPosX + 53, _startPosY + 45);
|
||||
}
|
||||
// отвал
|
||||
if (bulldoser.Blade)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 82, _startPosY + 30, 10, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 82, _startPosY + 60, 40, 10);
|
||||
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 82, _startPosY + 60 - i * 2, 40 - i * 2, 10);
|
||||
}
|
||||
|
||||
g.FillRectangle(additionalBrush, _startPosX + 50, _startPosY + 25, 10, 10);
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 50 + i * 2, _startPosY + 25 + i, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
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>
|
||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningTractor(паттерн Adapter)
|
||||
/// </summary>
|
||||
public class DrawningObjectTractor : IMoveableObject
|
||||
{
|
||||
private readonly DrawningTractor? _drawningTractor = null;
|
||||
public DrawningObjectTractor(DrawningTractor drawningTractor)
|
||||
{
|
||||
_drawningTractor = drawningTractor;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningTractor == null || _drawningTractor.EntityTractor ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningTractor.GetPosX,
|
||||
_drawningTractor.GetPosY, _drawningTractor.GetWidth, _drawningTractor.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningTractor?.EntityTractor?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawningTractor?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawningTractor?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
}
|
229
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs
Normal file
229
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs
Normal file
@ -0,0 +1,229 @@
|
||||
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 DrawningTractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityTractor? EntityTractor { 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>
|
||||
protected readonly int _tractorWidth = 75;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected readonly int _tractorHeight = 60;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawningTractor(int speed, double weight, Color bodyColor, int
|
||||
width, int height)
|
||||
{
|
||||
if (width <= _tractorWidth || height <= _tractorHeight)
|
||||
return;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
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="tractorWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="tractorHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawningTractor(int speed, double weight, Color bodyColor, int
|
||||
width, int height, int tractorWidth, int tractorHeight)
|
||||
{
|
||||
if (width <= _tractorWidth || height <= _tractorHeight)
|
||||
return;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_tractorWidth = tractorWidth;
|
||||
_tractorHeight = tractorHeight;
|
||||
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
|
||||
/// <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;
|
||||
/// <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;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
_startPosX -= (int)EntityTractor.Step;
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
_startPosY -= (int)EntityTractor.Step;
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
_startPosX += (int)EntityTractor.Step;
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
_startPosY += (int)EntityTractor.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (EntityTractor == null)
|
||||
return;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
if (x + _tractorWidth >= _pictureWidth || y + _tractorHeight >= _pictureHeight)
|
||||
{
|
||||
_startPosX = 1;
|
||||
_startPosY = (_tractorHeight + _tractorHeight) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@ namespace RPP_FirstLaba_Tractor.Entities
|
||||
/// <summary>
|
||||
/// Класс-сущность "Спортивный автомобиль"
|
||||
/// </summary>
|
||||
public class EntityBuldoserTractor : EntityTractor
|
||||
public class EntityBulldoser : EntityTractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
@ -18,15 +18,12 @@ namespace RPP_FirstLaba_Tractor.Entities
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
public bool WheelsOrnament { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// </summary>
|
||||
public bool Wing { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool SportLine { get; private set; }
|
||||
public bool Blade { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// </summary>
|
||||
@ -34,17 +31,15 @@ namespace RPP_FirstLaba_Tractor.Entities
|
||||
/// <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)
|
||||
/// <param name="wheelsOrnament">Признак наличия обвеса</param>
|
||||
/// <param name="blade">Признак наличия отвала</param>
|
||||
|
||||
public EntityBulldoser(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool wheelsOrnament, bool blade) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Wing = wing;
|
||||
SportLine = sportLine;
|
||||
WheelsOrnament = wheelsOrnament;
|
||||
Blade = blade;
|
||||
}
|
||||
}
|
||||
|
44
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityTractor.cs
Normal file
44
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityTractor.cs
Normal file
@ -0,0 +1,44 @@
|
||||
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 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)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
|
||||
using RPP_FirstLaba_Tractor.MovementStrategy;
|
||||
using RPP_FirstLaba_Tractor.DrawningObjects;
|
||||
|
||||
@ -125,7 +126,7 @@ namespace RPP_FirstLaba_Tractor
|
||||
this.pictureBoxTractor.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxTractor.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxTractor.Name = "pictureBoxTractor";
|
||||
this.pictureBoxTractor.Size = new System.Drawing.Size(891, 490);
|
||||
this.pictureBoxTractor.Size = new System.Drawing.Size(882, 453);
|
||||
this.pictureBoxTractor.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxTractor.TabIndex = 0;
|
||||
this.pictureBoxTractor.TabStop = false;
|
||||
@ -133,7 +134,7 @@ namespace RPP_FirstLaba_Tractor
|
||||
// buttonCreateTractor
|
||||
//
|
||||
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.Location = new System.Drawing.Point(12, 403);
|
||||
this.buttonCreateTractor.Name = "buttonCreateTractor";
|
||||
this.buttonCreateTractor.Size = new System.Drawing.Size(246, 29);
|
||||
this.buttonCreateTractor.TabIndex = 1;
|
||||
@ -146,7 +147,7 @@ namespace RPP_FirstLaba_Tractor
|
||||
this.buttonTop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonTop.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowUp;
|
||||
this.buttonTop.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonTop.Location = new System.Drawing.Point(813, 412);
|
||||
this.buttonTop.Location = new System.Drawing.Point(804, 375);
|
||||
this.buttonTop.Name = "buttonTop";
|
||||
this.buttonTop.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonTop.TabIndex = 2;
|
||||
@ -158,7 +159,7 @@ namespace RPP_FirstLaba_Tractor
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(777, 448);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(768, 411);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 3;
|
||||
@ -170,7 +171,7 @@ namespace RPP_FirstLaba_Tractor
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(813, 448);
|
||||
this.buttonDown.Location = new System.Drawing.Point(804, 411);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 4;
|
||||
@ -182,7 +183,7 @@ namespace RPP_FirstLaba_Tractor
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::RPP_FirstLaba_Tractor.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(849, 448);
|
||||
this.buttonRight.Location = new System.Drawing.Point(840, 411);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 5;
|
||||
@ -192,7 +193,7 @@ namespace RPP_FirstLaba_Tractor
|
||||
// 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.Location = new System.Drawing.Point(264, 403);
|
||||
this.buttonCreateBulldoserTractor.Name = "buttonCreateBulldoserTractor";
|
||||
this.buttonCreateBulldoserTractor.Size = new System.Drawing.Size(199, 29);
|
||||
this.buttonCreateBulldoserTractor.TabIndex = 6;
|
||||
@ -203,11 +204,11 @@ namespace RPP_FirstLaba_Tractor
|
||||
// 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.Location = new System.Drawing.Point(776, 46);
|
||||
this.buttonStep.Name = "buttonStep";
|
||||
this.buttonStep.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonStep.TabIndex = 7;
|
||||
this.buttonStep.Text = "button2";
|
||||
this.buttonStep.Text = "Øàã";
|
||||
this.buttonStep.UseVisualStyleBackColor = true;
|
||||
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||
//
|
||||
@ -219,14 +220,14 @@ namespace RPP_FirstLaba_Tractor
|
||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||
"Öåíòð ",
|
||||
"Ïðàâûé íèæíèé"});
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(728, 12);
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(719, 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.ClientSize = new System.Drawing.Size(882, 453);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.buttonCreateBulldoserTractor);
|
||||
@ -246,15 +247,15 @@ namespace RPP_FirstLaba_Tractor
|
||||
private void buttonCreateBulldoserTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningTractor = new DrawningBuldoserTractor(random.Next(100, 300),
|
||||
_drawningTractor = new DrawningBulldoser(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);
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxTractor.Width, pictureBoxTractor.Height);
|
||||
_drawningTractor.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
@ -281,7 +282,7 @@ namespace RPP_FirstLaba_Tractor
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawingObjectTractor(_drawningTractor), pictureBoxTractor.Width,
|
||||
DrawningObjectTractor(_drawningTractor), pictureBoxTractor.Width,
|
||||
pictureBoxTractor.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
|
@ -3,13 +3,12 @@ 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>
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -6,7 +6,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{
|
||||
internal class MoveToBorder: AbstractStrategy
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в центр экрана
|
||||
/// </summary>
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
@ -15,10 +18,10 @@ namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
return objParams.RightBorder <= FieldWidth
|
||||
&& objParams.RightBorder + GetStep() >= FieldWidth
|
||||
&& objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
@ -26,15 +29,21 @@ namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = FieldWidth - objParams.RightBorder;
|
||||
if (diffX > GetStep())
|
||||
var diffX = objParams.RightBorder - (FieldWidth - 1);
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
MoveRight();
|
||||
if (diffX < 0)
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = FieldHeight - objParams.DownBorder;
|
||||
if (diffY > GetStep())
|
||||
var diffY = objParams.DownBorder - (FieldHeight - 1);
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
MoveDown();
|
||||
if (diffY < 0)
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{
|
||||
internal class MoveToCenter: AbstractStrategy
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в центр экрана
|
||||
/// </summary>
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
@ -54,4 +57,3 @@ namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor
|
||||
namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
@ -54,4 +54,5 @@ namespace RPP_FirstLaba_Tractor
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,14 +4,15 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP_FirstLaba_Tractor
|
||||
namespace RPP_FirstLaba_Tractor.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum Status
|
||||
{
|
||||
NotInit, InProgress,
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
|
||||
|
@ -1,43 +0,0 @@
|
||||
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 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)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user