Compare commits
2 Commits
Laba_7_Dum
...
main
Author | SHA1 | Date | |
---|---|---|---|
a82d645309 | |||
602e71d6a6 |
@ -1,2 +0,0 @@
|
||||
TruckStorage
|
||||
111|100:100:Lime:Blue:True;100:100:Lime;100:100:Lime;100:100:Brown;100:100:Yellow:Lime:True;100:100:Red:Black:False;100:100:ActiveCaptionText:ButtonHighlight:True;100:100:Blue:Black:False;100:100:Blue;100:100:Lime;100:100:OrangeRed;100:100:White:Red:True;100:100:Lime;100:100:White:Black:False;100:100:White:Red:True;100:100:Blue:Black:False;100:100:ActiveCaptionText;100:100:White:Lime:True;100:100:Red;100:100:Blue:Red:True;
|
@ -1,2 +0,0 @@
|
||||
TruckStorage
|
||||
111|
|
25
CarRepairShop/CarRepairShop/CarRepairShop.sln
Normal file
25
CarRepairShop/CarRepairShop/CarRepairShop.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34525.116
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShopView", "CarRepairShopView\CarRepairShopView.csproj", "{5CC03CDD-1895-4F1F-858F-52713F693403}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5CC03CDD-1895-4F1F-858F-52713F693403}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5CC03CDD-1895-4F1F-858F-52713F693403}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5CC03CDD-1895-4F1F-858F-52713F693403}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5CC03CDD-1895-4F1F-858F-52713F693403}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F3F1A98D-8A28-4388-85A4-17B0C31F0B66}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
39
CarRepairShop/CarRepairShop/CarRepairShopView/Form1.Designer.cs
generated
Normal file
39
CarRepairShop/CarRepairShop/CarRepairShopView/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,39 @@
|
||||
namespace CarRepairShopView
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
10
CarRepairShop/CarRepairShop/CarRepairShopView/Form1.cs
Normal file
10
CarRepairShop/CarRepairShop/CarRepairShopView/Form1.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace CarRepairShopView
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
@ -26,36 +26,36 @@
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
17
CarRepairShop/CarRepairShop/CarRepairShopView/Program.cs
Normal file
17
CarRepairShop/CarRepairShop/CarRepairShopView/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace CarRepairShopView
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[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());
|
||||
}
|
||||
}
|
||||
}
|
@ -3,13 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.2.32616.157
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DumpTruck", "DumpTruck\DumpTruck.csproj", "{DCAA55AD-0C09-4CF9-B6B6-4CC43082AC55}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решения", "Элементы решения", "{846638BC-8C15-4072-9D60-8404116C8EEE}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
appsettings.json = appsettings.json
|
||||
nlog.config = nlog.config
|
||||
EndProjectSection
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DumpTruck", "DumpTruck\DumpTruck.csproj", "{DCAA55AD-0C09-4CF9-B6B6-4CC43082AC55}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -1,130 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DumpTruck.Entities;
|
||||
|
||||
namespace DumpTruck.DrawningObjects
|
||||
{
|
||||
internal class DrawningDumpTruck : DrawningTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена,
|
||||
public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool trailer, int width, int height)
|
||||
: base (speed, weight, bodyColor, width, height,110, 85)
|
||||
{
|
||||
if (EntityTruck != null)
|
||||
{
|
||||
EntityTruck = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, trailer);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTruck is not EntityDumpTruck dumpTruck
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
if (dumpTruck.Trailer)
|
||||
{
|
||||
//прицеп
|
||||
Brush trailer = new SolidBrush(dumpTruck.AdditionalColor);
|
||||
g.FillRectangle(trailer, _startPosX, _startPosY, 5, 38);
|
||||
g.FillRectangle(trailer, _startPosX + 5, _startPosY + 33, 70, 5);
|
||||
g.FillRectangle(trailer, _startPosX + 70, _startPosY, 5, 38);
|
||||
}
|
||||
}
|
||||
public void SetAdditionalColor(Color color)
|
||||
{
|
||||
(EntityTruck as EntityDumpTruck).SetAdditionalColor(color);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DumpTruck.DrawningObjects;
|
||||
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
{
|
||||
internal class DrawningObjectTruck : IMoveableObject
|
||||
|
||||
{
|
||||
private readonly DrawningTruck? _drawningTruck = null;
|
||||
public DrawningObjectTruck(DrawningTruck drawningTruck)
|
||||
{
|
||||
_drawningTruck = drawningTruck;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningTruck == null || _drawningTruck.EntityTruck == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningTruck.GetPosX, _drawningTruck.GetPosY, _drawningTruck.GetWidth, _drawningTruck.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningTruck?.EntityTruck?.Step ?? 0);
|
||||
|
||||
public bool CheckCanMove(DirectionType direction) => _drawningTruck?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) => _drawningTruck?.MoveTransport(direction);
|
||||
}
|
||||
}
|
@ -1,220 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DumpTruck.Entities;
|
||||
using DumpTruck.MovementStrategy;
|
||||
|
||||
namespace DumpTruck.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityTruck? EntityTruck { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectTruck(this);
|
||||
/// <summary>
|
||||
public int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
public int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected readonly int _truckWidth = 110;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected readonly int _truckHeight = 85;
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _truckWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _truckHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawningTruck(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
if (width < _truckWidth || height < _truckHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityTruck = new EntityTruck(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <param name="truckWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="truckHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawningTruck(int speed, double weight, Color bodyColor, int width, int height, int truckWidth, int truckHeight)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
if (width < _truckWidth || height < _truckHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_truckWidth = truckWidth;
|
||||
_truckHeight = truckHeight;
|
||||
EntityTruck = new EntityTruck(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x + _truckWidth > _pictureWidth)
|
||||
{
|
||||
x = Math.Max(0, _pictureWidth - _truckWidth);
|
||||
}
|
||||
if (y < 0 || y + _truckHeight > _pictureHeight)
|
||||
{
|
||||
y = Math.Max(0, _pictureHeight - _truckHeight);
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка, что объект может переместится по указанному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityTruck == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityTruck.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityTruck.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + _truckWidth + EntityTruck.Step < _pictureWidth,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + _truckHeight + EntityTruck.Step < _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityTruck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityTruck.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityTruck.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityTruck.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityTruck.Step;
|
||||
}
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + _truckWidth + EntityTruck.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityTruck.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + _truckHeight + EntityTruck.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityTruck.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTruck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
//грани
|
||||
g.DrawRectangle(pen, _startPosX + 80, _startPosY, 30, 40);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 40, 110, 20);
|
||||
//кузов
|
||||
Brush br = new SolidBrush(EntityTruck.BodyColor);
|
||||
g.FillRectangle(br, _startPosX + 81, _startPosY + 1, 29, 40);
|
||||
Brush br1 = new SolidBrush(EntityTruck.BodyColor);
|
||||
g.FillRectangle(br1, _startPosX + 1, _startPosY + 41, 109, 19);
|
||||
//колеса
|
||||
Brush wheels = new SolidBrush(Color.Black);
|
||||
g.FillEllipse(wheels, _startPosX, _startPosY + 63, 25, 25);
|
||||
g.FillEllipse(wheels, _startPosX + 25, _startPosY + 63, 25, 25);
|
||||
g.FillEllipse(wheels, _startPosX + 85, _startPosY + 63, 25, 25);
|
||||
}
|
||||
public void SetBodyColor(Color color)
|
||||
{
|
||||
EntityTruck.SetBodyColor(color);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -2,34 +2,10 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<SupportedOSPlatformVersion>10.0.22621.0</SupportedOSPlatformVersion>
|
||||
<UseWPF>True</UseWPF>
|
||||
<StartupObject></StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="nlog.config" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.AppSettings" Version="2.2.2" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.Entities
|
||||
{
|
||||
public class EntityDumpTruck : EntityTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// </summary>
|
||||
public bool Trailer { get; private set; }
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
|
||||
/// Инициализация полей объекта-класса
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
public EntityDumpTruck(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool trailer) : base (speed,weight, bodyColor)
|
||||
{
|
||||
Trailer = trailer;
|
||||
AdditionalColor = additionalColor;
|
||||
}
|
||||
public void SetAdditionalColor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Автомобиль"
|
||||
/// </summary>
|
||||
public class EntityTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Конструктор с параметрами
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityTruck(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
public void SetBodyColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,67 +0,0 @@
|
||||
using DumpTruck.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Расширение для класса EntityCar
|
||||
/// </summary>
|
||||
public static class ExtentionDrawningTruck
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawningTruck? CreateDrawningTruck(this string info, char
|
||||
separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawningTruck(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 5)
|
||||
{
|
||||
return new DrawningDumpTruck(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]),
|
||||
Convert.ToBoolean(strs[4]),
|
||||
width, height);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningTruck">Сохраняемый объект</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawningTruck drawningTruck,
|
||||
char separatorForObject)
|
||||
{
|
||||
var truck = drawningTruck.EntityTruck;
|
||||
if (truck == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str =
|
||||
$"{truck.Speed}{separatorForObject}{truck.Weight}{separatorForObject}{truck.BodyColor.Name}";
|
||||
if (truck is not EntityDumpTruck dumpTruck)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{separatorForObject}{dumpTruck.AdditionalColor.Name}{separatorForObject}{dumpTruck.Trailer}";
|
||||
}
|
||||
}
|
||||
}
|
39
DumpTruck/DumpTruck/Form1.Designer.cs
generated
Normal file
39
DumpTruck/DumpTruck/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,39 @@
|
||||
namespace DumpTruck
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
10
DumpTruck/DumpTruck/Form1.cs
Normal file
10
DumpTruck/DumpTruck/Form1.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace DumpTruck
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
@ -26,36 +26,36 @@
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
192
DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
generated
192
DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
generated
@ -1,192 +0,0 @@
|
||||
namespace DumpTruck
|
||||
{
|
||||
partial class FormDumpTruck
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
pictureBoxDumpTruck = new PictureBox();
|
||||
buttonUp = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
Create_Truck_Button = new Button();
|
||||
CreateDumpTruckButton = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
Step_Button = new Button();
|
||||
buttonSelectTruck = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxDumpTruck
|
||||
//
|
||||
pictureBoxDumpTruck.Dock = DockStyle.Fill;
|
||||
pictureBoxDumpTruck.Location = new Point(0, 0);
|
||||
pictureBoxDumpTruck.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxDumpTruck.Name = "pictureBoxDumpTruck";
|
||||
pictureBoxDumpTruck.Size = new Size(1010, 615);
|
||||
pictureBoxDumpTruck.TabIndex = 0;
|
||||
pictureBoxDumpTruck.TabStop = false;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(909, 499);
|
||||
buttonUp.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(27, 35);
|
||||
buttonUp.TabIndex = 2;
|
||||
buttonUp.Text = "1";
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.BackColor = SystemColors.ControlDark;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(874, 541);
|
||||
buttonLeft.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(27, 35);
|
||||
buttonLeft.TabIndex = 3;
|
||||
buttonLeft.Text = "3";
|
||||
buttonLeft.UseVisualStyleBackColor = false;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(943, 543);
|
||||
buttonRight.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(27, 35);
|
||||
buttonRight.TabIndex = 4;
|
||||
buttonRight.Text = "4";
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(909, 541);
|
||||
buttonDown.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(27, 35);
|
||||
buttonDown.TabIndex = 5;
|
||||
buttonDown.Text = "2";
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// Create_Truck_Button
|
||||
//
|
||||
Create_Truck_Button.Location = new Point(14, 523);
|
||||
Create_Truck_Button.Margin = new Padding(3, 4, 3, 4);
|
||||
Create_Truck_Button.Name = "Create_Truck_Button";
|
||||
Create_Truck_Button.Size = new Size(141, 31);
|
||||
Create_Truck_Button.TabIndex = 6;
|
||||
Create_Truck_Button.Text = "Create Truck";
|
||||
Create_Truck_Button.UseVisualStyleBackColor = true;
|
||||
Create_Truck_Button.Click += Create_Truck_Button_Click;
|
||||
//
|
||||
// CreateDumpTruckButton
|
||||
//
|
||||
CreateDumpTruckButton.Location = new Point(190, 523);
|
||||
CreateDumpTruckButton.Margin = new Padding(3, 4, 3, 4);
|
||||
CreateDumpTruckButton.Name = "CreateDumpTruckButton";
|
||||
CreateDumpTruckButton.Size = new Size(192, 31);
|
||||
CreateDumpTruckButton.TabIndex = 7;
|
||||
CreateDumpTruckButton.Text = "Create DumpTruck";
|
||||
CreateDumpTruckButton.UseVisualStyleBackColor = true;
|
||||
CreateDumpTruckButton.Click += CreateDumpTruckButton_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
|
||||
comboBoxStrategy.Location = new Point(858, 16);
|
||||
comboBoxStrategy.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(138, 28);
|
||||
comboBoxStrategy.TabIndex = 8;
|
||||
//
|
||||
// Step_Button
|
||||
//
|
||||
Step_Button.Location = new Point(911, 55);
|
||||
Step_Button.Margin = new Padding(3, 4, 3, 4);
|
||||
Step_Button.Name = "Step_Button";
|
||||
Step_Button.Size = new Size(86, 31);
|
||||
Step_Button.TabIndex = 9;
|
||||
Step_Button.Text = "Step";
|
||||
Step_Button.UseVisualStyleBackColor = true;
|
||||
Step_Button.Click += Step_Button_Click;
|
||||
//
|
||||
// buttonSelectTruck
|
||||
//
|
||||
buttonSelectTruck.Location = new Point(443, 523);
|
||||
buttonSelectTruck.Name = "buttonSelectTruck";
|
||||
buttonSelectTruck.Size = new Size(94, 29);
|
||||
buttonSelectTruck.TabIndex = 10;
|
||||
buttonSelectTruck.Text = "SelectTruck";
|
||||
buttonSelectTruck.UseVisualStyleBackColor = true;
|
||||
buttonSelectTruck.Click += buttonSelectTruck_Click_1;
|
||||
//
|
||||
// FormDumpTruck
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1010, 615);
|
||||
Controls.Add(buttonSelectTruck);
|
||||
Controls.Add(Step_Button);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(CreateDumpTruckButton);
|
||||
Controls.Add(Create_Truck_Button);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(pictureBoxDumpTruck);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormDumpTruck";
|
||||
Text = "FormDumpTruck";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxDumpTruck;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button Create_Truck_Button;
|
||||
private Button CreateDumpTruckButton;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button Step_Button;
|
||||
private Button buttonSelectTruck;
|
||||
}
|
||||
}
|
@ -1,159 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.MovementStrategy;
|
||||
|
||||
|
||||
namespace DumpTruck
|
||||
{
|
||||
public partial class FormDumpTruck : Form
|
||||
{
|
||||
private DrawningTruck? _drawningTruck;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
/// Выбранный автомобиль
|
||||
/// </summary>
|
||||
public DrawningTruck? selectedTruck { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация формы
|
||||
/// </summary>
|
||||
public FormDumpTruck()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
selectedTruck = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningTruck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxDumpTruck.Width,
|
||||
pictureBoxDumpTruck.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningTruck.DrawTransport(gr);
|
||||
pictureBoxDumpTruck.Image = bmp;
|
||||
}
|
||||
private void Create_Truck_Button_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
_drawningTruck = new DrawningTruck(random.Next(100, 300), random.Next(1000, 3000),
|
||||
color,
|
||||
pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
|
||||
_drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void CreateDumpTruckButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
Color color2 = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog2 = new();
|
||||
if (dialog2.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color2 = dialog2.Color;
|
||||
}
|
||||
_drawningTruck = new DrawningDumpTruck(random.Next(100, 300), random.Next(1000, 3000),
|
||||
color, color2,
|
||||
Convert.ToBoolean(1), pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
|
||||
_drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningTruck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningTruck.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningTruck.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningTruck.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningTruck.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void Step_Button_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningTruck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawningObjectTruck(_drawningTruck), pictureBoxDumpTruck.Width,
|
||||
pictureBoxDumpTruck.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectTruck_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
selectedTruck = _drawningTruck;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
255
DumpTruck/DumpTruck/FormTruckCollection.Designer.cs
generated
255
DumpTruck/DumpTruck/FormTruckCollection.Designer.cs
generated
@ -1,255 +0,0 @@
|
||||
namespace DumpTruck
|
||||
{
|
||||
partial class FormTruckCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBox1 = new GroupBox();
|
||||
groupBox2 = new GroupBox();
|
||||
textBoxStorageName = new TextBox();
|
||||
listBoxStorages = new ListBox();
|
||||
buttonRemoveObject = new Button();
|
||||
buttonAddObject = new Button();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonRefreshCollection = new Button();
|
||||
buttonRemoveTruck = new Button();
|
||||
buttonAddTruck = new Button();
|
||||
menuStrip = new MenuStrip();
|
||||
toolStripMenuItem1 = new ToolStripMenuItem();
|
||||
toolStripMenuItemLoad = new ToolStripMenuItem();
|
||||
toolStripMenuItemSave = new ToolStripMenuItem();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
groupBox1.SuspendLayout();
|
||||
groupBox2.SuspendLayout();
|
||||
menuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(groupBox2);
|
||||
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||
groupBox1.Controls.Add(buttonRefreshCollection);
|
||||
groupBox1.Controls.Add(buttonRemoveTruck);
|
||||
groupBox1.Controls.Add(buttonAddTruck);
|
||||
groupBox1.Controls.Add(menuStrip);
|
||||
groupBox1.Location = new Point(689, 16);
|
||||
groupBox1.Margin = new Padding(3, 4, 3, 4);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Padding = new Padding(3, 4, 3, 4);
|
||||
groupBox1.Size = new Size(229, 568);
|
||||
groupBox1.TabIndex = 0;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
groupBox2.Controls.Add(textBoxStorageName);
|
||||
groupBox2.Controls.Add(listBoxStorages);
|
||||
groupBox2.Controls.Add(buttonRemoveObject);
|
||||
groupBox2.Controls.Add(buttonAddObject);
|
||||
groupBox2.Location = new Point(3, 24);
|
||||
groupBox2.Name = "groupBox2";
|
||||
groupBox2.Size = new Size(220, 267);
|
||||
groupBox2.TabIndex = 5;
|
||||
groupBox2.TabStop = false;
|
||||
groupBox2.Text = "Наборы";
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(30, 26);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(171, 27);
|
||||
textBoxStorageName.TabIndex = 3;
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.Location = new Point(30, 107);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(171, 104);
|
||||
listBoxStorages.TabIndex = 2;
|
||||
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||
//
|
||||
// buttonRemoveObject
|
||||
//
|
||||
buttonRemoveObject.Location = new Point(30, 217);
|
||||
buttonRemoveObject.Name = "buttonRemoveObject";
|
||||
buttonRemoveObject.Size = new Size(171, 39);
|
||||
buttonRemoveObject.TabIndex = 1;
|
||||
buttonRemoveObject.Text = "Удалить набор";
|
||||
buttonRemoveObject.UseVisualStyleBackColor = true;
|
||||
buttonRemoveObject.Click += buttonDelObject_Click;
|
||||
//
|
||||
// buttonAddObject
|
||||
//
|
||||
buttonAddObject.Location = new Point(30, 59);
|
||||
buttonAddObject.Name = "buttonAddObject";
|
||||
buttonAddObject.Size = new Size(171, 33);
|
||||
buttonAddObject.TabIndex = 0;
|
||||
buttonAddObject.Text = "Добавить набор";
|
||||
buttonAddObject.UseVisualStyleBackColor = true;
|
||||
buttonAddObject.Click += buttonAddObject_Click;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(7, 428);
|
||||
maskedTextBoxNumber.Margin = new Padding(3, 4, 3, 4);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(114, 27);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(0, 516);
|
||||
buttonRefreshCollection.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(215, 44);
|
||||
buttonRefreshCollection.TabIndex = 3;
|
||||
buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||
//
|
||||
// buttonRemoveTruck
|
||||
//
|
||||
buttonRemoveTruck.Location = new Point(0, 463);
|
||||
buttonRemoveTruck.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRemoveTruck.Name = "buttonRemoveTruck";
|
||||
buttonRemoveTruck.Size = new Size(215, 45);
|
||||
buttonRemoveTruck.TabIndex = 2;
|
||||
buttonRemoveTruck.Text = "Удалить грузовик";
|
||||
buttonRemoveTruck.UseVisualStyleBackColor = true;
|
||||
buttonRemoveTruck.Click += buttonRemoveTruck_Click;
|
||||
//
|
||||
// buttonAddTruck
|
||||
//
|
||||
buttonAddTruck.Location = new Point(0, 379);
|
||||
buttonAddTruck.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddTruck.Name = "buttonAddTruck";
|
||||
buttonAddTruck.Size = new Size(215, 41);
|
||||
buttonAddTruck.TabIndex = 1;
|
||||
buttonAddTruck.Text = "Добавить грузовик";
|
||||
buttonAddTruck.UseVisualStyleBackColor = true;
|
||||
buttonAddTruck.Click += buttonAddTruck_Click;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
menuStrip.AutoSize = false;
|
||||
menuStrip.Dock = DockStyle.None;
|
||||
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem1 });
|
||||
menuStrip.Location = new Point(7, 314);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.RenderMode = ToolStripRenderMode.Professional;
|
||||
menuStrip.Size = new Size(223, 47);
|
||||
menuStrip.TabIndex = 6;
|
||||
menuStrip.Tag = "";
|
||||
menuStrip.Text = "menuStrip";
|
||||
//
|
||||
// toolStripMenuItem1
|
||||
//
|
||||
toolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemLoad, toolStripMenuItemSave });
|
||||
toolStripMenuItem1.Name = "toolStripMenuItem1";
|
||||
toolStripMenuItem1.Size = new Size(44, 43);
|
||||
toolStripMenuItem1.Text = "file";
|
||||
//
|
||||
// toolStripMenuItemLoad
|
||||
//
|
||||
toolStripMenuItemLoad.Name = "toolStripMenuItemLoad";
|
||||
toolStripMenuItemLoad.Size = new Size(224, 26);
|
||||
toolStripMenuItemLoad.Text = "Load";
|
||||
toolStripMenuItemLoad.Click += LoadStripMenuItem_Click;
|
||||
//
|
||||
// toolStripMenuItemSave
|
||||
//
|
||||
toolStripMenuItemSave.Name = "toolStripMenuItemSave";
|
||||
toolStripMenuItemSave.Size = new Size(224, 26);
|
||||
toolStripMenuItemSave.Text = "Save";
|
||||
toolStripMenuItemSave.Click += SaveStripMenuItem_Click;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location = new Point(11, 16);
|
||||
pictureBoxCollection.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(672, 568);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.FileName = "openFileDialog";
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormTruckCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(935, 611);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(groupBox1);
|
||||
MainMenuStrip = menuStrip;
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormTruckCollection";
|
||||
Text = "Набор грузовиков";
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
groupBox2.ResumeLayout(false);
|
||||
groupBox2.PerformLayout();
|
||||
menuStrip.ResumeLayout(false);
|
||||
menuStrip.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox1;
|
||||
private Button buttonAddTruck;
|
||||
private Button buttonRemoveTruck;
|
||||
private Button buttonRefreshCollection;
|
||||
private PictureBox pictureBoxCollection;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private GroupBox groupBox2;
|
||||
private Button buttonRemoveObject;
|
||||
private Button buttonAddObject;
|
||||
private ListBox listBoxStorages;
|
||||
private TextBox textBoxStorageName;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem toolStripMenuItem1;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private ToolStripMenuItem toolStripMenuItemLoad;
|
||||
private ToolStripMenuItem toolStripMenuItemSave;
|
||||
}
|
||||
}
|
@ -1,244 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml;
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.Generics;
|
||||
using DumpTruck.MovementStrategy;
|
||||
using DumpTruck.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Windows;
|
||||
using NLog;
|
||||
|
||||
|
||||
namespace DumpTruck
|
||||
{
|
||||
public partial class FormTruckCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly TrucksGenericStorage _storage;
|
||||
|
||||
private readonly Microsoft.Extensions.Logging.ILogger _logger;
|
||||
public FormTruckCollection(ILogger<FormTruckCollection> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new TrucksGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||
>= listBoxStorages.Items.Count))
|
||||
{
|
||||
listBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
||||
index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void buttonRemoveTruck_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning($"Не удалось удалить объект: не выбран набор");
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning($"Не удалось удалить объект: набор пуст");
|
||||
return;
|
||||
}
|
||||
if (System.Windows.Forms.MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
try
|
||||
{
|
||||
if (obj - pos)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowTrucks();
|
||||
_logger.LogInformation($"Удален объект на позиции: {pos}");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
catch (TruckNotFoundException ex)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Не удалось удалить объект: {ex.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowTrucks();
|
||||
}
|
||||
|
||||
private void buttonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}");
|
||||
}
|
||||
|
||||
private void AddTruck(DrawningTruck truck)
|
||||
{
|
||||
truck._pictureWidth = pictureBoxCollection.Width;
|
||||
truck._pictureHeight = pictureBoxCollection.Height;
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning($"Не удалось добавить объект: набор пуст");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (obj + truck != -1)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowTrucks();
|
||||
_logger.LogInformation($"Объект добавлен {truck}");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Не удалось добавить объект: {ex.Message}");
|
||||
}
|
||||
}
|
||||
private void buttonAddTruck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning($"Не удалось добавить объект: не выбран набор");
|
||||
return;
|
||||
}
|
||||
var formTruckConfig = new FormTruckConfig();
|
||||
formTruckConfig.AddEvent(AddTruck);
|
||||
formTruckConfig.Show();
|
||||
}
|
||||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTrucks();
|
||||
}
|
||||
|
||||
private void buttonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||
if (System.Windows.Forms.MessageBox.Show($"Удалить объект {name}?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(name);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Удален набор: {name}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SaveStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.SaveData(saveFileDialog.FileName);
|
||||
System.Windows.Forms.MessageBox.Show("Сохранение прошло успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation($"Сохранение прошло успешно: {saveFileDialog.FileName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.LoadData(openFileDialog.FileName);
|
||||
System.Windows.Forms.MessageBox.Show("Загрузка прошла успешно",
|
||||
"Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Загрузка прошла успешно: {openFileDialog.FileName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show($"Не загрузилось {ex.Message}", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Не загрузилось: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>145, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>315, 17</value>
|
||||
</metadata>
|
||||
</root>
|
352
DumpTruck/DumpTruck/FormTruckConfig.Designer.cs
generated
352
DumpTruck/DumpTruck/FormTruckConfig.Designer.cs
generated
@ -1,352 +0,0 @@
|
||||
namespace DumpTruck
|
||||
{
|
||||
partial class FormTruckConfig
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBoxConfig = new GroupBox();
|
||||
labelModifiedObject = new Label();
|
||||
labelSimpleObject = new Label();
|
||||
groupBoxColor = new GroupBox();
|
||||
panelBlue = new Panel();
|
||||
panelLime = new Panel();
|
||||
panelRed = new Panel();
|
||||
panelOrange = new Panel();
|
||||
panelBrown = new Panel();
|
||||
panelYellow = new Panel();
|
||||
panelBlack = new Panel();
|
||||
panelWrite = new Panel();
|
||||
checkBoxTrailer = new CheckBox();
|
||||
numericUpDownWeight = new NumericUpDown();
|
||||
numericUpDownSpeed = new NumericUpDown();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
pictureBoxObject = new PictureBox();
|
||||
panelObject = new Panel();
|
||||
labelAdditionalColor = new Label();
|
||||
labelBodyColor = new Label();
|
||||
buttonOk = new Button();
|
||||
buttonCancel = new Button();
|
||||
groupBoxConfig.SuspendLayout();
|
||||
groupBoxColor.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
|
||||
panelObject.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxConfig
|
||||
//
|
||||
groupBoxConfig.Controls.Add(labelModifiedObject);
|
||||
groupBoxConfig.Controls.Add(labelSimpleObject);
|
||||
groupBoxConfig.Controls.Add(groupBoxColor);
|
||||
groupBoxConfig.Controls.Add(checkBoxTrailer);
|
||||
groupBoxConfig.Controls.Add(numericUpDownWeight);
|
||||
groupBoxConfig.Controls.Add(numericUpDownSpeed);
|
||||
groupBoxConfig.Controls.Add(label2);
|
||||
groupBoxConfig.Controls.Add(label1);
|
||||
groupBoxConfig.Location = new Point(12, 24);
|
||||
groupBoxConfig.Name = "groupBoxConfig";
|
||||
groupBoxConfig.Size = new Size(724, 393);
|
||||
groupBoxConfig.TabIndex = 0;
|
||||
groupBoxConfig.TabStop = false;
|
||||
groupBoxConfig.Text = "groupBox1";
|
||||
//
|
||||
// labelModifiedObject
|
||||
//
|
||||
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelModifiedObject.Location = new Point(550, 264);
|
||||
labelModifiedObject.Name = "labelModifiedObject";
|
||||
labelModifiedObject.Size = new Size(140, 40);
|
||||
labelModifiedObject.TabIndex = 7;
|
||||
labelModifiedObject.Text = "Продвинутый";
|
||||
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelModifiedObject.MouseDown += LabelObject_MouseDown;
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelSimpleObject.Location = new Point(300, 264);
|
||||
labelSimpleObject.Name = "labelSimpleObject";
|
||||
labelSimpleObject.Size = new Size(140, 40);
|
||||
labelSimpleObject.TabIndex = 6;
|
||||
labelSimpleObject.Text = "Простой";
|
||||
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelSimpleObject.MouseDown += LabelObject_MouseDown;
|
||||
//
|
||||
// groupBoxColor
|
||||
//
|
||||
groupBoxColor.Controls.Add(panelBlue);
|
||||
groupBoxColor.Controls.Add(panelLime);
|
||||
groupBoxColor.Controls.Add(panelRed);
|
||||
groupBoxColor.Controls.Add(panelOrange);
|
||||
groupBoxColor.Controls.Add(panelBrown);
|
||||
groupBoxColor.Controls.Add(panelYellow);
|
||||
groupBoxColor.Controls.Add(panelBlack);
|
||||
groupBoxColor.Controls.Add(panelWrite);
|
||||
groupBoxColor.Location = new Point(287, 26);
|
||||
groupBoxColor.Name = "groupBoxColor";
|
||||
groupBoxColor.Size = new Size(418, 213);
|
||||
groupBoxColor.TabIndex = 5;
|
||||
groupBoxColor.TabStop = false;
|
||||
groupBoxColor.Text = "groupBox2";
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
panelBlue.BackColor = Color.Blue;
|
||||
panelBlue.Location = new Point(317, 123);
|
||||
panelBlue.Name = "panelBlue";
|
||||
panelBlue.Size = new Size(62, 58);
|
||||
panelBlue.TabIndex = 1;
|
||||
panelBlue.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelLime
|
||||
//
|
||||
panelLime.BackColor = Color.Lime;
|
||||
panelLime.Location = new Point(225, 123);
|
||||
panelLime.Name = "panelLime";
|
||||
panelLime.Size = new Size(62, 58);
|
||||
panelLime.TabIndex = 1;
|
||||
panelLime.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
panelRed.BackColor = Color.Red;
|
||||
panelRed.Location = new Point(317, 40);
|
||||
panelRed.Name = "panelRed";
|
||||
panelRed.Size = new Size(62, 58);
|
||||
panelRed.TabIndex = 1;
|
||||
panelRed.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelOrange
|
||||
//
|
||||
panelOrange.BackColor = Color.OrangeRed;
|
||||
panelOrange.Location = new Point(225, 40);
|
||||
panelOrange.Name = "panelOrange";
|
||||
panelOrange.Size = new Size(62, 58);
|
||||
panelOrange.TabIndex = 1;
|
||||
panelOrange.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelBrown
|
||||
//
|
||||
panelBrown.BackColor = Color.Brown;
|
||||
panelBrown.Location = new Point(131, 123);
|
||||
panelBrown.Name = "panelBrown";
|
||||
panelBrown.Size = new Size(62, 58);
|
||||
panelBrown.TabIndex = 1;
|
||||
panelBrown.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
panelYellow.BackColor = Color.Yellow;
|
||||
panelYellow.Location = new Point(131, 40);
|
||||
panelYellow.Name = "panelYellow";
|
||||
panelYellow.Size = new Size(62, 58);
|
||||
panelYellow.TabIndex = 2;
|
||||
panelYellow.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
panelBlack.BackColor = SystemColors.ActiveCaptionText;
|
||||
panelBlack.Location = new Point(30, 123);
|
||||
panelBlack.Name = "panelBlack";
|
||||
panelBlack.Size = new Size(62, 58);
|
||||
panelBlack.TabIndex = 1;
|
||||
panelBlack.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelWrite
|
||||
//
|
||||
panelWrite.BackColor = SystemColors.ButtonHighlight;
|
||||
panelWrite.Location = new Point(30, 40);
|
||||
panelWrite.Name = "panelWrite";
|
||||
panelWrite.Size = new Size(62, 58);
|
||||
panelWrite.TabIndex = 0;
|
||||
panelWrite.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// checkBoxTrailer
|
||||
//
|
||||
checkBoxTrailer.AutoSize = true;
|
||||
checkBoxTrailer.Location = new Point(48, 160);
|
||||
checkBoxTrailer.Name = "checkBoxTrailer";
|
||||
checkBoxTrailer.Size = new Size(72, 24);
|
||||
checkBoxTrailer.TabIndex = 4;
|
||||
checkBoxTrailer.Text = "Trailer";
|
||||
checkBoxTrailer.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
numericUpDownWeight.Location = new Point(133, 111);
|
||||
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
numericUpDownWeight.Size = new Size(77, 27);
|
||||
numericUpDownWeight.TabIndex = 3;
|
||||
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
numericUpDownSpeed.Location = new Point(133, 42);
|
||||
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
numericUpDownSpeed.Size = new Size(77, 27);
|
||||
numericUpDownSpeed.TabIndex = 2;
|
||||
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(48, 113);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(36, 20);
|
||||
label2.TabIndex = 1;
|
||||
label2.Text = "Вес:";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(48, 49);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(76, 20);
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Скорость:";
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
pictureBoxObject.Location = new Point(3, 67);
|
||||
pictureBoxObject.Name = "pictureBoxObject";
|
||||
pictureBoxObject.Size = new Size(357, 278);
|
||||
pictureBoxObject.TabIndex = 1;
|
||||
pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
panelObject.AllowDrop = true;
|
||||
panelObject.Controls.Add(labelAdditionalColor);
|
||||
panelObject.Controls.Add(labelBodyColor);
|
||||
panelObject.Controls.Add(pictureBoxObject);
|
||||
panelObject.Location = new Point(742, 37);
|
||||
panelObject.Name = "panelObject";
|
||||
panelObject.Size = new Size(363, 345);
|
||||
panelObject.TabIndex = 3;
|
||||
panelObject.DragDrop += PanelObject_DragDrop;
|
||||
panelObject.DragEnter += PanelObject_DragEnter;
|
||||
//
|
||||
// labelAdditionalColor
|
||||
//
|
||||
labelAdditionalColor.AllowDrop = true;
|
||||
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAdditionalColor.Location = new Point(211, 8);
|
||||
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||
labelAdditionalColor.Size = new Size(111, 56);
|
||||
labelAdditionalColor.TabIndex = 3;
|
||||
labelAdditionalColor.Text = "Доп Цвет";
|
||||
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelAdditionalColor.UseMnemonic = false;
|
||||
labelAdditionalColor.DragDrop += labelColor_DragDrop;
|
||||
labelAdditionalColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// labelBodyColor
|
||||
//
|
||||
labelBodyColor.AllowDrop = true;
|
||||
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelBodyColor.Location = new Point(42, 8);
|
||||
labelBodyColor.Name = "labelBodyColor";
|
||||
labelBodyColor.Size = new Size(100, 56);
|
||||
labelBodyColor.TabIndex = 2;
|
||||
labelBodyColor.Text = "Цвет";
|
||||
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelBodyColor.DragDrop += labelColor_DragDrop;
|
||||
labelBodyColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// buttonOk
|
||||
//
|
||||
buttonOk.Location = new Point(764, 388);
|
||||
buttonOk.Name = "buttonOk";
|
||||
buttonOk.Size = new Size(94, 29);
|
||||
buttonOk.TabIndex = 4;
|
||||
buttonOk.Text = "Добавить";
|
||||
buttonOk.UseVisualStyleBackColor = true;
|
||||
buttonOk.Click += buttonOk_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(993, 388);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 5;
|
||||
buttonCancel.Text = "Удалить";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormTruckConfig
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1132, 455);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonOk);
|
||||
Controls.Add(panelObject);
|
||||
Controls.Add(groupBoxConfig);
|
||||
Name = "FormTruckConfig";
|
||||
Text = "Создание объекта";
|
||||
groupBoxConfig.ResumeLayout(false);
|
||||
groupBoxConfig.PerformLayout();
|
||||
groupBoxColor.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
|
||||
panelObject.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxConfig;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
private CheckBox checkBoxTrailer;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private GroupBox groupBoxColor;
|
||||
private Panel panelWrite;
|
||||
private Panel panelBlue;
|
||||
private Panel panelLime;
|
||||
private Panel panelRed;
|
||||
private Panel panelOrange;
|
||||
private Panel panelBrown;
|
||||
private Panel panelYellow;
|
||||
private Panel panelBlack;
|
||||
private Label labelModifiedObject;
|
||||
private Label labelSimpleObject;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Panel panelObject;
|
||||
private Label labelAdditionalColor;
|
||||
private Label labelBodyColor;
|
||||
private Button buttonOk;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
@ -1,175 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.Generics;
|
||||
using DumpTruck.MovementStrategy;
|
||||
using DumpTruck.Entities;
|
||||
|
||||
namespace DumpTruck
|
||||
{
|
||||
public partial class FormTruckConfig : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Переменная-выбранная машина
|
||||
/// </summary>
|
||||
DrawningTruck? _truck = null;
|
||||
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event Action<DrawningTruck> EventAddTruck;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormTruckConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += panelColor_MouseDown;
|
||||
panelWrite.MouseDown += panelColor_MouseDown;
|
||||
panelBlue.MouseDown += panelColor_MouseDown;
|
||||
panelLime.MouseDown += panelColor_MouseDown;
|
||||
panelRed.MouseDown += panelColor_MouseDown;
|
||||
panelOrange.MouseDown += panelColor_MouseDown;
|
||||
panelYellow.MouseDown += panelColor_MouseDown;
|
||||
panelBrown.MouseDown += panelColor_MouseDown;
|
||||
|
||||
buttonCancel.Click += (sender, e) => Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Отрисовать машину
|
||||
/// </summary>
|
||||
private void DrawTruck()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_truck?.SetPosition(5, 5);
|
||||
_truck?.DrawTransport(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev">Привязанный метод</param>
|
||||
public void AddEvent(Action<DrawningTruck> ev)
|
||||
{
|
||||
if (EventAddTruck == null)
|
||||
{
|
||||
EventAddTruck = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddTruck += 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);
|
||||
}
|
||||
|
||||
private void panelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, 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;
|
||||
}
|
||||
}
|
||||
|
||||
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(typeof(Color)) ?? 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":
|
||||
_truck = new DrawningTruck((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
||||
pictureBoxObject.Height);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_truck = new DrawningDumpTruck((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||||
checkBoxTrailer.Checked, pictureBoxObject.Width,
|
||||
pictureBoxObject.Height);
|
||||
break;
|
||||
}
|
||||
DrawTruck();
|
||||
}
|
||||
|
||||
public void labelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_truck == null)
|
||||
return;
|
||||
|
||||
((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||
switch (((Label)sender).Name)
|
||||
{
|
||||
case "labelBodyColor":
|
||||
_truck.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
case "labelAdditionalColor":
|
||||
if (!(_truck is DrawningDumpTruck))
|
||||
{
|
||||
return;
|
||||
}
|
||||
(_truck as DrawningDumpTruck).SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
}
|
||||
DrawTruck();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление машины
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddTruck?.Invoke(_truck);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace DumpTruck.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);
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DumpTruck.DrawningObjects;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
{
|
||||
internal class MoveToBorder: AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DumpTruck.DrawningObjects;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
{
|
||||
internal class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.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;
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,3 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
namespace DumpTruck
|
||||
{
|
||||
internal static class Program
|
||||
@ -14,25 +9,9 @@ namespace DumpTruck
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider =
|
||||
services.BuildServiceProvider())
|
||||
{
|
||||
|
||||
Application.Run(serviceProvider.GetRequiredService<FormTruckCollection>());
|
||||
}
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormTruckCollection>()
|
||||
.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,122 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DumpTruck.Exceptions;
|
||||
|
||||
namespace DumpTruck.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?>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="truck">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T truck)
|
||||
{
|
||||
return Insert(truck, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="truck">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T truck, int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
if (position < 0 || position > Count)
|
||||
throw new TruckNotFoundException(position);
|
||||
if (Count >= _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
// Вставка по позиции
|
||||
_places.Insert(position, truck);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if ((position < 0) || (position > Count)) throw new TruckNotFoundException(position);
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <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 >= _maxCount || Count == _maxCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Вставка в список по позиции
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetTrucks(int? maxTrucks = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxTrucks.HasValue && i == maxTrucks.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class StorageOverflowException : ApplicationException
|
||||
{
|
||||
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: { count}") { }
|
||||
public StorageOverflowException() : base() { }
|
||||
public StorageOverflowException(string message) : base(message) { }
|
||||
public StorageOverflowException(string message, Exception exception)
|
||||
: base(message, exception) { }
|
||||
protected StorageOverflowException(SerializationInfo info,
|
||||
StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -1,166 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.Exceptions;
|
||||
using DumpTruck.Generics;
|
||||
using DumpTruck.MovementStrategy;
|
||||
|
||||
|
||||
namespace DumpTruck.Generics
|
||||
{
|
||||
internal class TrucksGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>> _truckStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _truckStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
/// </summary>
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char _separatorRecords = ';';
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// /// <param name="pictureHeight"></param>
|
||||
public TrucksGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_truckStorages = new Dictionary<string, TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для добавления
|
||||
_truckStorages.Add(name, new TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления
|
||||
if (_truckStorages.ContainsKey(name))
|
||||
_truckStorages.Remove(name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения набора
|
||||
if (_truckStorages.ContainsKey(ind))
|
||||
return _truckStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение информации по автомобилям в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string, TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>> record in _truckStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningTruck? elem in record.Value.GetTrucks)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException("Невалиданя операция, нет данных для сохранения");
|
||||
}
|
||||
using StreamWriter sw = new(filename);
|
||||
sw.Write($"TruckStorage{Environment.NewLine}{data}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка информации по автомобилям в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
string str = sr.ReadLine();
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
throw new NullReferenceException("Нет данных для загрузки");
|
||||
}
|
||||
if (!str.StartsWith("TruckStorage"))
|
||||
{
|
||||
throw new InvalidDataException("Неверный формат данных");
|
||||
}
|
||||
_truckStorages.Clear();
|
||||
while ((str = sr.ReadLine()) != null)
|
||||
{
|
||||
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TrucksGenericCollection<DrawningTruck, DrawningObjectTruck> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set.Reverse())
|
||||
{
|
||||
DrawningTruck? truck = elem?.CreateDrawningTruck(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (truck != null)
|
||||
{
|
||||
if (collection + truck == -1)
|
||||
{
|
||||
throw new ApplicationException("Ошибка добавления в коллекцию");
|
||||
}
|
||||
}
|
||||
}
|
||||
_truckStorages.Add(record[0], collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class TruckNotFoundException : ApplicationException
|
||||
{
|
||||
public TruckNotFoundException(int i) : base($"Не найден объект по позиции { i}") { }
|
||||
public TruckNotFoundException() : base() { }
|
||||
public TruckNotFoundException(string message) : base(message) { }
|
||||
public TruckNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected TruckNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DumpTruck.Generics
|
||||
{
|
||||
internal class TrucksGenericCollection<T, U>
|
||||
where T : DrawningTruck
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 140;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 100;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public TrucksGenericCollection(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 +(TrucksGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(TrucksGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <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 ShowTrucks()
|
||||
{
|
||||
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)
|
||||
//рамзеткa места
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, 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 width = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawningTruck? truck = _collection[i];
|
||||
if (truck == null)
|
||||
continue;
|
||||
truck.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight);
|
||||
truck.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetTrucks => _collection.GetTrucks();
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/log_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||
"Properties": {
|
||||
"Application": "ArmoredTransport"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" internalLogLevel="Info">
|
||||
<targets>
|
||||
<target xsi:type="File" name="tofile" fileName="log-
|
||||
${shortdate}.log" />
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/log_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||
"Properties": {
|
||||
"Application": "DumpTruck"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" internalLogLevel="Info">
|
||||
<targets>
|
||||
<target xsi:type="File" name="tofile" fileName="carlog-
|
||||
${shortdate}.log" />
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
2
test.txt
Normal file
2
test.txt
Normal file
@ -0,0 +1,2 @@
|
||||
TruckStorage
|
||||
test|100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:Lime;100:100:Blue:Black:True;100:100:White:Black:True;100:100:White:Black:False;100:100:White;
|
Loading…
Reference in New Issue
Block a user