Добавление стратегии
This commit is contained in:
commit
a7bcf86f4f
@ -1,29 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace ProjectBulldozer.Drawnings;
|
||||
|
||||
namespace ProjectBulldozer;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
|
||||
//сделано
|
@ -1,278 +0,0 @@
|
||||
namespace ProjectBulldozer;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningBulldozer
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBulldozer? EntityBulldozer { get; private set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _BulldozerWidth = 180;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _BulldozerHeight = 140;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="additionalOtval">Признак наличия отвала спереди</param>
|
||||
/// <param name="additionalRihl">Признак наличия рыхлителя сзади</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool additionalOtval, bool additionalRihl)
|
||||
{
|
||||
EntityBulldozer = new EntityBulldozer();
|
||||
EntityBulldozer.Init(speed, weight, bodyColor, additionalColor, additionalOtval,
|
||||
additionalRihl);
|
||||
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_BulldozerWidth < width && _BulldozerHeight < height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
SetPosition(_startPosX.Value, _startPosY.Value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (x < 0 || x + _BulldozerWidth > _pictureWidth || y < 0 || y + _BulldozerHeight > _pictureHeight)
|
||||
{
|
||||
_startPosX = _pictureWidth - _BulldozerWidth;
|
||||
_startPosY = _pictureHeight - _BulldozerHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение
|
||||
public bool MoveTransport(DirectionType direction) {
|
||||
|
||||
if (EntityBulldozer == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityBulldozer.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityBulldozer.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityBulldozer.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityBulldozer.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + _BulldozerWidth + EntityBulldozer.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityBulldozer.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + _BulldozerHeight + EntityBulldozer.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityBulldozer.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBulldozer == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brush = new SolidBrush(Color.Black);
|
||||
Brush bl = new SolidBrush(EntityBulldozer.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityBulldozer.BodyColor);
|
||||
Brush bodyBrush2 = new SolidBrush(EntityBulldozer.AdditionalColor);
|
||||
|
||||
|
||||
|
||||
|
||||
//основное тело
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 20, _startPosY.Value + 40, 120, 60);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 40, 120, 60);
|
||||
|
||||
|
||||
|
||||
//Гусеницы
|
||||
Brush gg = new SolidBrush(Color.LightGray);
|
||||
g.FillEllipse(gg, _startPosX.Value + 23, _startPosY.Value + 101, 118, 35);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 23, _startPosY.Value + 101, 118, 35);
|
||||
|
||||
|
||||
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 26, _startPosY.Value + 103, 110, 30);
|
||||
|
||||
//катки в гусеницах
|
||||
Brush gr = new SolidBrush(Color.Gray);
|
||||
g.FillEllipse(gr, _startPosX.Value + 40, _startPosY.Value + 108, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 108, 20, 20);
|
||||
|
||||
|
||||
g.FillEllipse(gr, _startPosX.Value + 65, _startPosY.Value + 110, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 65, _startPosY.Value + 110, 20, 20);
|
||||
|
||||
g.FillEllipse(gr, _startPosX.Value + 115, _startPosY.Value + 110, 15, 15);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 115, _startPosY.Value + 110, 15, 15);
|
||||
|
||||
g.FillEllipse(gr, _startPosX.Value + 90, _startPosY.Value + 110, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 110, 20, 20);
|
||||
|
||||
|
||||
|
||||
|
||||
//кабина водителя
|
||||
g.FillRectangle(bodyBrush2, _startPosX.Value + 20, _startPosY.Value, 40, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value, 40, 40);
|
||||
|
||||
|
||||
//выхлопная труба
|
||||
Brush brBr = new SolidBrush(Color.Brown);
|
||||
|
||||
g.FillRectangle(brBr, _startPosX.Value + 110, _startPosY.Value, 15, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value, 15, 40);
|
||||
|
||||
|
||||
|
||||
//Brush bl = new SolidBrush(Color.LightYellow);
|
||||
/////////отвал
|
||||
///
|
||||
if (EntityBulldozer.AdditionalOtval)
|
||||
{
|
||||
Point[] Otval =
|
||||
{
|
||||
new Point(_startPosX.Value + 142, _startPosY.Value + 70),
|
||||
new Point(_startPosX.Value + 172, _startPosY.Value + 130),
|
||||
new Point(_startPosX.Value+ 142, _startPosY.Value + 130),
|
||||
|
||||
|
||||
};
|
||||
|
||||
g.FillPolygon(bl, Otval);
|
||||
g.DrawPolygon(pen, Otval);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///рыхлитель
|
||||
if (EntityBulldozer.AdditionalRihl)
|
||||
{
|
||||
Brush black = new SolidBrush(Color.Black);
|
||||
Point[] Rihl =
|
||||
{
|
||||
new Point(_startPosX.Value + 18 , _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 18, _startPosY.Value + 80),
|
||||
new Point(_startPosX.Value, _startPosY.Value + 120),
|
||||
|
||||
};
|
||||
|
||||
g.FillPolygon(black, Rihl);
|
||||
g.DrawPolygon(pen, Rihl);
|
||||
|
||||
Point[] Ttt =
|
||||
{
|
||||
new Point(_startPosX.Value + 18 , _startPosY.Value + 80),
|
||||
new Point(_startPosX.Value + 18, _startPosY.Value + 120),
|
||||
new Point(_startPosX.Value, _startPosY.Value + 50),
|
||||
|
||||
};
|
||||
g.FillPolygon(black, Ttt);
|
||||
g.DrawPolygon(pen, Ttt);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
31
ProjectBulldozer/ProjectBulldozer/Drawnings/DirectionType.cs
Normal file
31
ProjectBulldozer/ProjectBulldozer/Drawnings/DirectionType.cs
Normal file
@ -0,0 +1,31 @@
|
||||
namespace ProjectBulldozer.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType1
|
||||
{
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
|
||||
|
||||
//сделано
|
104
ProjectBulldozer/ProjectBulldozer/Drawnings/DrawingBulldozer.cs
Normal file
104
ProjectBulldozer/ProjectBulldozer/Drawnings/DrawingBulldozer.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using ProjectBulldozer.Entities;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ProjectBulldozer.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningBulldozer : DrawningBulldozerProstoy
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="additionalOtval">Признак наличия отвала спереди</param>
|
||||
/// <param name="additionalRihl">Признак наличия рыхлителя сзади</param>
|
||||
|
||||
public DrawningBulldozer(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool additionalOtval, bool additionalRihl, bool v) : base(180, 140)
|
||||
{
|
||||
EntityBulldozerProstoy = new EntityBulldozer(speed, weight, bodyColor, additionalColor, additionalOtval,
|
||||
additionalRihl);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBulldozerProstoy == null || EntityBulldozerProstoy is not EntityBulldozer Bulldozer || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(Bulldozer.BodyColor);
|
||||
Brush bodyBrush2 = new SolidBrush(Bulldozer.AdditionalColor);
|
||||
|
||||
|
||||
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
|
||||
Brush bl = new SolidBrush(Bulldozer.AdditionalColor);
|
||||
/////////отвал
|
||||
///
|
||||
if (Bulldozer.AdditionalOtval)
|
||||
{
|
||||
Point[] Otval =
|
||||
{
|
||||
new Point(_startPosX.Value + 142, _startPosY.Value + 70),
|
||||
new Point(_startPosX.Value + 172, _startPosY.Value + 130),
|
||||
new Point(_startPosX.Value+ 142, _startPosY.Value + 130),
|
||||
|
||||
|
||||
};
|
||||
|
||||
g.FillPolygon(bl, Otval);
|
||||
g.DrawPolygon(pen, Otval);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///рыхлитель
|
||||
if (Bulldozer.AdditionalRihl)
|
||||
{
|
||||
Brush black = new SolidBrush(Color.Black);
|
||||
Point[] Rihl =
|
||||
{
|
||||
new Point(_startPosX.Value + 18 , _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 18, _startPosY.Value + 80),
|
||||
new Point(_startPosX.Value, _startPosY.Value + 120),
|
||||
|
||||
};
|
||||
|
||||
g.FillPolygon(black, Rihl);
|
||||
g.DrawPolygon(pen, Rihl);
|
||||
|
||||
Point[] Ttt =
|
||||
{
|
||||
new Point(_startPosX.Value + 18 , _startPosY.Value + 80),
|
||||
new Point(_startPosX.Value + 18, _startPosY.Value + 120),
|
||||
new Point(_startPosX.Value, _startPosY.Value + 50),
|
||||
|
||||
};
|
||||
g.FillPolygon(black, Ttt);
|
||||
g.DrawPolygon(pen, Ttt);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,252 @@
|
||||
using ProjectBulldozer.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBulldozer.Drawnings;
|
||||
|
||||
public class DrawningBulldozerProstoy
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBulldozerProstoy? EntityBulldozerProstoy { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки бульдозера
|
||||
/// </summary>
|
||||
private readonly int _BulldozerWidth = 130;
|
||||
/// <summary>
|
||||
/// Высота прорисовки бульдозера
|
||||
/// </summary>
|
||||
private readonly int _BulldozerHeight = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _BulldozerWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _BulldozerHeight;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningBulldozerProstoy()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningBulldozerProstoy(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityBulldozerProstoy = new EntityBulldozerProstoy(speed, weight, bodyColor);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="BulldozerWidth">Ширина прорисовки бульдозера</param>
|
||||
/// <param name="BulldozerHeight">Высота прорисовки бульдозера</param>
|
||||
protected DrawningBulldozerProstoy(int BulldozerWidth, int BulldozerHeight) : this()
|
||||
{
|
||||
_BulldozerWidth = BulldozerWidth;
|
||||
_BulldozerHeight = BulldozerHeight;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_BulldozerWidth < width && _BulldozerHeight < height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
SetPosition(_startPosX.Value, _startPosY.Value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (x < 0 || x + _BulldozerWidth > _pictureWidth || y < 0 || y + _BulldozerHeight > _pictureHeight)
|
||||
{
|
||||
_startPosX = _pictureWidth - _BulldozerWidth;
|
||||
_startPosY = _pictureHeight - _BulldozerHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
|
||||
if (EntityBulldozerProstoy == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityBulldozerProstoy.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityBulldozerProstoy.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityBulldozerProstoy.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityBulldozerProstoy.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + _BulldozerWidth + EntityBulldozerProstoy.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityBulldozerProstoy.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + _BulldozerHeight + EntityBulldozerProstoy.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityBulldozerProstoy.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBulldozerProstoy == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brush = new SolidBrush(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(EntityBulldozerProstoy.BodyColor);
|
||||
|
||||
|
||||
//основное тело
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 10, _startPosY.Value + 35, 120, 60);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 35, 120, 60);
|
||||
|
||||
|
||||
|
||||
//Гусеницы
|
||||
Brush gg = new SolidBrush(Color.LightGray);
|
||||
g.FillEllipse(gg, _startPosX.Value + 13, _startPosY.Value + 96, 118, 35);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 13, _startPosY.Value + 96, 118, 35);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 16, _startPosY.Value + 98, 110, 30);
|
||||
|
||||
//катки в гусеницах
|
||||
Brush gr = new SolidBrush(Color.Gray);
|
||||
g.FillEllipse(gr, _startPosX.Value + 30, _startPosY.Value + 104, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 104, 20, 20);////
|
||||
|
||||
|
||||
g.FillEllipse(gr, _startPosX.Value + 55, _startPosY.Value + 105, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 55, _startPosY.Value + 105, 20, 20);
|
||||
|
||||
g.FillEllipse(gr, _startPosX.Value + 105, _startPosY.Value + 105, 15, 15);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 105, _startPosY.Value + 105, 15, 15);
|
||||
|
||||
g.FillEllipse(gr, _startPosX.Value + 80, _startPosY.Value + 105, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 105, 20, 20);
|
||||
|
||||
//кабина водителя
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 10, _startPosY.Value, 40, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value, 40, 40);
|
||||
|
||||
|
||||
//выхлопная труба
|
||||
Brush brBr = new SolidBrush(Color.Brown);
|
||||
|
||||
g.FillRectangle(brBr, _startPosX.Value + 100, _startPosY.Value, 15, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value, 15, 40);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,20 +1,11 @@
|
||||
|
||||
namespace ProjectBulldozer;
|
||||
namespace ProjectBulldozer.Entities;
|
||||
|
||||
public class EntityBulldozer
|
||||
public class EntityBulldozer : EntityBulldozerProstoy
|
||||
{
|
||||
/// <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 EntityBulldozer(int speed, double weight, Color bodyColor) : base(speed, weight, bodyColor)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
@ -28,10 +19,8 @@ public class EntityBulldozer
|
||||
/// </summary>
|
||||
public bool AdditionalRihl { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// </summary>
|
||||
@ -41,12 +30,9 @@ public class EntityBulldozer
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="additionalOtval">Признак наличия отвала спереди</param>
|
||||
/// <param name="additionalRihl">Признак наличия рыхлителя сзади</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool additionalOtval, bool additionalRihl)
|
||||
public EntityBulldozer(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool additionalOtval, bool additionalRihl) : base(speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
AdditionalOtval = additionalOtval;
|
||||
AdditionalRihl = additionalRihl;
|
@ -0,0 +1,41 @@
|
||||
namespace ProjectBulldozer.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Бульдозер простой"
|
||||
/// </summary>
|
||||
public class EntityBulldozerProstoy
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public EntityBulldozerProstoy(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -34,6 +34,9 @@
|
||||
buttonDown = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreateBulldozerProstoy = new Button();
|
||||
ButtonStrategyStep = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -51,9 +54,9 @@
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 511);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(94, 29);
|
||||
buttonCreate.Size = new Size(231, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.Text = "Создать бульозер с доп.";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreateBulldozer_Click;
|
||||
//
|
||||
@ -105,9 +108,43 @@
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateBulldozerProstoy
|
||||
//
|
||||
buttonCreateBulldozerProstoy.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBulldozerProstoy.Location = new Point(274, 511);
|
||||
buttonCreateBulldozerProstoy.Name = "buttonCreateBulldozerProstoy";
|
||||
buttonCreateBulldozerProstoy.Size = new Size(231, 29);
|
||||
buttonCreateBulldozerProstoy.TabIndex = 6;
|
||||
buttonCreateBulldozerProstoy.Text = "Создать простой бульдозер";
|
||||
buttonCreateBulldozerProstoy.UseVisualStyleBackColor = true;
|
||||
buttonCreateBulldozerProstoy.Click += buttonCreateBulldozerProstoy_Click;
|
||||
//
|
||||
// ButtonStrategyStep
|
||||
//
|
||||
ButtonStrategyStep.Location = new Point(793, 46);
|
||||
ButtonStrategyStep.Name = "ButtonStrategyStep";
|
||||
ButtonStrategyStep.Size = new Size(94, 29);
|
||||
ButtonStrategyStep.TabIndex = 8;
|
||||
ButtonStrategyStep.Text = "Шаг";
|
||||
ButtonStrategyStep.UseVisualStyleBackColor = true;
|
||||
ButtonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(744, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(143, 28);
|
||||
comboBoxStrategy.TabIndex = 9;
|
||||
//
|
||||
// FormBulldozer
|
||||
//
|
||||
ClientSize = new Size(899, 552);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(ButtonStrategyStep);
|
||||
Controls.Add(buttonCreateBulldozerProstoy);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonDown);
|
||||
@ -128,5 +165,8 @@
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateBulldozerProstoy;
|
||||
private Button ButtonStrategyStep;
|
||||
private ComboBox comboBoxStrategy;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectBulldozer.Drawnings;
|
||||
using ProjectBulldozer.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -15,47 +17,79 @@ namespace ProjectBulldozer
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningBulldozer? _drawningBulldozer;
|
||||
private DrawningBulldozerProstoy? _drawningBulldozerProstoy;
|
||||
|
||||
private AbstractStrategy? _strategy;
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
public FormBulldozer()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки машины
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningBulldozer == null)
|
||||
if (_drawningBulldozerProstoy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxBulldozer.Width,
|
||||
pictureBoxBulldozer.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningBulldozer.DrawTransport(gr);
|
||||
_drawningBulldozerProstoy.DrawTransport(gr);
|
||||
pictureBoxBulldozer.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// создеание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBulldozerProstoy):
|
||||
_drawningBulldozerProstoy = new DrawningBulldozerProstoy(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningBulldozer):
|
||||
_drawningBulldozerProstoy = new DrawningBulldozer(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawningBulldozerProstoy.SetPictureSize(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
||||
_drawningBulldozerProstoy.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать бульдозер с доп."
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningBulldozer = new DrawningBulldozer();
|
||||
|
||||
_drawningBulldozer.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningBulldozer.SetPictureSize(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
||||
_drawningBulldozer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateBulldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBulldozer));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать обычный бульдозер"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateBulldozerProstoy_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBulldozerProstoy));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
@ -63,7 +97,7 @@ namespace ProjectBulldozer
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBulldozer == null)
|
||||
if (_drawningBulldozerProstoy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -73,19 +107,19 @@ namespace ProjectBulldozer
|
||||
{
|
||||
case "buttonUp":
|
||||
result =
|
||||
_drawningBulldozer.MoveTransport(DirectionType1.Up);
|
||||
_drawningBulldozerProstoy.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result =
|
||||
_drawningBulldozer.MoveTransport(DirectionType1.Down);
|
||||
_drawningBulldozerProstoy.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result =
|
||||
_drawningBulldozer.MoveTransport(DirectionType1.Left);
|
||||
_drawningBulldozerProstoy.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawningBulldozer.MoveTransport(DirectionType1.Right);
|
||||
_drawningBulldozerProstoy.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
@ -94,6 +128,48 @@ namespace ProjectBulldozer
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBulldozerProstoy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableBulldozer(_drawningBulldozerProstoy),
|
||||
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user