Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
dd17103d9e | |||
9874caf690 | |||
3a02eacd59 | |||
de23a30c02 | |||
fbad9188bf | |||
40cd0e854b | |||
0f4098ad95 | |||
c176fe7a23 | |||
6ce7a673ce | |||
212151318a | |||
d32417974c | |||
63ff3ebf93 |
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32825.248
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bulldozer", "Bulldozer\Bulldozer.csproj", "{5971A7E3-6CB0-41D7-A8C9-F2E29DBC4C68}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bulldozer", "Bulldozer\Bulldozer.csproj", "{054C01C3-1210-4465-84BB-9B559909C149}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -11,15 +11,15 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5971A7E3-6CB0-41D7-A8C9-F2E29DBC4C68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5971A7E3-6CB0-41D7-A8C9-F2E29DBC4C68}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5971A7E3-6CB0-41D7-A8C9-F2E29DBC4C68}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5971A7E3-6CB0-41D7-A8C9-F2E29DBC4C68}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{054C01C3-1210-4465-84BB-9B559909C149}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{054C01C3-1210-4465-84BB-9B559909C149}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{054C01C3-1210-4465-84BB-9B559909C149}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{054C01C3-1210-4465-84BB-9B559909C149}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {59528A8E-08B2-4D91-8AD1-D237F3B6C1B5}
|
||||
SolutionGuid = {F8B8E9BD-8990-494B-B3F6-8CBB63A85858}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -8,4 +8,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
26
Bulldozer/Bulldozer/DirectionType.cs
Normal file
26
Bulldozer/Bulldozer/DirectionType.cs
Normal file
@ -0,0 +1,26 @@
|
||||
namespace Bulldozer
|
||||
{
|
||||
/// <summary>
|
||||
/// Направления движения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4,
|
||||
|
||||
}
|
||||
}
|
227
Bulldozer/Bulldozer/DrawingObjects/DrawingBulldozer.cs
Normal file
227
Bulldozer/Bulldozer/DrawingObjects/DrawingBulldozer.cs
Normal file
@ -0,0 +1,227 @@
|
||||
using Bulldozer.Entities;
|
||||
using Bulldozer.MovementStrategy;
|
||||
|
||||
namespace Bulldozer.DrawingObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс отрисовки и перемещения объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawingBulldozer
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBulldozer? EntityBulldozer { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
public int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
public int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Координата прорисовки по оси X
|
||||
/// </summary>
|
||||
protected int _startPosX;
|
||||
/// <summary>
|
||||
/// Координата прорисовки по оси Y
|
||||
/// </summary>
|
||||
protected int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина бульдозера
|
||||
/// </summary>
|
||||
protected readonly int _bulldozerWidth = 150;
|
||||
/// <summary>
|
||||
/// Высота бульдозера
|
||||
/// </summary>
|
||||
protected readonly int _bulldozerHeight = 60;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityBulldozer = new EntityBulldozer(speed, weight, bodyColor, additionalColor);
|
||||
}
|
||||
|
||||
/// <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 DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int bulldozerWidth, int bulldozerHeight)
|
||||
{
|
||||
if (width < _bulldozerWidth || height < _bulldozerHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_bulldozerWidth = bulldozerWidth;
|
||||
_bulldozerHeight = bulldozerHeight;
|
||||
EntityBulldozer = new EntityBulldozer(speed, weight, bodyColor, additionalColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
// Проверка границ
|
||||
if (x < 0) x = 0;
|
||||
if (y < 0) y = 0;
|
||||
if (x > _pictureWidth - _bulldozerWidth) x = _pictureWidth - _bulldozerWidth;
|
||||
if (y > _pictureHeight - _bulldozerHeight) y = _pictureHeight - _bulldozerHeight;
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityBulldozer == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
// влево
|
||||
DirectionType.Left => _startPosX - EntityBulldozer.Step > 0,
|
||||
// вверх
|
||||
DirectionType.Up => _startPosY - EntityBulldozer.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + EntityBulldozer.Step < _pictureWidth,
|
||||
// вниз
|
||||
DirectionType.Down => _startPosY + EntityBulldozer.Step < _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityBulldozer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
_startPosX -= (int)EntityBulldozer.Step;
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
_startPosY -= (int)EntityBulldozer.Step;
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
_startPosX += (int)EntityBulldozer.Step;
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
_startPosY += (int)EntityBulldozer.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBulldozer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(EntityBulldozer.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(EntityBulldozer.AdditionalColor);
|
||||
/// <summary>
|
||||
/// Заливка гусеницы бульдозера
|
||||
/// </summary>
|
||||
|
||||
|
||||
Brush brGray = new SolidBrush(Color.Gray);
|
||||
g.FillEllipse(brGray, _startPosX + 17, _startPosY + 24, 119, 40); //Гусеница
|
||||
g.FillEllipse(additionalBrush, _startPosX + 20, _startPosY + 35, 20, 20); // Левое колесо гусеницы
|
||||
g.FillEllipse(additionalBrush, _startPosX + 115, _startPosY + 35, 20, 20); // Правое колесо гусеницы
|
||||
g.FillEllipse(additionalBrush, _startPosX + 50, _startPosY + 45, 10, 10); // 1 центральное колесо гусеницы
|
||||
g.FillEllipse(additionalBrush, _startPosX + 70, _startPosY + 45, 10, 10); // 2 центральное колесо гусеницы
|
||||
g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 45, 10, 10); // 3 центральное колесо гусеницы
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Отрисовка границ бульдозера
|
||||
/// </summary>
|
||||
g.DrawEllipse(pen, _startPosX + 17, _startPosY + 24, 119, 40);
|
||||
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 35, 20, 20); // Левое колесо гусеницы
|
||||
g.DrawEllipse(pen, _startPosX + 115, _startPosY + 35, 20, 20); // Правое колесо гусеницы
|
||||
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 45, 10, 10); // 1 центральное колесо гусеницы
|
||||
g.DrawEllipse(pen, _startPosX + 70, _startPosY + 45, 10, 10); // 2 центральное колесо гусеницы
|
||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 45, 10, 10); // 3 центральное колесо гусеницы
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Кузов бульдозера
|
||||
/// </summary>
|
||||
g.FillRectangle(bodyBrush, _startPosX + 102, _startPosY, 28, 24); //кабина
|
||||
g.FillRectangle(bodyBrush, _startPosX + 17, _startPosY + 24, 119, 18); // основная часть
|
||||
g.FillRectangle(bodyBrush, _startPosX + 30, _startPosY, 10, 24); // выхлопная труба
|
||||
|
||||
/// Корпус
|
||||
/// </summary>
|
||||
g.DrawRectangle(pen, _startPosX + 102, _startPosY, 28, 24); //кабина
|
||||
g.DrawRectangle(pen, _startPosX + 17, _startPosY + 24, 119, 18); // основная часть
|
||||
g.DrawRectangle(pen, _startPosX + 30, _startPosY, 10, 24); // выхлопная труба
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawingBulldozer
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectBulldozer(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
using Bulldozer.Entities;
|
||||
|
||||
namespace Bulldozer.DrawingObjects
|
||||
{
|
||||
public class DrawingBulldozerUpgraded : DrawingBulldozer
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="blade">Признак наличия рыхлителя</param>
|
||||
/// <param name="ripper">Признак наличия отвала</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
|
||||
|
||||
public DrawingBulldozerUpgraded(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool blade, bool ripper, int width, int height) :
|
||||
base(speed, weight, bodyColor, additionalColor, width, height)
|
||||
{
|
||||
if (EntityBulldozer != null)
|
||||
{
|
||||
EntityBulldozer = new EntityBulldozerUpgraded(speed, weight, bodyColor, additionalColor, dopColor, blade, ripper);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBulldozer is not EntityBulldozerUpgraded upgradedBulldozer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Brush dopBrush = new SolidBrush(upgradedBulldozer.DopColor);
|
||||
Pen dopPen = new Pen(upgradedBulldozer.DopColor);
|
||||
/// <summary>
|
||||
/// Отрисовка отвала бульдозера
|
||||
/// </summary>
|
||||
base.DrawTransport(g);
|
||||
if (upgradedBulldozer.Blade)
|
||||
{
|
||||
Point point1 = new Point(_startPosX + 8, _startPosY + 29);
|
||||
Point point2 = new Point(_startPosX + 8, _startPosY + 50);
|
||||
Point point3 = new Point(_startPosX, _startPosY + 50);
|
||||
Point[] triangle = { point1, point2, point3 };
|
||||
|
||||
g.FillRectangle(dopBrush, _startPosX + 8, _startPosY + 29, 8, 8); // заливка основания отвала
|
||||
g.FillPolygon(dopBrush, triangle); // заливка отвала
|
||||
|
||||
g.DrawRectangle(dopPen, _startPosX + 8, _startPosY + 29, 8, 8); // обводка основания отвала
|
||||
g.DrawPolygon(dopPen, triangle); // обводка отвала
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Отрисовка рыхлителя бульдозера
|
||||
/// </summary>
|
||||
if (upgradedBulldozer.Ripper)
|
||||
{
|
||||
Point ripperPoint1 = new Point(_startPosX + 140, _startPosY + 37);
|
||||
Point ripperPoint2 = new Point(_startPosX + 151, _startPosY + 37);
|
||||
Point ripperPoint3 = new Point(_startPosX + 140, _startPosY + 60);
|
||||
Point[] ripper = { ripperPoint1, ripperPoint2, ripperPoint3 };
|
||||
|
||||
g.FillRectangle(dopBrush, _startPosX + 136, _startPosY + 29, 15, 8); // заливка основания рыхлителя
|
||||
g.FillPolygon(dopBrush, ripper); // заливка отвала
|
||||
|
||||
g.DrawRectangle(dopPen, _startPosX + 136, _startPosY + 29, 15, 8); // обводка основания рыхлителя
|
||||
g.DrawPolygon(dopPen, ripper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using Bulldozer.Entities;
|
||||
|
||||
namespace Bulldozer.DrawingObjects
|
||||
{
|
||||
public static class ExtentionDrawingBulldozer
|
||||
{
|
||||
public static DrawingBulldozer? CreateDrawingBulldozer(this string info, char separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 4)
|
||||
{
|
||||
return new DrawingBulldozer(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), Color.FromName(strs[3]), width, height);
|
||||
}
|
||||
if (strs.Length == 7)
|
||||
{
|
||||
return new DrawingBulldozerUpgraded(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]),
|
||||
Color.FromName(strs[4]),
|
||||
Convert.ToBoolean(strs[5]),
|
||||
Convert.ToBoolean(strs[6]), width, height);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawingBulldozer">Сохраняемый объект</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawingBulldozer drawingBulldozer, char separatorForObject)
|
||||
{
|
||||
var bulldozer = drawingBulldozer.EntityBulldozer;
|
||||
if (bulldozer == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = $"{bulldozer.Speed}{separatorForObject}{bulldozer.Weight}{separatorForObject}{bulldozer.BodyColor.Name}{separatorForObject}{bulldozer.AdditionalColor.Name}";
|
||||
if (bulldozer is not EntityBulldozerUpgraded bulldozerUpgraded)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{separatorForObject}{bulldozerUpgraded.DopColor.Name}{separatorForObject}{bulldozerUpgraded.Ripper}{separatorForObject}{bulldozerUpgraded.Blade}";
|
||||
}
|
||||
}
|
||||
}
|
48
Bulldozer/Bulldozer/Entities/EntityBulldozer.cs
Normal file
48
Bulldozer/Bulldozer/Entities/EntityBulldozer.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System.Windows.Forms.Design;
|
||||
|
||||
namespace Bulldozer.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Бульдозер"
|
||||
/// </summary>
|
||||
public class EntityBulldozer
|
||||
{
|
||||
/// <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 Color AdditionalColor { 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 EntityBulldozer(int speed, double weight, Color bodyColor, Color additionalColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
}
|
||||
public void SetBodyColor(Color bodyColor)
|
||||
{
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
41
Bulldozer/Bulldozer/Entities/EntityBulldozerUpgraded.cs
Normal file
41
Bulldozer/Bulldozer/Entities/EntityBulldozerUpgraded.cs
Normal file
@ -0,0 +1,41 @@
|
||||
namespace Bulldozer.Entities
|
||||
{
|
||||
public class EntityBulldozerUpgraded : EntityBulldozer
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Отвал бульдозера
|
||||
/// </summary>
|
||||
public bool Blade { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Рыхлитель бульдозера
|
||||
/// </summary>
|
||||
public bool Ripper { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса бульдозера с обвесами
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="additionalColor">Цвет обвесов</param>
|
||||
/// <param name="blade">Отвал бульдозера</param>
|
||||
/// <param name="ripper">Рыхлитель бульдозера</param>
|
||||
public EntityBulldozerUpgraded(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool blade, bool ripper) :
|
||||
base(speed, weight, bodyColor, additionalColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Blade = blade;
|
||||
Ripper = ripper;
|
||||
}
|
||||
|
||||
public void SetDopColor(Color dopColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
}
|
||||
}
|
||||
}
|
39
Bulldozer/Bulldozer/Form1.Designer.cs
generated
39
Bulldozer/Bulldozer/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace Bulldozer
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace Bulldozer
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
208
Bulldozer/Bulldozer/FormBulldozer.Designer.cs
generated
Normal file
208
Bulldozer/Bulldozer/FormBulldozer.Designer.cs
generated
Normal file
@ -0,0 +1,208 @@
|
||||
namespace Bulldozer
|
||||
{
|
||||
partial class FormBulldozer
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxBulldozer = new System.Windows.Forms.PictureBox();
|
||||
this.buttonCreateBulldozer = 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.buttonUp = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
this.buttonCreateUpgradedBulldozer = new System.Windows.Forms.Button();
|
||||
this.buttonSelectBulldozer = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBulldozer)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxBulldozer
|
||||
//
|
||||
this.pictureBoxBulldozer.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxBulldozer.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.pictureBoxBulldozer.Name = "pictureBoxBulldozer";
|
||||
this.pictureBoxBulldozer.Size = new System.Drawing.Size(1110, 793);
|
||||
this.pictureBoxBulldozer.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxBulldozer.TabIndex = 0;
|
||||
this.pictureBoxBulldozer.TabStop = false;
|
||||
//
|
||||
// buttonCreateBulldozer
|
||||
//
|
||||
this.buttonCreateBulldozer.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateBulldozer.Location = new System.Drawing.Point(14, 746);
|
||||
this.buttonCreateBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCreateBulldozer.Name = "buttonCreateBulldozer";
|
||||
this.buttonCreateBulldozer.Size = new System.Drawing.Size(151, 31);
|
||||
this.buttonCreateBulldozer.TabIndex = 1;
|
||||
this.buttonCreateBulldozer.Text = "Создать бульдозер";
|
||||
this.buttonCreateBulldozer.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateBulldozer.Click += new System.EventHandler(this.buttonCreateBulldozer_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::Bulldozer.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Image = global::Bulldozer.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(967, 741);
|
||||
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonLeft.TabIndex = 2;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Bulldozer.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(1009, 741);
|
||||
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonDown.TabIndex = 3;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::Bulldozer.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Image = global::Bulldozer.Properties.Resources.arrowRight;
|
||||
this.buttonRight.Location = new System.Drawing.Point(1050, 741);
|
||||
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonRight.TabIndex = 4;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Bulldozer.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Image = global::Bulldozer.Properties.Resources.arrowUp;
|
||||
this.buttonUp.Location = new System.Drawing.Point(1009, 693);
|
||||
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonUp.TabIndex = 5;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
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(834, 12);
|
||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(264, 28);
|
||||
this.comboBoxStrategy.TabIndex = 6;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonStep.Location = new System.Drawing.Point(1038, 47);
|
||||
this.buttonStep.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonStep.Name = "buttonStep";
|
||||
this.buttonStep.Size = new System.Drawing.Size(60, 31);
|
||||
this.buttonStep.TabIndex = 7;
|
||||
this.buttonStep.Text = "Шаг";
|
||||
this.buttonStep.UseVisualStyleBackColor = true;
|
||||
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||
//
|
||||
// buttonCreateUpgradedBulldozer
|
||||
//
|
||||
this.buttonCreateUpgradedBulldozer.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateUpgradedBulldozer.Location = new System.Drawing.Point(171, 746);
|
||||
this.buttonCreateUpgradedBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCreateUpgradedBulldozer.Name = "buttonCreateUpgradedBulldozer";
|
||||
this.buttonCreateUpgradedBulldozer.Size = new System.Drawing.Size(235, 31);
|
||||
this.buttonCreateUpgradedBulldozer.TabIndex = 8;
|
||||
this.buttonCreateUpgradedBulldozer.Text = "Создать бульдозер с обвесами";
|
||||
this.buttonCreateUpgradedBulldozer.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateUpgradedBulldozer.Click += new System.EventHandler(this.buttonCreateUpgradedBulldozer_Click);
|
||||
//
|
||||
// buttonSelectBulldozer
|
||||
//
|
||||
this.buttonSelectBulldozer.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonSelectBulldozer.Location = new System.Drawing.Point(412, 746);
|
||||
this.buttonSelectBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonSelectBulldozer.Name = "buttonSelectBulldozer";
|
||||
this.buttonSelectBulldozer.Size = new System.Drawing.Size(130, 31);
|
||||
this.buttonSelectBulldozer.TabIndex = 9;
|
||||
this.buttonSelectBulldozer.Text = "Выбрать объект";
|
||||
this.buttonSelectBulldozer.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectBulldozer.Click += new System.EventHandler(this.buttonSelectBulldozer_Click);
|
||||
//
|
||||
// FormBulldozer
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1110, 793);
|
||||
this.Controls.Add(this.buttonSelectBulldozer);
|
||||
this.Controls.Add(this.buttonCreateUpgradedBulldozer);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonCreateBulldozer);
|
||||
this.Controls.Add(this.pictureBoxBulldozer);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormBulldozer";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Bulldozer";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBulldozer)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxBulldozer;
|
||||
private Button buttonCreateBulldozer;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonCreateUpgradedBulldozer;
|
||||
private Button buttonSelectBulldozer;
|
||||
}
|
||||
}
|
180
Bulldozer/Bulldozer/FormBulldozer.cs
Normal file
180
Bulldozer/Bulldozer/FormBulldozer.cs
Normal file
@ -0,0 +1,180 @@
|
||||
using Bulldozer.MovementStrategy;
|
||||
using Bulldozer.DrawingObjects;
|
||||
|
||||
namespace Bulldozer
|
||||
{
|
||||
public partial class FormBulldozer : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawingBulldozer? _drawingBulldozer;
|
||||
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Âûáðàííûé áóëüäîçåð
|
||||
/// </summary>
|
||||
public DrawingBulldozer? SelectedBulldozer { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
/// </summary>
|
||||
public FormBulldozer()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedBulldozer = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè áóëüäîçåðà
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingBulldozer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingBulldozer.DrawTransport(gr);
|
||||
pictureBoxBulldozer.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü áóëüäîçåð ñ îáâåñàìè"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingBulldozer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingBulldozer.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingBulldozer.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingBulldozer.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingBulldozer.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateUpgradedBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // Îñíîâíîé öâåò
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // Äîï. öâåò äëÿ EntityUpgradedBulldozer
|
||||
ColorDialog colorDialog = new();
|
||||
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
bodyColor = colorDialog.Color;
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
dopColor = colorDialog.Color;
|
||||
_drawingBulldozer = new DrawingBulldozerUpgraded(
|
||||
random.Next(100, 300), // Ñêîðîñòü
|
||||
random.Next(1000, 3000), // Âåñ
|
||||
bodyColor, additionalColor, dopColor,
|
||||
Convert.ToBoolean(random.Next(2)),
|
||||
Convert.ToBoolean(random.Next(2)),
|
||||
pictureBoxBulldozer.Width,
|
||||
pictureBoxBulldozer.Height
|
||||
);
|
||||
|
||||
_drawingBulldozer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
||||
private void buttonCreateBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog colorDialog = new ColorDialog();
|
||||
|
||||
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodyColor = colorDialog.Color;
|
||||
}
|
||||
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
|
||||
_drawingBulldozer = new DrawingBulldozer(random.Next(100, 300), // Ñêîðîñòü
|
||||
random.Next(1000, 3000), // Âåñ
|
||||
bodyColor, additionalColor,
|
||||
pictureBoxBulldozer.Width,
|
||||
pictureBoxBulldozer.Height);
|
||||
|
||||
_drawingBulldozer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingBulldozer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawingObjectBulldozer(_drawingBulldozer), pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Âûáîð áóëüäîçåðà
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void buttonSelectBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedBulldozer = _drawingBulldozer;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
60
Bulldozer/Bulldozer/FormBulldozer.resx
Normal file
60
Bulldozer/Bulldozer/FormBulldozer.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
259
Bulldozer/Bulldozer/FormBulldozerCollection.Designer.cs
generated
Normal file
259
Bulldozer/Bulldozer/FormBulldozerCollection.Designer.cs
generated
Normal file
@ -0,0 +1,259 @@
|
||||
namespace Bulldozer
|
||||
{
|
||||
partial class FormBulldozerCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.panelTools = new System.Windows.Forms.Panel();
|
||||
this.groupListBulldozersBox = new System.Windows.Forms.GroupBox();
|
||||
this.buttonDeleteBulldozersList = new System.Windows.Forms.Button();
|
||||
this.buttonAddBulldozersList = new System.Windows.Forms.Button();
|
||||
this.listBoxBulldozerStorages = new System.Windows.Forms.ListBox();
|
||||
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||
this.textBoxDeletingBulldozer = new System.Windows.Forms.TextBox();
|
||||
this.buttonUpdateColletion = new System.Windows.Forms.Button();
|
||||
this.buttonDeleteBulldozer = new System.Windows.Forms.Button();
|
||||
this.buttonAddBulldozer = new System.Windows.Forms.Button();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.toolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.panelTools.SuspendLayout();
|
||||
this.groupListBulldozersBox.SuspendLayout();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Anchor = System.Windows.Forms.AnchorStyles.Left;
|
||||
this.pictureBoxCollection.BackColor = System.Drawing.SystemColors.Control;
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(14, 16);
|
||||
this.pictureBoxCollection.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(813, 761);
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panelTools
|
||||
//
|
||||
this.panelTools.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
||||
this.panelTools.Controls.Add(this.groupListBulldozersBox);
|
||||
this.panelTools.Controls.Add(this.textBoxDeletingBulldozer);
|
||||
this.panelTools.Controls.Add(this.buttonUpdateColletion);
|
||||
this.panelTools.Controls.Add(this.buttonDeleteBulldozer);
|
||||
this.panelTools.Controls.Add(this.buttonAddBulldozer);
|
||||
this.panelTools.Location = new System.Drawing.Point(833, 16);
|
||||
this.panelTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.panelTools.Name = "panelTools";
|
||||
this.panelTools.Size = new System.Drawing.Size(267, 761);
|
||||
this.panelTools.TabIndex = 1;
|
||||
this.panelTools.Tag = "";
|
||||
//
|
||||
// groupListBulldozersBox
|
||||
//
|
||||
this.groupListBulldozersBox.Controls.Add(this.buttonDeleteBulldozersList);
|
||||
this.groupListBulldozersBox.Controls.Add(this.buttonAddBulldozersList);
|
||||
this.groupListBulldozersBox.Controls.Add(this.listBoxBulldozerStorages);
|
||||
this.groupListBulldozersBox.Controls.Add(this.textBoxStorageName);
|
||||
this.groupListBulldozersBox.Location = new System.Drawing.Point(16, 33);
|
||||
this.groupListBulldozersBox.Name = "groupListBulldozersBox";
|
||||
this.groupListBulldozersBox.Size = new System.Drawing.Size(230, 282);
|
||||
this.groupListBulldozersBox.TabIndex = 8;
|
||||
this.groupListBulldozersBox.TabStop = false;
|
||||
this.groupListBulldozersBox.Text = "Наборы";
|
||||
//
|
||||
// buttonDeleteBulldozersList
|
||||
//
|
||||
this.buttonDeleteBulldozersList.Location = new System.Drawing.Point(6, 226);
|
||||
this.buttonDeleteBulldozersList.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDeleteBulldozersList.Name = "buttonDeleteBulldozersList";
|
||||
this.buttonDeleteBulldozersList.Size = new System.Drawing.Size(221, 53);
|
||||
this.buttonDeleteBulldozersList.TabIndex = 7;
|
||||
this.buttonDeleteBulldozersList.Text = "Удалить набор";
|
||||
this.buttonDeleteBulldozersList.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteBulldozersList.Click += new System.EventHandler(this.buttonDeleteBulldozersList_Click);
|
||||
//
|
||||
// buttonAddBulldozersList
|
||||
//
|
||||
this.buttonAddBulldozersList.Location = new System.Drawing.Point(6, 55);
|
||||
this.buttonAddBulldozersList.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonAddBulldozersList.Name = "buttonAddBulldozersList";
|
||||
this.buttonAddBulldozersList.Size = new System.Drawing.Size(221, 53);
|
||||
this.buttonAddBulldozersList.TabIndex = 6;
|
||||
this.buttonAddBulldozersList.Text = "Добавить набор";
|
||||
this.buttonAddBulldozersList.UseVisualStyleBackColor = true;
|
||||
this.buttonAddBulldozersList.Click += new System.EventHandler(this.buttonAddBulldozersList_Click);
|
||||
//
|
||||
// listBoxBulldozerStorages
|
||||
//
|
||||
this.listBoxBulldozerStorages.FormattingEnabled = true;
|
||||
this.listBoxBulldozerStorages.ItemHeight = 20;
|
||||
this.listBoxBulldozerStorages.Location = new System.Drawing.Point(6, 115);
|
||||
this.listBoxBulldozerStorages.Name = "listBoxBulldozerStorages";
|
||||
this.listBoxBulldozerStorages.Size = new System.Drawing.Size(220, 104);
|
||||
this.listBoxBulldozerStorages.TabIndex = 5;
|
||||
this.listBoxBulldozerStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxBulldozerStorages_SelectedIndexChanged);
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
this.textBoxStorageName.Location = new System.Drawing.Point(7, 20);
|
||||
this.textBoxStorageName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||
this.textBoxStorageName.Size = new System.Drawing.Size(220, 27);
|
||||
this.textBoxStorageName.TabIndex = 4;
|
||||
//
|
||||
// textBoxDeletingBulldozer
|
||||
//
|
||||
this.textBoxDeletingBulldozer.Location = new System.Drawing.Point(25, 525);
|
||||
this.textBoxDeletingBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.textBoxDeletingBulldozer.Name = "textBoxDeletingBulldozer";
|
||||
this.textBoxDeletingBulldozer.Size = new System.Drawing.Size(220, 27);
|
||||
this.textBoxDeletingBulldozer.TabIndex = 3;
|
||||
//
|
||||
// buttonUpdateColletion
|
||||
//
|
||||
this.buttonUpdateColletion.Location = new System.Drawing.Point(25, 692);
|
||||
this.buttonUpdateColletion.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonUpdateColletion.Name = "buttonUpdateColletion";
|
||||
this.buttonUpdateColletion.Size = new System.Drawing.Size(221, 53);
|
||||
this.buttonUpdateColletion.TabIndex = 2;
|
||||
this.buttonUpdateColletion.Text = "Обновить коллекцию";
|
||||
this.buttonUpdateColletion.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonDeleteBulldozer
|
||||
//
|
||||
this.buttonDeleteBulldozer.Location = new System.Drawing.Point(25, 563);
|
||||
this.buttonDeleteBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDeleteBulldozer.Name = "buttonDeleteBulldozer";
|
||||
this.buttonDeleteBulldozer.Size = new System.Drawing.Size(221, 53);
|
||||
this.buttonDeleteBulldozer.TabIndex = 1;
|
||||
this.buttonDeleteBulldozer.Text = "Удалить объект";
|
||||
this.buttonDeleteBulldozer.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteBulldozer.Click += new System.EventHandler(this.buttonDeleteBulldozer_Click);
|
||||
//
|
||||
// buttonAddBulldozer
|
||||
//
|
||||
this.buttonAddBulldozer.Location = new System.Drawing.Point(24, 464);
|
||||
this.buttonAddBulldozer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonAddBulldozer.Name = "buttonAddBulldozer";
|
||||
this.buttonAddBulldozer.Size = new System.Drawing.Size(221, 53);
|
||||
this.buttonAddBulldozer.TabIndex = 0;
|
||||
this.buttonAddBulldozer.Text = "Добавить объект";
|
||||
this.buttonAddBulldozer.UseVisualStyleBackColor = true;
|
||||
this.buttonAddBulldozer.Click += new System.EventHandler(this.buttonAddBulldozer_Click);
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.FileName = "openFileDialog";
|
||||
this.openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(1110, 28);
|
||||
this.menuStrip.TabIndex = 2;
|
||||
this.menuStrip.Text = "menuStrip";
|
||||
//
|
||||
// toolStripMenuItem
|
||||
//
|
||||
this.toolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.SaveToolStripMenuItem,
|
||||
this.LoadToolStripMenuItem});
|
||||
this.toolStripMenuItem.Name = "toolStripMenuItem";
|
||||
this.toolStripMenuItem.Size = new System.Drawing.Size(59, 24);
|
||||
this.toolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.SaveToolStripMenuItem.Text = "Сохранить";
|
||||
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.LoadToolStripMenuItem.Text = "Загрузить";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// FormBulldozerCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1110, 793);
|
||||
this.Controls.Add(this.panelTools);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormBulldozerCollection";
|
||||
this.Text = "Bulldozer Collection";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.panelTools.ResumeLayout(false);
|
||||
this.panelTools.PerformLayout();
|
||||
this.groupListBulldozersBox.ResumeLayout(false);
|
||||
this.groupListBulldozersBox.PerformLayout();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Panel panelTools;
|
||||
private TextBox textBoxDeletingBulldozer;
|
||||
private Button buttonUpdateColletion;
|
||||
private Button buttonDeleteBulldozer;
|
||||
private Button buttonAddBulldozer;
|
||||
private ListBox listBoxBulldozerStorages;
|
||||
private TextBox textBoxStorageName;
|
||||
private GroupBox groupListBulldozersBox;
|
||||
private Button buttonDeleteBulldozersList;
|
||||
private Button buttonAddBulldozersList;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem toolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
}
|
||||
}
|
223
Bulldozer/Bulldozer/FormBulldozerCollection.cs
Normal file
223
Bulldozer/Bulldozer/FormBulldozerCollection.cs
Normal file
@ -0,0 +1,223 @@
|
||||
using Bulldozer.DrawingObjects;
|
||||
using Bulldozer.Generics;
|
||||
using Bulldozer.MovementStrategy;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
namespace Bulldozer
|
||||
{
|
||||
public partial class FormBulldozerCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly BulldozersGenericStorage _storage;
|
||||
|
||||
|
||||
public FormBulldozerCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new BulldozersGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Заполнение listBoxBulldozerStorages
|
||||
/// </summary>
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxBulldozerStorages.SelectedIndex;
|
||||
listBoxBulldozerStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxBulldozerStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxBulldozerStorages.Items.Count > 0 && (index == -1 || index >= listBoxBulldozerStorages.Items.Count))
|
||||
{
|
||||
listBoxBulldozerStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxBulldozerStorages.Items.Count > 0 && index > -1 && index < listBoxBulldozerStorages.Items.Count)
|
||||
{
|
||||
listBoxBulldozerStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление набора в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonAddBulldozersList_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void listBoxBulldozerStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _storage[listBoxBulldozerStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBulldozers();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonDeleteBulldozersList_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxBulldozerStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {listBoxBulldozerStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxBulldozerStorages.SelectedItem.ToString() ?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
|
||||
private void buttonAddBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxBulldozerStorages.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Выберите набор в списке.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
var formBulldozerConfig = new FormBulldozerConfig();
|
||||
formBulldozerConfig.AddEvent(AddBulldozer);
|
||||
formBulldozerConfig.Show();
|
||||
}
|
||||
private void AddBulldozer(DrawingBulldozer bulldozer)
|
||||
{
|
||||
bulldozer._pictureWidth = pictureBoxCollection.Width;
|
||||
bulldozer._pictureHeight = pictureBoxCollection.Height;
|
||||
|
||||
if (listBoxBulldozerStorages.SelectedIndex == -1) return;
|
||||
|
||||
var obj = _storage[listBoxBulldozerStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (obj + bulldozer > -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowBulldozers();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonDeleteBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxBulldozerStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxBulldozerStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(textBoxDeletingBulldozer.Text);
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowBulldozers();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonUpdateCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxBulldozerStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxBulldozerStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowBulldozers();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.SaveData(saveFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Загрузка прошла успешно!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadObjects();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не загрузилось!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
69
Bulldozer/Bulldozer/FormBulldozerCollection.resx
Normal file
69
Bulldozer/Bulldozer/FormBulldozerCollection.resx
Normal file
@ -0,0 +1,69 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>184, 17</value>
|
||||
</metadata>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>338, 17</value>
|
||||
</metadata>
|
||||
</root>
|
435
Bulldozer/Bulldozer/FormBulldozerConfig.Designer.cs
generated
Normal file
435
Bulldozer/Bulldozer/FormBulldozerConfig.Designer.cs
generated
Normal file
@ -0,0 +1,435 @@
|
||||
namespace Bulldozer
|
||||
{
|
||||
partial class FormBulldozerConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBoxParameters = new System.Windows.Forms.GroupBox();
|
||||
this.groupBoxMarks = new System.Windows.Forms.GroupBox();
|
||||
this.checkBoxRipper = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxBlade = new System.Windows.Forms.CheckBox();
|
||||
this.labelModifiedObject = new System.Windows.Forms.Label();
|
||||
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||
this.groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||
this.panelPurple = new System.Windows.Forms.Panel();
|
||||
this.panelBlack = new System.Windows.Forms.Panel();
|
||||
this.panelGray = new System.Windows.Forms.Panel();
|
||||
this.panelWhite = new System.Windows.Forms.Panel();
|
||||
this.panelYellow = new System.Windows.Forms.Panel();
|
||||
this.panelBlue = new System.Windows.Forms.Panel();
|
||||
this.panelGreen = new System.Windows.Forms.Panel();
|
||||
this.panelRed = new System.Windows.Forms.Panel();
|
||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.labelWeight = new System.Windows.Forms.Label();
|
||||
this.labelSpeed = new System.Windows.Forms.Label();
|
||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.panelObject = new System.Windows.Forms.Panel();
|
||||
this.labelAddColor = new System.Windows.Forms.Label();
|
||||
this.labelColor = new System.Windows.Forms.Label();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.groupBoxParameters.SuspendLayout();
|
||||
this.groupBoxMarks.SuspendLayout();
|
||||
this.groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||
this.panelObject.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxParameters
|
||||
//
|
||||
this.groupBoxParameters.Controls.Add(this.groupBoxMarks);
|
||||
this.groupBoxParameters.Controls.Add(this.labelModifiedObject);
|
||||
this.groupBoxParameters.Controls.Add(this.labelSimpleObject);
|
||||
this.groupBoxParameters.Controls.Add(this.groupBoxColors);
|
||||
this.groupBoxParameters.Controls.Add(this.numericUpDownWeight);
|
||||
this.groupBoxParameters.Controls.Add(this.numericUpDownSpeed);
|
||||
this.groupBoxParameters.Controls.Add(this.labelWeight);
|
||||
this.groupBoxParameters.Controls.Add(this.labelSpeed);
|
||||
this.groupBoxParameters.Location = new System.Drawing.Point(10, 10);
|
||||
this.groupBoxParameters.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.groupBoxParameters.Name = "groupBoxParameters";
|
||||
this.groupBoxParameters.Padding = new System.Windows.Forms.Padding(2);
|
||||
this.groupBoxParameters.Size = new System.Drawing.Size(586, 272);
|
||||
this.groupBoxParameters.TabIndex = 0;
|
||||
this.groupBoxParameters.TabStop = false;
|
||||
this.groupBoxParameters.Text = "Параметры";
|
||||
//
|
||||
// groupBoxMarks
|
||||
//
|
||||
this.groupBoxMarks.Controls.Add(this.checkBoxRipper);
|
||||
this.groupBoxMarks.Controls.Add(this.checkBoxBlade);
|
||||
this.groupBoxMarks.Location = new System.Drawing.Point(24, 133);
|
||||
this.groupBoxMarks.Name = "groupBoxMarks";
|
||||
this.groupBoxMarks.Size = new System.Drawing.Size(250, 116);
|
||||
this.groupBoxMarks.TabIndex = 9;
|
||||
this.groupBoxMarks.TabStop = false;
|
||||
this.groupBoxMarks.Text = "Признаки";
|
||||
//
|
||||
// checkBoxRipper
|
||||
//
|
||||
this.checkBoxRipper.AutoSize = true;
|
||||
this.checkBoxRipper.Location = new System.Drawing.Point(17, 41);
|
||||
this.checkBoxRipper.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.checkBoxRipper.Name = "checkBoxRipper";
|
||||
this.checkBoxRipper.Size = new System.Drawing.Size(170, 24);
|
||||
this.checkBoxRipper.TabIndex = 4;
|
||||
this.checkBoxRipper.Text = "Наличие рыхлителя";
|
||||
this.checkBoxRipper.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxBlade
|
||||
//
|
||||
this.checkBoxBlade.AutoSize = true;
|
||||
this.checkBoxBlade.Location = new System.Drawing.Point(17, 74);
|
||||
this.checkBoxBlade.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.checkBoxBlade.Name = "checkBoxBlade";
|
||||
this.checkBoxBlade.Size = new System.Drawing.Size(143, 24);
|
||||
this.checkBoxBlade.TabIndex = 5;
|
||||
this.checkBoxBlade.Text = "Наличие отвала";
|
||||
this.checkBoxBlade.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// labelModifiedObject
|
||||
//
|
||||
this.labelModifiedObject.BackColor = System.Drawing.SystemColors.ActiveCaption;
|
||||
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelModifiedObject.Location = new System.Drawing.Point(450, 180);
|
||||
this.labelModifiedObject.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||
this.labelModifiedObject.Size = new System.Drawing.Size(107, 69);
|
||||
this.labelModifiedObject.TabIndex = 8;
|
||||
this.labelModifiedObject.Text = "Продвинутый";
|
||||
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelModifiedObject.MouseDown += labelObject_MouseDown;
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
this.labelSimpleObject.BackColor = System.Drawing.SystemColors.ActiveCaption;
|
||||
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelSimpleObject.Location = new System.Drawing.Point(329, 180);
|
||||
this.labelSimpleObject.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||
this.labelSimpleObject.Size = new System.Drawing.Size(102, 69);
|
||||
this.labelSimpleObject.TabIndex = 7;
|
||||
this.labelSimpleObject.Text = "Простой";
|
||||
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelSimpleObject.MouseDown += labelObject_MouseDown;
|
||||
//
|
||||
// groupBoxColors
|
||||
//
|
||||
this.groupBoxColors.Controls.Add(this.panelPurple);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlack);
|
||||
this.groupBoxColors.Controls.Add(this.panelGray);
|
||||
this.groupBoxColors.Controls.Add(this.panelWhite);
|
||||
this.groupBoxColors.Controls.Add(this.panelYellow);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlue);
|
||||
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||
this.groupBoxColors.Location = new System.Drawing.Point(311, 16);
|
||||
this.groupBoxColors.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.groupBoxColors.Name = "groupBoxColors";
|
||||
this.groupBoxColors.Padding = new System.Windows.Forms.Padding(2);
|
||||
this.groupBoxColors.Size = new System.Drawing.Size(259, 155);
|
||||
this.groupBoxColors.TabIndex = 6;
|
||||
this.groupBoxColors.TabStop = false;
|
||||
this.groupBoxColors.Text = "Цвета";
|
||||
this.groupBoxColors.DragDrop += PanelObject_DragDrop;
|
||||
this.groupBoxColors.DragEnter += PanelObject_DragEnter;
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||
this.panelPurple.Location = new System.Drawing.Point(194, 90);
|
||||
this.panelPurple.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.panelPurple.Name = "panelPurple";
|
||||
this.panelPurple.Size = new System.Drawing.Size(43, 43);
|
||||
this.panelPurple.TabIndex = 1;
|
||||
this.panelPurple.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||
this.panelBlack.Location = new System.Drawing.Point(135, 90);
|
||||
this.panelBlack.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.panelBlack.Name = "panelBlack";
|
||||
this.panelBlack.Size = new System.Drawing.Size(43, 43);
|
||||
this.panelBlack.TabIndex = 1;
|
||||
this.panelBlack.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||
this.panelGray.Location = new System.Drawing.Point(77, 90);
|
||||
this.panelGray.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.panelGray.Name = "panelGray";
|
||||
this.panelGray.Size = new System.Drawing.Size(43, 43);
|
||||
this.panelGray.TabIndex = 1;
|
||||
this.panelGray.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||
this.panelWhite.Location = new System.Drawing.Point(18, 90);
|
||||
this.panelWhite.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.panelWhite.Name = "panelWhite";
|
||||
this.panelWhite.Size = new System.Drawing.Size(43, 43);
|
||||
this.panelWhite.TabIndex = 1;
|
||||
this.panelWhite.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||
this.panelYellow.Location = new System.Drawing.Point(194, 34);
|
||||
this.panelYellow.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.panelYellow.Name = "panelYellow";
|
||||
this.panelYellow.Size = new System.Drawing.Size(43, 43);
|
||||
this.panelYellow.TabIndex = 1;
|
||||
this.panelYellow.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||
this.panelBlue.Location = new System.Drawing.Point(135, 34);
|
||||
this.panelBlue.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.panelBlue.Name = "panelBlue";
|
||||
this.panelBlue.Size = new System.Drawing.Size(43, 43);
|
||||
this.panelBlue.TabIndex = 1;
|
||||
this.panelBlue.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
||||
this.panelGreen.Location = new System.Drawing.Point(77, 34);
|
||||
this.panelGreen.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(43, 43);
|
||||
this.panelGreen.TabIndex = 1;
|
||||
this.panelGreen.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||
this.panelRed.Location = new System.Drawing.Point(18, 34);
|
||||
this.panelRed.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.panelRed.Name = "panelRed";
|
||||
this.panelRed.Size = new System.Drawing.Size(43, 43);
|
||||
this.panelRed.TabIndex = 0;
|
||||
this.panelRed.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
this.numericUpDownWeight.Location = new System.Drawing.Point(117, 75);
|
||||
this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.numericUpDownWeight.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownWeight.Minimum = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
this.numericUpDownWeight.Size = new System.Drawing.Size(144, 27);
|
||||
this.numericUpDownWeight.TabIndex = 3;
|
||||
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(117, 42);
|
||||
this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
this.numericUpDownSpeed.Size = new System.Drawing.Size(144, 27);
|
||||
this.numericUpDownSpeed.TabIndex = 2;
|
||||
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
this.labelWeight.AutoSize = true;
|
||||
this.labelWeight.Location = new System.Drawing.Point(24, 80);
|
||||
this.labelWeight.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelWeight.Name = "labelWeight";
|
||||
this.labelWeight.Size = new System.Drawing.Size(33, 20);
|
||||
this.labelWeight.TabIndex = 1;
|
||||
this.labelWeight.Text = "Вес";
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
this.labelSpeed.AutoSize = true;
|
||||
this.labelSpeed.Location = new System.Drawing.Point(24, 43);
|
||||
this.labelSpeed.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelSpeed.Name = "labelSpeed";
|
||||
this.labelSpeed.Size = new System.Drawing.Size(73, 20);
|
||||
this.labelSpeed.TabIndex = 0;
|
||||
this.labelSpeed.Text = "Скорость";
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
this.pictureBoxObject.Location = new System.Drawing.Point(26, 49);
|
||||
this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||
this.pictureBoxObject.Size = new System.Drawing.Size(286, 140);
|
||||
this.pictureBoxObject.TabIndex = 1;
|
||||
this.pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
this.panelObject.AllowDrop = true;
|
||||
this.panelObject.Controls.Add(this.labelAddColor);
|
||||
this.panelObject.Controls.Add(this.labelColor);
|
||||
this.panelObject.Controls.Add(this.pictureBoxObject);
|
||||
this.panelObject.Location = new System.Drawing.Point(621, 18);
|
||||
this.panelObject.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.panelObject.Name = "panelObject";
|
||||
this.panelObject.Size = new System.Drawing.Size(334, 202);
|
||||
this.panelObject.TabIndex = 2;
|
||||
this.panelObject.DragDrop += PanelObject_DragDrop;
|
||||
this.panelObject.DragEnter += PanelObject_DragEnter;
|
||||
//
|
||||
// labelAddColor
|
||||
//
|
||||
this.labelAddColor.AllowDrop = true;
|
||||
this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelAddColor.Location = new System.Drawing.Point(180, 7);
|
||||
this.labelAddColor.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelAddColor.Name = "labelAddColor";
|
||||
this.labelAddColor.Size = new System.Drawing.Size(132, 40);
|
||||
this.labelAddColor.TabIndex = 3;
|
||||
this.labelAddColor.Text = "Дополн. цвет";
|
||||
this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelAddColor.DragDrop += labelColor_dragDrop;
|
||||
this.labelAddColor.DragEnter += labelColor_dragEnter;
|
||||
//
|
||||
// labelColor
|
||||
//
|
||||
this.labelColor.AllowDrop = true;
|
||||
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelColor.Location = new System.Drawing.Point(26, 7);
|
||||
this.labelColor.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelColor.Name = "labelColor";
|
||||
this.labelColor.Size = new System.Drawing.Size(132, 40);
|
||||
this.labelColor.TabIndex = 2;
|
||||
this.labelColor.Text = "Основной цвет";
|
||||
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelColor.DragDrop += labelColor_dragDrop;
|
||||
this.labelColor.DragEnter += labelColor_dragEnter;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(626, 233);
|
||||
this.buttonAdd.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(152, 41);
|
||||
this.buttonAdd.TabIndex = 3;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(794, 233);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(152, 41);
|
||||
this.buttonCancel.TabIndex = 4;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormBulldozerConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(978, 291);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.panelObject);
|
||||
this.Controls.Add(this.groupBoxParameters);
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "FormBulldozerConfig";
|
||||
this.Text = "Создание объекта";
|
||||
this.groupBoxParameters.ResumeLayout(false);
|
||||
this.groupBoxParameters.PerformLayout();
|
||||
this.groupBoxMarks.ResumeLayout(false);
|
||||
this.groupBoxMarks.PerformLayout();
|
||||
this.groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||
this.panelObject.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxParameters;
|
||||
private CheckBox checkBoxBlade;
|
||||
private CheckBox checkBoxRipper;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelWeight;
|
||||
private Label labelSpeed;
|
||||
private Label labelModifiedObject;
|
||||
private Label labelSimpleObject;
|
||||
private GroupBox groupBoxColors;
|
||||
private Panel panelPurple;
|
||||
private Panel panelBlack;
|
||||
private Panel panelGray;
|
||||
private Panel panelWhite;
|
||||
private Panel panelYellow;
|
||||
private Panel panelBlue;
|
||||
private Panel panelGreen;
|
||||
private Panel panelRed;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Panel panelObject;
|
||||
private Label labelAddColor;
|
||||
private Label labelColor;
|
||||
private Button buttonAdd;
|
||||
private Button buttonCancel;
|
||||
private GroupBox groupBoxMarks;
|
||||
}
|
||||
}
|
146
Bulldozer/Bulldozer/FormBulldozerConfig.cs
Normal file
146
Bulldozer/Bulldozer/FormBulldozerConfig.cs
Normal file
@ -0,0 +1,146 @@
|
||||
using Bulldozer.Entities;
|
||||
using Bulldozer.DrawingObjects;
|
||||
|
||||
namespace Bulldozer
|
||||
{
|
||||
public partial class FormBulldozerConfig : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Переменная-выбранный бульдозер
|
||||
/// </summary>
|
||||
DrawingBulldozer? _bulldozer = null;
|
||||
|
||||
/// <summary>
|
||||
/// Делегат для передачи объекта-бульдозера
|
||||
/// </summary>
|
||||
private event Action<DrawingBulldozer>? EventAddBulldozer;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormBulldozerConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += panelColor_MouseDown;
|
||||
panelPurple.MouseDown += panelColor_MouseDown;
|
||||
panelGray.MouseDown += panelColor_MouseDown;
|
||||
panelGreen.MouseDown += panelColor_MouseDown;
|
||||
panelRed.MouseDown += panelColor_MouseDown;
|
||||
panelWhite.MouseDown += panelColor_MouseDown;
|
||||
panelYellow.MouseDown += panelColor_MouseDown;
|
||||
panelBlue.MouseDown += panelColor_MouseDown;
|
||||
buttonCancel.Click += (s, e) => Close();
|
||||
}
|
||||
|
||||
private void DrawBulldozer()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_bulldozer?.SetPosition(5, 5);
|
||||
_bulldozer?.DrawTransport(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev">Привязанный метод</param>
|
||||
public void AddEvent(Action<DrawingBulldozer> ev)
|
||||
{
|
||||
if (EventAddBulldozer == null)
|
||||
{
|
||||
EventAddBulldozer = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddBulldozer += ev;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Передаем информацию при нажатии на Label
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void labelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Действия при приеме перетаскиваемой информации
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_bulldozer = new DrawingBulldozer((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Cyan, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_bulldozer = new DrawingBulldozerUpgraded((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, Color.Blue,checkBoxRipper.Checked, checkBoxBlade.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
break;
|
||||
}
|
||||
DrawBulldozer();
|
||||
}
|
||||
|
||||
public void panelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
private void labelColor_dragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
private void labelColor_dragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_bulldozer == null)
|
||||
return;
|
||||
switch (((Label)sender).Name)
|
||||
{
|
||||
case "labelColor":
|
||||
_bulldozer?.EntityBulldozer?.SetBodyColor((Color) e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
case "labelAddColor":
|
||||
if (!(_bulldozer is DrawingBulldozerUpgraded))
|
||||
return;
|
||||
(_bulldozer.EntityBulldozer as EntityBulldozerUpgraded)?.SetDopColor(dopColor: (Color) e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
}
|
||||
DrawBulldozer();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление бульдозера
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddBulldozer?.Invoke(_bulldozer);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
Bulldozer/Bulldozer/FormBulldozerConfig.resx
Normal file
60
Bulldozer/Bulldozer/FormBulldozerConfig.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
151
Bulldozer/Bulldozer/Generics/BulldozersGenericCollection.cs
Normal file
151
Bulldozer/Bulldozer/Generics/BulldozersGenericCollection.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using Bulldozer.DrawingObjects;
|
||||
using Bulldozer.MovementStrategy;
|
||||
|
||||
namespace Bulldozer.Generics
|
||||
{
|
||||
internal class BulldozersGenericCollection<T, U>
|
||||
where T : DrawingBulldozer
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetBulldozers => _collection.GetBulldozers();
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 270;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 70;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public BulldozersGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(BulldozersGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return -1;
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static T? operator -(BulldozersGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowBulldozers()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 20, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int heightObjCount = _pictureHeight / _placeSizeHeight;
|
||||
int widthObjCount = _pictureWidth / _placeSizeWidth;
|
||||
int totalObjects = _collection.Count;
|
||||
int i = 0;
|
||||
foreach (var bulldozer in _collection.GetBulldozers())
|
||||
{
|
||||
|
||||
if (bulldozer != null)
|
||||
{
|
||||
int col = widthObjCount - 1 - (i % widthObjCount);
|
||||
int row = heightObjCount - 1 - (i / widthObjCount);
|
||||
|
||||
bulldozer.SetPosition(col * _placeSizeWidth + 3, row * _placeSizeHeight + 3);
|
||||
bulldozer?.DrawTransport(g);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i > totalObjects)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
188
Bulldozer/Bulldozer/Generics/BulldozersGenericStorage.cs
Normal file
188
Bulldozer/Bulldozer/Generics/BulldozersGenericStorage.cs
Normal file
@ -0,0 +1,188 @@
|
||||
using Bulldozer.DrawingObjects;
|
||||
using Bulldozer.MovementStrategy;
|
||||
using System.Text;
|
||||
|
||||
namespace Bulldozer.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции
|
||||
/// </summary>
|
||||
internal class BulldozersGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>> _bulldozerStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _bulldozerStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public BulldozersGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_bulldozerStorages = new Dictionary<string, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (!_bulldozerStorages.ContainsKey(name))
|
||||
{
|
||||
_bulldozerStorages.Add(name, new BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
// TODO: Прописать логику для удаления набора
|
||||
if (_bulldozerStorages.ContainsKey(name))
|
||||
{
|
||||
_bulldozerStorages.Remove(name);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_bulldozerStorages.ContainsKey(ind))
|
||||
{
|
||||
return _bulldozerStorages[ind];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
/// </summary>
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char _separatorRecords = ';';
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение информации по автомобилям в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>> record in _bulldozerStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawingBulldozer? elem in record.Value.GetBulldozers)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string toWrite = $"BulldozerStorage{Environment.NewLine}{data}";
|
||||
var strs = toWrite.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
using (StreamWriter sw = new(filename))
|
||||
{
|
||||
foreach (var str in strs)
|
||||
{
|
||||
sw.WriteLine(str);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка информации по автомобилям в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
string str = sr.ReadLine();
|
||||
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!strs[0].StartsWith("BulldozerStorage"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_bulldozerStorages.Clear();
|
||||
do
|
||||
{
|
||||
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
str = sr.ReadLine();
|
||||
continue;
|
||||
}
|
||||
BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawingBulldozer? bulldozer =
|
||||
elem?.CreateDrawingBulldozer(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (bulldozer != null)
|
||||
{
|
||||
if ((collection + bulldozer) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_bulldozerStorages.Add(record[0], collection);
|
||||
|
||||
str = sr.ReadLine();
|
||||
} while (str != null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
126
Bulldozer/Bulldozer/Generics/SetGeneric.cs
Normal file
126
Bulldozer/Bulldozer/Generics/SetGeneric.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace Bulldozer.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T?> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в списке
|
||||
/// </summary>
|
||||
public int Count => _places.Count;
|
||||
|
||||
/// <summary>
|
||||
/// Максимальное количество объектов в списке
|
||||
/// </summary>
|
||||
private readonly int _maxCount;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T?>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="bulldozer">Добавляемый бульдозер</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T bulldozer)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
return -1;
|
||||
Insert(bulldozer, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="bulldozer">Добавляемый бульдозер</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T bulldozer , int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount) return -1;
|
||||
_places.Insert(position, bulldozer);
|
||||
return position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
return false;
|
||||
|
||||
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
// Позиция находится за пределами допустимого диапазона, вернем null
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= Count) return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position >= Count || Count == _maxCount) return;
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetBulldozers(int? maxBulldozers = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxBulldozers.HasValue && i == maxBulldozers.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
126
Bulldozer/Bulldozer/MovementStrategy/AbstractStrategy.cs
Normal file
126
Bulldozer/Bulldozer/MovementStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,126 @@
|
||||
namespace Bulldozer.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,31 @@
|
||||
using Bulldozer.DrawingObjects;
|
||||
|
||||
|
||||
namespace Bulldozer.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Реализация интерфейса IDrawingObject для работы с объектом DrawingBulldozer (паттерн Adapter)
|
||||
/// </summary>
|
||||
public class DrawingObjectBulldozer : IMoveableObject
|
||||
{
|
||||
private readonly DrawingBulldozer? _drawingBulldozer = null;
|
||||
public DrawingObjectBulldozer(DrawingBulldozer drawingBulldozer)
|
||||
{
|
||||
_drawingBulldozer = drawingBulldozer;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawingBulldozer == null || _drawingBulldozer.EntityBulldozer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawingBulldozer.GetPosX, _drawingBulldozer.GetPosY, _drawingBulldozer.GetWidth, _drawingBulldozer.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawingBulldozer?.EntityBulldozer?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) => _drawingBulldozer?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) => _drawingBulldozer?.MoveTransport(direction);
|
||||
}
|
||||
}
|
30
Bulldozer/Bulldozer/MovementStrategy/IMoveableObject.cs
Normal file
30
Bulldozer/Bulldozer/MovementStrategy/IMoveableObject.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Bulldozer.DrawingObjects;
|
||||
|
||||
namespace Bulldozer.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);
|
||||
}
|
||||
}
|
57
Bulldozer/Bulldozer/MovementStrategy/MoveToBorder.cs
Normal file
57
Bulldozer/Bulldozer/MovementStrategy/MoveToBorder.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using Bulldozer.DrawingObjects;
|
||||
namespace Bulldozer.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в правую нижнюю границу экрана
|
||||
/// </summary>
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
|
||||
var objParams = GetObjectParameters;
|
||||
|
||||
return objParams != null
|
||||
&& objParams.ObjectMiddleHorizontal >= FieldWidth
|
||||
&& objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth
|
||||
&& objParams.ObjectMiddleVertical >= FieldHeight
|
||||
&& objParams.ObjectMiddleVertical - GetStep() <= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
|
||||
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
Bulldozer/Bulldozer/MovementStrategy/MoveToCenter.cs
Normal file
51
Bulldozer/Bulldozer/MovementStrategy/MoveToCenter.cs
Normal file
@ -0,0 +1,51 @@
|
||||
namespace Bulldozer.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в центр экрана
|
||||
/// </summary>
|
||||
public 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
52
Bulldozer/Bulldozer/MovementStrategy/ObjectParameters.cs
Normal file
52
Bulldozer/Bulldozer/MovementStrategy/ObjectParameters.cs
Normal file
@ -0,0 +1,52 @@
|
||||
namespace Bulldozer.MovementStrategy
|
||||
{
|
||||
/// <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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
12
Bulldozer/Bulldozer/MovementStrategy/Status.cs
Normal file
12
Bulldozer/Bulldozer/MovementStrategy/Status.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace Bulldozer.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace Bulldozer
|
||||
namespace Bulldozer.MovementStrategy
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
@ -8,10 +8,8 @@ namespace Bulldozer
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new FormBulldozerCollection());
|
||||
}
|
||||
}
|
||||
}
|
103
Bulldozer/Bulldozer/Properties/Resources.Designer.cs
generated
Normal file
103
Bulldozer/Bulldozer/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Bulldozer.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Bulldozer.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrowDown {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrowDown", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrowLeft {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrowLeft", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrowRight {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrowRight", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrowUp {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrowUp", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -117,4 +117,17 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="arrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
BIN
Bulldozer/Bulldozer/Resources/arrowDown.png
Normal file
BIN
Bulldozer/Bulldozer/Resources/arrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
Bulldozer/Bulldozer/Resources/arrowLeft.png
Normal file
BIN
Bulldozer/Bulldozer/Resources/arrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 104 KiB |
BIN
Bulldozer/Bulldozer/Resources/arrowRight.png
Normal file
BIN
Bulldozer/Bulldozer/Resources/arrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 104 KiB |
BIN
Bulldozer/Bulldozer/Resources/arrowUp.png
Normal file
BIN
Bulldozer/Bulldozer/Resources/arrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.0 KiB |
Loading…
Reference in New Issue
Block a user