Compare commits
39 Commits
Author | SHA1 | Date | |
---|---|---|---|
eaefd63d01 | |||
1a626daa2b | |||
26ffabe715 | |||
4c180b71cb | |||
ce1d47a44e | |||
ff8612fc91 | |||
c8545fdb07 | |||
fb1f7abf5c | |||
a1d6167007 | |||
94a7a2f2bc | |||
7d265f9eb0 | |||
18d078a97e | |||
127a678e28 | |||
db78391b7f | |||
c918183e43 | |||
a258fe0f84 | |||
15f09ac242 | |||
559876c90b | |||
0dfabf5f19 | |||
26e3503e00 | |||
0feb1800b4 | |||
a63bca3d27 | |||
275b551026 | |||
e5619197bc | |||
1f66a0689b | |||
c9b0d52c9f | |||
93037118d6 | |||
ebf367ef84 | |||
f75d1f1b7b | |||
dea236e608 | |||
144100d479 | |||
f7feca445e | |||
0245de20ce | |||
8e1ef84198 | |||
064b8e1188 | |||
5e1c2a5559 | |||
84a371c0cf | |||
5737b79408 | |||
1a57528049 |
78
ElectricLocomotive/ElectricLocomotive/AbstractStrategy.cs
Normal file
78
ElectricLocomotive/ElectricLocomotive/AbstractStrategy.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ElectricLocomotive;
|
||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.MovementStrategy
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
public Status GetStatus() { return _state; }
|
||||||
|
/// <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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
protected bool MoveLeft() => MoveTo(Direction.Left);
|
||||||
|
protected bool MoveRight() => MoveTo(Direction.Right);
|
||||||
|
protected bool MoveUp() => MoveTo(Direction.Up);
|
||||||
|
protected bool MoveDown() => MoveTo(Direction.Down);
|
||||||
|
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
/// <param name="directionType">Направление</param>
|
||||||
|
private bool MoveTo(Direction directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
ElectricLocomotive/ElectricLocomotive/Direction.cs
Normal file
16
ElectricLocomotive/ElectricLocomotive/Direction.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricLocomotive
|
||||||
|
{
|
||||||
|
public enum Direction
|
||||||
|
{
|
||||||
|
Up = 1,
|
||||||
|
Down = 2,
|
||||||
|
Left = 3,
|
||||||
|
Right = 4
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ElectricLocomotive;
|
||||||
|
using ProjectElectricLocomotive.Entities;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.DrawingObjects
|
||||||
|
{
|
||||||
|
public class DrawingElectricLocomotive : DrawingLocomotive
|
||||||
|
{
|
||||||
|
public DrawingElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph, bool compartment, int width, int height) : base(speed, weight, bodyColor, width, height, 80, 52)
|
||||||
|
{
|
||||||
|
if (EntityLocomotive != null)
|
||||||
|
{
|
||||||
|
EntityLocomotive = new EntityElectricLocomotive(speed, width, bodyColor, additionalColor, pantograph, compartment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityLocomotive is not EntityElectricLocomotive electricLocomotive)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush blackBrush = new SolidBrush(Color.Black);
|
||||||
|
Brush windows = new SolidBrush(Color.LightBlue);
|
||||||
|
Brush additionalBrush = new SolidBrush(electricLocomotive.AdditionalColor);
|
||||||
|
Brush bodyColor = new SolidBrush(electricLocomotive.BodyColor);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 40, _startPosY + 24, 25, 11);
|
||||||
|
if (electricLocomotive.Compartment)
|
||||||
|
g.FillPolygon(additionalBrush, new Point[]
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 61, _startPosY + 25),
|
||||||
|
new Point(_startPosX + 85, _startPosY + 25),
|
||||||
|
new Point(_startPosX + 85, _startPosY + 35),
|
||||||
|
new Point(_startPosX + 61, _startPosY + 35),
|
||||||
|
new Point(_startPosX + 61, _startPosY + 25),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (electricLocomotive.Pantograph)
|
||||||
|
{
|
||||||
|
g.FillRectangle(blackBrush, _startPosX + 30, _startPosY + 15, 20, 5);
|
||||||
|
g.DrawLine(pen, _startPosX + 30, _startPosY + 15, _startPosX + 50, _startPosY + 2);
|
||||||
|
g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 60, _startPosY + 2);
|
||||||
|
}
|
||||||
|
base.DrawTransport(g);
|
||||||
|
}
|
||||||
|
public void SetAdditionalColor(Color color)
|
||||||
|
{
|
||||||
|
(EntityLocomotive as EntityElectricLocomotive).SetAdditionalColor(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
175
ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs
Normal file
175
ElectricLocomotive/ElectricLocomotive/DrawingLocomotive.cs
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ElectricLocomotive;
|
||||||
|
using ProjectElectricLocomotive.Entities;
|
||||||
|
using ProjectElectricLocomotive.MovementStrategy;
|
||||||
|
using ProjectElectricLocomotive.Properties;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.DrawingObjects
|
||||||
|
{
|
||||||
|
public class DrawingLocomotive
|
||||||
|
{
|
||||||
|
public EntityLocomotive? EntityLocomotive { get; protected set; }
|
||||||
|
|
||||||
|
public int _pictureWidth;
|
||||||
|
public int _pictureHeight;
|
||||||
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
|
protected readonly int _locomWidth = 80;
|
||||||
|
protected readonly int _locomHeight = 52;
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
public int GetWidth => _locomWidth;
|
||||||
|
public int GetHeight => _locomHeight;
|
||||||
|
public DrawingLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
|
||||||
|
{
|
||||||
|
if (width < _locomWidth || heigth < _locomHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = heigth;
|
||||||
|
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
protected DrawingLocomotive(int speed, double weight, Color bodyColor, int width,
|
||||||
|
int height, int locomWidth, int locomHeight)
|
||||||
|
{
|
||||||
|
if (width < _locomWidth || height < _locomHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_locomWidth = locomWidth;
|
||||||
|
_locomHeight = locomHeight;
|
||||||
|
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (x < 0 || x + _locomWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
x = _pictureWidth - _locomWidth;
|
||||||
|
}
|
||||||
|
if (y < 0 || y + _locomHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
y = _pictureHeight - _locomHeight;
|
||||||
|
}
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
public void MoveTransport(Direction direction)
|
||||||
|
{
|
||||||
|
if (EntityLocomotive == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Direction.Left:
|
||||||
|
if (_startPosX - EntityLocomotive.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityLocomotive.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Direction.Up:
|
||||||
|
if (_startPosY - EntityLocomotive.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityLocomotive.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Direction.Right:
|
||||||
|
if (_startPosX + EntityLocomotive.Step + _locomWidth < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityLocomotive.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Direction.Down:
|
||||||
|
if (_startPosY + EntityLocomotive.Step + _locomHeight < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityLocomotive.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
if (EntityLocomotive == null) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush blackBrush = new SolidBrush(Color.Black);
|
||||||
|
Brush windows = new SolidBrush(Color.LightBlue);
|
||||||
|
Brush bodyColor = new SolidBrush(EntityLocomotive.BodyColor);
|
||||||
|
g.FillPolygon(bodyColor, new Point[]
|
||||||
|
{
|
||||||
|
new Point(_startPosX, _startPosY + 40),
|
||||||
|
new Point(_startPosX, _startPosY + 30),
|
||||||
|
new Point(_startPosX + 20, _startPosY + 20),
|
||||||
|
new Point(_startPosX + 70, _startPosY + 20),
|
||||||
|
new Point(_startPosX + 80, _startPosY + 20),
|
||||||
|
new Point(_startPosX + 80, _startPosY + 40),
|
||||||
|
new Point(_startPosX + 75, _startPosY + 45),
|
||||||
|
new Point(_startPosX + 5, _startPosY + 45),
|
||||||
|
new Point(_startPosX, _startPosY + 40),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawPolygon(pen, new Point[]
|
||||||
|
{
|
||||||
|
new Point(_startPosX, _startPosY + 40),
|
||||||
|
new Point(_startPosX, _startPosY + 30),
|
||||||
|
new Point(_startPosX + 20, _startPosY + 20),
|
||||||
|
new Point(_startPosX + 70, _startPosY + 20),
|
||||||
|
new Point(_startPosX + 80, _startPosY + 20),
|
||||||
|
new Point(_startPosX + 80, _startPosY + 40),
|
||||||
|
new Point(_startPosX + 75, _startPosY + 45),
|
||||||
|
new Point(_startPosX + 5, _startPosY + 45),
|
||||||
|
new Point(_startPosX, _startPosY + 40),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
g.FillEllipse(windows, _startPosX + 10, _startPosY + 24, 10, 10);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 10, _startPosY + 25, 10, 10);
|
||||||
|
|
||||||
|
g.FillRectangle(windows, _startPosX + 25, _startPosY + 25, 10, 5);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 25, _startPosY + 25, 10, 5);
|
||||||
|
|
||||||
|
|
||||||
|
g.FillEllipse(blackBrush, _startPosX + 10, _startPosY + 45, 10, 10);
|
||||||
|
g.FillEllipse(blackBrush, _startPosX + 25, _startPosY + 45, 10, 10);
|
||||||
|
|
||||||
|
g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 45, 10, 10);
|
||||||
|
g.FillEllipse(blackBrush, _startPosX + 65, _startPosY + 45, 10, 10);
|
||||||
|
}
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
public bool CanMove(Direction direction)
|
||||||
|
{
|
||||||
|
if (EntityLocomotive == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
Direction.Left => _startPosX - EntityLocomotive.Step > 0,
|
||||||
|
//вверх
|
||||||
|
Direction.Up => _startPosY - EntityLocomotive.Step > 0,
|
||||||
|
// вправо
|
||||||
|
Direction.Right => _startPosX + EntityLocomotive.Step < _pictureWidth,
|
||||||
|
//вниз
|
||||||
|
Direction.Down => _startPosY + EntityLocomotive.Step < _pictureHeight,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public IMoveableObject GetMoveableObject => new
|
||||||
|
DrawingObjectLocomotive(this);
|
||||||
|
public void SetBodyColor(Color color)
|
||||||
|
{
|
||||||
|
EntityLocomotive.SetBodyColor(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
|||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
using ElectricLocomotive;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.MovementStrategy
|
||||||
|
{
|
||||||
|
public class DrawingObjectLocomotive : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawingLocomotive? _drawingLocomotive = null;
|
||||||
|
|
||||||
|
public DrawingObjectLocomotive(DrawingLocomotive drawingLocomotive)
|
||||||
|
{
|
||||||
|
_drawingLocomotive = drawingLocomotive;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawingLocomotive == null || _drawingLocomotive.EntityLocomotive == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawingLocomotive.GetPosX,
|
||||||
|
_drawingLocomotive.GetPosY, _drawingLocomotive.GetWidth, _drawingLocomotive.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawingLocomotive?.EntityLocomotive?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(Direction direction) => _drawingLocomotive?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(Direction direction) => _drawingLocomotive?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>WinExe</OutputType>
|
|
||||||
<TargetFramework>net7.0-windows</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -0,0 +1,31 @@
|
|||||||
|
using ProjectElectricLocomotive.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.Entities
|
||||||
|
{
|
||||||
|
public class EntityElectricLocomotive : EntityLocomotive
|
||||||
|
{
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
public bool Pantograph { get; set; }
|
||||||
|
public bool Compartment { get; set; }
|
||||||
|
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="pantograph">Признак наличия токоприемника</param>
|
||||||
|
/// <param name="compartment">Признак наличия отсеков под электрические батареи</param>
|
||||||
|
public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph,
|
||||||
|
bool compartment) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
Pantograph = pantograph;
|
||||||
|
Compartment = compartment;
|
||||||
|
}
|
||||||
|
public void SetAdditionalColor(Color color)
|
||||||
|
{
|
||||||
|
AdditionalColor = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
Normal file
30
ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.Entities
|
||||||
|
{
|
||||||
|
public class EntityLocomotive
|
||||||
|
{
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
public Color BodyColor { get; protected set; }
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес локомотива</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public EntityLocomotive(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
public void SetBodyColor(Color color)
|
||||||
|
{
|
||||||
|
BodyColor = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs
Normal file
64
ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectElectricLocomotive.Entities;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.DrawingObjects
|
||||||
|
{
|
||||||
|
public static class ExtentionLocomotive
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из строки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">Строка с данными для создания объекта</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <param name="width">Ширина</param>
|
||||||
|
/// <param name="height">Высота</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
public static DrawingLocomotive? CreateDrawningLocomotive(this string info, char
|
||||||
|
separatorForObject, int width, int height)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawingLocomotive(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]), width, height);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawingElectricLocomotive(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]),
|
||||||
|
Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5]), width, height);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningCar">Сохраняемый объект</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <returns>Строка с данными по объекту</returns>
|
||||||
|
public static string GetDataForSave(this DrawingLocomotive drawningCar, char separatorForObject)
|
||||||
|
{
|
||||||
|
var loco = drawningCar.EntityLocomotive;
|
||||||
|
if (loco == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
var str =
|
||||||
|
$"{loco.Speed}{separatorForObject}{loco.Weight}{separatorForObject}{loco.BodyColor.Name}";
|
||||||
|
if (loco is not EntityElectricLocomotive electricLocomotive)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return
|
||||||
|
$"{str}{separatorForObject}{electricLocomotive.AdditionalColor.Name}{separatorForObject}{electricLocomotive.Pantograph}{separatorForObject}{electricLocomotive.Compartment}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,39 +0,0 @@
|
|||||||
namespace ElectricLocomotive
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form1";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace ElectricLocomotive
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
209
ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.Designer.cs
generated
Normal file
209
ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.Designer.cs
generated
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ElectricLocomotive
|
||||||
|
{
|
||||||
|
partial class FormElectricLocomotive
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
pictureBoxElectricLocomotive = new PictureBox();
|
||||||
|
buttonCreateElectricLocomotive = new Button();
|
||||||
|
buttonLeft = new Button();
|
||||||
|
buttonUp = new Button();
|
||||||
|
buttonRight = new Button();
|
||||||
|
buttonDown = new Button();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonCreateLocomotive = new Button();
|
||||||
|
buttonStep = new Button();
|
||||||
|
button1 = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxElectricLocomotive
|
||||||
|
//
|
||||||
|
pictureBoxElectricLocomotive.Cursor = Cursors.No;
|
||||||
|
pictureBoxElectricLocomotive.Dock = DockStyle.Fill;
|
||||||
|
pictureBoxElectricLocomotive.Enabled = false;
|
||||||
|
pictureBoxElectricLocomotive.Location = new Point(0, 0);
|
||||||
|
pictureBoxElectricLocomotive.Name = "pictureBoxElectricLocomotive";
|
||||||
|
pictureBoxElectricLocomotive.Size = new Size(847, 441);
|
||||||
|
pictureBoxElectricLocomotive.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
|
pictureBoxElectricLocomotive.TabIndex = 0;
|
||||||
|
pictureBoxElectricLocomotive.TabStop = false;
|
||||||
|
pictureBoxElectricLocomotive.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonCreateElectricLocomotive
|
||||||
|
//
|
||||||
|
buttonCreateElectricLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateElectricLocomotive.Font = new Font("Calibri", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
buttonCreateElectricLocomotive.Location = new Point(11, 365);
|
||||||
|
buttonCreateElectricLocomotive.Margin = new Padding(2);
|
||||||
|
buttonCreateElectricLocomotive.Name = "buttonCreateElectricLocomotive";
|
||||||
|
buttonCreateElectricLocomotive.Size = new Size(134, 64);
|
||||||
|
buttonCreateElectricLocomotive.TabIndex = 1;
|
||||||
|
buttonCreateElectricLocomotive.Text = "Создать электролокомотив";
|
||||||
|
buttonCreateElectricLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateElectricLocomotive.Click += buttonCreateElectricLocomotive_Click;
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonLeft.BackgroundImage = ProjectElectricLocomotive.Properties.Resources.free_icon_left_arrow_line_symbol_54321;
|
||||||
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonLeft.Location = new Point(733, 399);
|
||||||
|
buttonLeft.Margin = new Padding(2);
|
||||||
|
buttonLeft.Name = "buttonLeft";
|
||||||
|
buttonLeft.Size = new Size(30, 30);
|
||||||
|
buttonLeft.TabIndex = 2;
|
||||||
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonUp.BackgroundImage = ProjectElectricLocomotive.Properties.Resources.free_icon_up_arrow_angle_54817;
|
||||||
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonUp.Location = new Point(767, 365);
|
||||||
|
buttonUp.Margin = new Padding(2);
|
||||||
|
buttonUp.Name = "buttonUp";
|
||||||
|
buttonUp.Size = new Size(30, 30);
|
||||||
|
buttonUp.TabIndex = 3;
|
||||||
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRight.BackgroundImage = ProjectElectricLocomotive.Properties.Resources.free_icon_right_arrow_angle_54833;
|
||||||
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonRight.Location = new Point(802, 399);
|
||||||
|
buttonRight.Margin = new Padding(2);
|
||||||
|
buttonRight.Name = "buttonRight";
|
||||||
|
buttonRight.Size = new Size(30, 30);
|
||||||
|
buttonRight.TabIndex = 4;
|
||||||
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonDown.BackgroundImage = ProjectElectricLocomotive.Properties.Resources.free_icon_down_arrow_54785;
|
||||||
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonDown.Location = new Point(767, 399);
|
||||||
|
buttonDown.Margin = new Padding(2);
|
||||||
|
buttonDown.Name = "buttonDown";
|
||||||
|
buttonDown.Size = new Size(30, 30);
|
||||||
|
buttonDown.TabIndex = 5;
|
||||||
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightEdge" });
|
||||||
|
comboBoxStrategy.Location = new Point(681, 7);
|
||||||
|
comboBoxStrategy.Margin = new Padding(2);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(151, 23);
|
||||||
|
comboBoxStrategy.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// buttonCreateLocomotive
|
||||||
|
//
|
||||||
|
buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateLocomotive.Font = new Font("Calibri", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
buttonCreateLocomotive.Location = new Point(149, 365);
|
||||||
|
buttonCreateLocomotive.Margin = new Padding(2);
|
||||||
|
buttonCreateLocomotive.Name = "buttonCreateLocomotive";
|
||||||
|
buttonCreateLocomotive.Size = new Size(102, 65);
|
||||||
|
buttonCreateLocomotive.TabIndex = 7;
|
||||||
|
buttonCreateLocomotive.Text = "Создать локомотив";
|
||||||
|
buttonCreateLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateLocomotive.Click += buttonCreateLocomotive_Click;
|
||||||
|
//
|
||||||
|
// buttonStep
|
||||||
|
//
|
||||||
|
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
buttonStep.Font = new Font("Calibri", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
buttonStep.Location = new Point(744, 34);
|
||||||
|
buttonStep.Margin = new Padding(2);
|
||||||
|
buttonStep.Name = "buttonStep";
|
||||||
|
buttonStep.Size = new Size(88, 34);
|
||||||
|
buttonStep.TabIndex = 8;
|
||||||
|
buttonStep.Text = "Шаг";
|
||||||
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStep.Click += buttonStrategyStep_Click;
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
button1.Location = new Point(256, 365);
|
||||||
|
button1.Name = "button1";
|
||||||
|
button1.Size = new Size(206, 64);
|
||||||
|
button1.TabIndex = 9;
|
||||||
|
button1.Text = "Выбрать локомотив";
|
||||||
|
button1.UseVisualStyleBackColor = true;
|
||||||
|
button1.Click += ButtonSelectLocomotive_Click;
|
||||||
|
//
|
||||||
|
// FormElectricLocomotive
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(847, 441);
|
||||||
|
Controls.Add(button1);
|
||||||
|
Controls.Add(buttonStep);
|
||||||
|
Controls.Add(buttonCreateLocomotive);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
|
Controls.Add(buttonDown);
|
||||||
|
Controls.Add(buttonRight);
|
||||||
|
Controls.Add(buttonUp);
|
||||||
|
Controls.Add(buttonLeft);
|
||||||
|
Controls.Add(buttonCreateElectricLocomotive);
|
||||||
|
Controls.Add(pictureBoxElectricLocomotive);
|
||||||
|
Margin = new Padding(2);
|
||||||
|
Name = "FormElectricLocomotive";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "ElectricLocomotive";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxElectricLocomotive;
|
||||||
|
private Button buttonCreateElectricLocomotive;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonDown;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonCreateLocomotive;
|
||||||
|
private Button buttonStep;
|
||||||
|
private Button button1;
|
||||||
|
}
|
||||||
|
}
|
132
ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.cs
Normal file
132
ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.cs
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
using ProjectElectricLocomotive.MovementStrategy;
|
||||||
|
using ProjectElectricLocomotive;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ElectricLocomotive
|
||||||
|
|
||||||
|
{
|
||||||
|
public partial class FormElectricLocomotive : Form
|
||||||
|
{
|
||||||
|
private DrawingLocomotive? _drawingLocomotive;
|
||||||
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public DrawingLocomotive? SelectedLocomotive { get; private set; }
|
||||||
|
public FormElectricLocomotive()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
SelectedLocomotive = null;
|
||||||
|
}
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawingLocomotive == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawingLocomotive.DrawTransport(gr);
|
||||||
|
pictureBoxElectricLocomotive.Image = bmp;
|
||||||
|
}
|
||||||
|
private void buttonCreateElectricLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog colorDialog = new ColorDialog();
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = colorDialog.Color;
|
||||||
|
}
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = colorDialog.Color;
|
||||||
|
}
|
||||||
|
_drawingLocomotive = new DrawingElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||||
|
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||||
|
_drawingLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void buttonCreateLocomotive_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;
|
||||||
|
}
|
||||||
|
_drawingLocomotive = new DrawingLocomotive(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000), color,
|
||||||
|
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||||
|
_drawingLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
|
100));
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
}
|
||||||
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingLocomotive == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_drawingLocomotive.MoveTransport(Direction.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_drawingLocomotive.MoveTransport(Direction.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_drawingLocomotive.MoveTransport(Direction.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_drawingLocomotive.MoveTransport(Direction.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingLocomotive == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToRightEdge(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(new DrawingObjectLocomotive(_drawingLocomotive), pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedLocomotive = _drawingLocomotive;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
251
ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
generated
Normal file
251
ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
generated
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
namespace ProjectElectricLocomotive
|
||||||
|
{
|
||||||
|
partial class FormLocomotiveCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLocomotiveCollection));
|
||||||
|
groupBoxSets = new GroupBox();
|
||||||
|
textBoxSetName = new TextBox();
|
||||||
|
buttonDeleteSet = new Button();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
ButtonAddLocomotive = new Button();
|
||||||
|
buttonAddSet = new Button();
|
||||||
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
ButtonRefreshCollection = new Button();
|
||||||
|
ButtonRemoveLocomotive = new Button();
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
menuStrip = new MenuStrip();
|
||||||
|
файлToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
saveFileDialog = new SaveFileDialog();
|
||||||
|
openFileDialog = new OpenFileDialog();
|
||||||
|
groupBoxMenu = new GroupBox();
|
||||||
|
groupBoxSets.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
menuStrip.SuspendLayout();
|
||||||
|
groupBoxMenu.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxSets
|
||||||
|
//
|
||||||
|
groupBoxSets.Controls.Add(textBoxSetName);
|
||||||
|
groupBoxSets.Controls.Add(buttonDeleteSet);
|
||||||
|
groupBoxSets.Controls.Add(listBoxStorages);
|
||||||
|
groupBoxSets.Controls.Add(ButtonAddLocomotive);
|
||||||
|
groupBoxSets.Controls.Add(buttonAddSet);
|
||||||
|
groupBoxSets.Location = new Point(0, 22);
|
||||||
|
groupBoxSets.Name = "groupBoxSets";
|
||||||
|
groupBoxSets.Size = new Size(242, 314);
|
||||||
|
groupBoxSets.TabIndex = 5;
|
||||||
|
groupBoxSets.TabStop = false;
|
||||||
|
groupBoxSets.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// textBoxSetName
|
||||||
|
//
|
||||||
|
textBoxSetName.Location = new Point(6, 38);
|
||||||
|
textBoxSetName.Name = "textBoxSetName";
|
||||||
|
textBoxSetName.Size = new Size(226, 23);
|
||||||
|
textBoxSetName.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonDeleteSet
|
||||||
|
//
|
||||||
|
buttonDeleteSet.Location = new Point(6, 216);
|
||||||
|
buttonDeleteSet.Name = "buttonDeleteSet";
|
||||||
|
buttonDeleteSet.Size = new Size(226, 45);
|
||||||
|
buttonDeleteSet.TabIndex = 2;
|
||||||
|
buttonDeleteSet.Text = "Удалить набор";
|
||||||
|
buttonDeleteSet.UseVisualStyleBackColor = true;
|
||||||
|
buttonDeleteSet.Click += ButtonRemoveObject_Click;
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
listBoxStorages.FormattingEnabled = true;
|
||||||
|
listBoxStorages.ItemHeight = 15;
|
||||||
|
listBoxStorages.Location = new Point(6, 116);
|
||||||
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
|
listBoxStorages.Size = new Size(226, 94);
|
||||||
|
listBoxStorages.TabIndex = 1;
|
||||||
|
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// ButtonAddLocomotive
|
||||||
|
//
|
||||||
|
ButtonAddLocomotive.Location = new Point(6, 269);
|
||||||
|
ButtonAddLocomotive.Name = "ButtonAddLocomotive";
|
||||||
|
ButtonAddLocomotive.Size = new Size(226, 39);
|
||||||
|
ButtonAddLocomotive.TabIndex = 0;
|
||||||
|
ButtonAddLocomotive.Text = "Добавить локомотив";
|
||||||
|
ButtonAddLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddLocomotive.Click += buttonAddLocomotive_Click;
|
||||||
|
//
|
||||||
|
// buttonAddSet
|
||||||
|
//
|
||||||
|
buttonAddSet.Location = new Point(6, 67);
|
||||||
|
buttonAddSet.Name = "buttonAddSet";
|
||||||
|
buttonAddSet.Size = new Size(226, 34);
|
||||||
|
buttonAddSet.TabIndex = 0;
|
||||||
|
buttonAddSet.Text = "Добавить набор";
|
||||||
|
buttonAddSet.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddSet.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Location = new Point(6, 342);
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(226, 23);
|
||||||
|
maskedTextBoxNumber.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
ButtonRefreshCollection.Location = new Point(6, 440);
|
||||||
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
ButtonRefreshCollection.Size = new Size(230, 43);
|
||||||
|
ButtonRefreshCollection.TabIndex = 2;
|
||||||
|
ButtonRefreshCollection.Text = " Обновить коллекцию";
|
||||||
|
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// ButtonRemoveLocomotive
|
||||||
|
//
|
||||||
|
ButtonRemoveLocomotive.Location = new Point(6, 388);
|
||||||
|
ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
|
||||||
|
ButtonRemoveLocomotive.Size = new Size(230, 39);
|
||||||
|
ButtonRemoveLocomotive.TabIndex = 1;
|
||||||
|
ButtonRemoveLocomotive.Text = "Удалить локомотив";
|
||||||
|
ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveLocomotive.Click += buttonRemoveLocomotive_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(6, 24);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(655, 560);
|
||||||
|
pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
|
pictureBoxCollection.TabIndex = 1;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
menuStrip.BackColor = SystemColors.ButtonFace;
|
||||||
|
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||||
|
menuStrip.Location = new Point(0, 0);
|
||||||
|
menuStrip.Name = "menuStrip";
|
||||||
|
menuStrip.Size = new Size(909, 24);
|
||||||
|
menuStrip.TabIndex = 2;
|
||||||
|
menuStrip.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// файлToolStripMenuItem
|
||||||
|
//
|
||||||
|
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { LoadToolStripMenuItem, SaveToolStripMenuItem });
|
||||||
|
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||||
|
файлToolStripMenuItem.Size = new Size(48, 20);
|
||||||
|
файлToolStripMenuItem.Text = "&Файл";
|
||||||
|
//
|
||||||
|
// LoadToolStripMenuItem
|
||||||
|
//
|
||||||
|
LoadToolStripMenuItem.Image = (Image)resources.GetObject("LoadToolStripMenuItem.Image");
|
||||||
|
LoadToolStripMenuItem.ImageTransparentColor = Color.Magenta;
|
||||||
|
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||||
|
LoadToolStripMenuItem.Size = new Size(141, 22);
|
||||||
|
LoadToolStripMenuItem.Text = "Загрузка";
|
||||||
|
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// SaveToolStripMenuItem
|
||||||
|
//
|
||||||
|
SaveToolStripMenuItem.Image = (Image)resources.GetObject("SaveToolStripMenuItem.Image");
|
||||||
|
SaveToolStripMenuItem.ImageTransparentColor = Color.Magenta;
|
||||||
|
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
|
SaveToolStripMenuItem.Size = new Size(141, 22);
|
||||||
|
SaveToolStripMenuItem.Text = "Сохранение";
|
||||||
|
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
openFileDialog.FileName = "openFileDialog1";
|
||||||
|
//
|
||||||
|
// groupBoxMenu
|
||||||
|
//
|
||||||
|
groupBoxMenu.AutoSize = true;
|
||||||
|
groupBoxMenu.Controls.Add(maskedTextBoxNumber);
|
||||||
|
groupBoxMenu.Controls.Add(groupBoxSets);
|
||||||
|
groupBoxMenu.Controls.Add(ButtonRemoveLocomotive);
|
||||||
|
groupBoxMenu.Controls.Add(ButtonRefreshCollection);
|
||||||
|
groupBoxMenu.Dock = DockStyle.Right;
|
||||||
|
groupBoxMenu.Location = new Point(661, 24);
|
||||||
|
groupBoxMenu.Name = "groupBoxMenu";
|
||||||
|
groupBoxMenu.Size = new Size(248, 563);
|
||||||
|
groupBoxMenu.TabIndex = 6;
|
||||||
|
groupBoxMenu.TabStop = false;
|
||||||
|
groupBoxMenu.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// FormLocomotiveCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(909, 587);
|
||||||
|
Controls.Add(groupBoxMenu);
|
||||||
|
Controls.Add(menuStrip);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
MainMenuStrip = menuStrip;
|
||||||
|
Name = "FormLocomotiveCollection";
|
||||||
|
Text = "Набор локомотивов";
|
||||||
|
groupBoxSets.ResumeLayout(false);
|
||||||
|
groupBoxSets.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
menuStrip.ResumeLayout(false);
|
||||||
|
menuStrip.PerformLayout();
|
||||||
|
groupBoxMenu.ResumeLayout(false);
|
||||||
|
groupBoxMenu.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private Button ButtonAddLocomotive;
|
||||||
|
private Button ButtonRemoveLocomotive;
|
||||||
|
private Button ButtonRefreshCollection;
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private GroupBox groupBoxSets;
|
||||||
|
private Button buttonDeleteSet;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button buttonAddSet;
|
||||||
|
private TextBox textBoxSetName;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private ToolStripMenuItem файлToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||||
|
private GroupBox groupBoxMenu;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,199 @@
|
|||||||
|
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 ElectricLocomotive;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
using ProjectElectricLocomotive.Exceptions;
|
||||||
|
using ProjectElectricLocomotive.Generics;
|
||||||
|
using ProjectElectricLocomotive.MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive
|
||||||
|
{
|
||||||
|
public partial class FormLocomotiveCollection : Form
|
||||||
|
{
|
||||||
|
private readonly LocomotivesGenericStorage _storage;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
public FormLocomotiveCollection(ILogger<FormLocomotiveCollection> logger)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_storage = new LocomotivesGenericStorage(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 ButtonAddObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxSetName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не всё заполнено", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning("Неудачная попытка. Коллекция не добавлена, не все данные заполнены");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBoxSetName.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
|
||||||
|
_logger.LogInformation($"Добавлен набор: {textBoxSetName.Text}");
|
||||||
|
}
|
||||||
|
private void buttonAddLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var formLocomotiveConfig = new FormLocomotiveConfig();
|
||||||
|
formLocomotiveConfig.AddEvent(AddLocomotive);
|
||||||
|
formLocomotiveConfig.Show();
|
||||||
|
}
|
||||||
|
public void AddLocomotive(DrawingLocomotive loco)
|
||||||
|
{
|
||||||
|
loco._pictureWidth = pictureBoxCollection.Width;
|
||||||
|
loco._pictureHeight = pictureBoxCollection.Height;
|
||||||
|
|
||||||
|
if (listBoxStorages.SelectedIndex == -1) return;
|
||||||
|
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (obj + loco > -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = obj.ShowLocomotives();
|
||||||
|
_logger.LogInformation($"Добавлен объект {obj}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (StorageOverflowException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
_logger.LogWarning("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRemoveObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||||
|
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||||
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(name);
|
||||||
|
ReloadObjects();
|
||||||
|
_logger.LogInformation($"Набор '{name}' удален");
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Отмена удаления набора");
|
||||||
|
}
|
||||||
|
private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1) return;
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Отмена удаления объекта");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var removeObj = obj - pos;
|
||||||
|
if (removeObj != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
_logger.LogInformation($"Удален объект с позиции {pos}");
|
||||||
|
pictureBoxCollection.Image = obj.ShowLocomotives();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
_logger.LogWarning("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (LocomotiveNotFoundException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
_logger.LogWarning($"Не найден объект по позиции: {obj}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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.ShowLocomotives();
|
||||||
|
}
|
||||||
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowLocomotives();
|
||||||
|
}
|
||||||
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storage.SaveData(saveFileDialog.FileName);
|
||||||
|
_logger.LogInformation($"Данные загружены в файл {saveFileDialog.FileName}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogWarning($"Не удалось сохранить информацию в файл: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storage.LoadData(openFileDialog.FileName);
|
||||||
|
_logger.LogInformation($"Данные загружены из файла {openFileDialog.FileName}");
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogWarning($"Не удалось загрузить информацию из файла: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,153 @@
|
|||||||
|
<?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>19, 13</value>
|
||||||
|
</metadata>
|
||||||
|
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||||
|
<data name="LoadToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||||
|
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAFUSURBVDhPlZK9SgNBFIXnCcQnkLyA4CPkHayFdBY22mqj
|
||||||
|
paVlxCKCoBaClUQLESNRC4OE4EKQrAbcYBKy62Z/ynHOzUwcMzuyDhzYGc795tw7y2ZXFEVLSZI8p2la
|
||||||
|
kkf5lywO1vZr/MH54LkhwlgQKsZxvC4AfHHjjM+tHOaDiKIKiqDqk0s6rbUJoCDCsy3t5kJh+bJFZrZ8
|
||||||
|
YGhh9ZjgSIeUUgVZPgHot2HfGwbTNu4aTf75UuW+50wVhSMAKwRwugO6aevokYohfQbDzj1/vdj8pffb
|
||||||
|
PfJREpUAEPSOvXoFBdSFBIDgmxIgTr3lEkRPYZMOwDwYDtzrXToATPVp06B9QwB8o4YAipjVr02dqx0T
|
||||||
|
gOHMGm3qNc8nL6EAX33XMP2l8cj7mQEOvMaJYbKpWy/zMAzf6BVE9ADF6CnLnCXMCn8mAUSMEiCYwX/k
|
||||||
|
+/48Y4x9AwxhsnXBwZZBAAAAAElFTkSuQmCC
|
||||||
|
</value>
|
||||||
|
</data>
|
||||||
|
<data name="SaveToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||||
|
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABzSURBVDhPY/j69WvDt2/f/pODQXoZQIyYCfv+MwTPIQmD
|
||||||
|
9ID0gg3ApoAYjGHAh/cficLD2QBS8SA1AJufkTGyWtoagM5HFwdhmAEfkPMCukJkzcjiIAw24MuXLwbI
|
||||||
|
hqArRNaMLA7CYANAAGYISIA0/O0/AID67ECmnhNDAAAAAElFTkSuQmCC
|
||||||
|
</value>
|
||||||
|
</data>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>134, 11</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>269, 13</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>25</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
369
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
generated
Normal file
369
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
generated
Normal file
@ -0,0 +1,369 @@
|
|||||||
|
namespace ProjectElectricLocomotive
|
||||||
|
{
|
||||||
|
partial class FormLocomotiveConfig
|
||||||
|
{
|
||||||
|
/// <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();
|
||||||
|
checkBoxCompartment = new CheckBox();
|
||||||
|
labelAdvancedObject = new Label();
|
||||||
|
labelSimpleObject = new Label();
|
||||||
|
groupBoxColors = new GroupBox();
|
||||||
|
panelColorPurple = new Panel();
|
||||||
|
panelColorBlack = new Panel();
|
||||||
|
panelColorGray = new Panel();
|
||||||
|
panelColorWhite = new Panel();
|
||||||
|
panelColorYellow = new Panel();
|
||||||
|
panelColorBlue = new Panel();
|
||||||
|
panelColorGreen = new Panel();
|
||||||
|
panelColorRed = new Panel();
|
||||||
|
checkBoxPantograph = new CheckBox();
|
||||||
|
numericUpDownWeight = new NumericUpDown();
|
||||||
|
numericUpDownSpeed = new NumericUpDown();
|
||||||
|
labelWeight = new Label();
|
||||||
|
labelSpeed = new Label();
|
||||||
|
pictureBoxLoco = new PictureBox();
|
||||||
|
panelWithPictureBox = new Panel();
|
||||||
|
labelAdvancedColor = new Label();
|
||||||
|
labelSimpleColor = new Label();
|
||||||
|
buttonAddObject = new Button();
|
||||||
|
buttonCancelObject = new Button();
|
||||||
|
groupBoxConfig.SuspendLayout();
|
||||||
|
groupBoxColors.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxLoco).BeginInit();
|
||||||
|
panelWithPictureBox.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxConfig
|
||||||
|
//
|
||||||
|
groupBoxConfig.Controls.Add(checkBoxCompartment);
|
||||||
|
groupBoxConfig.Controls.Add(labelAdvancedObject);
|
||||||
|
groupBoxConfig.Controls.Add(labelSimpleObject);
|
||||||
|
groupBoxConfig.Controls.Add(groupBoxColors);
|
||||||
|
groupBoxConfig.Controls.Add(checkBoxPantograph);
|
||||||
|
groupBoxConfig.Controls.Add(numericUpDownWeight);
|
||||||
|
groupBoxConfig.Controls.Add(numericUpDownSpeed);
|
||||||
|
groupBoxConfig.Controls.Add(labelWeight);
|
||||||
|
groupBoxConfig.Controls.Add(labelSpeed);
|
||||||
|
groupBoxConfig.Location = new Point(2, 4);
|
||||||
|
groupBoxConfig.Name = "groupBoxConfig";
|
||||||
|
groupBoxConfig.Size = new Size(474, 255);
|
||||||
|
groupBoxConfig.TabIndex = 0;
|
||||||
|
groupBoxConfig.TabStop = false;
|
||||||
|
groupBoxConfig.Text = "Параметры";
|
||||||
|
//
|
||||||
|
// checkBoxCompartment
|
||||||
|
//
|
||||||
|
checkBoxCompartment.AutoSize = true;
|
||||||
|
checkBoxCompartment.Location = new Point(10, 149);
|
||||||
|
checkBoxCompartment.Name = "checkBoxCompartment";
|
||||||
|
checkBoxCompartment.Size = new Size(121, 19);
|
||||||
|
checkBoxCompartment.TabIndex = 10;
|
||||||
|
checkBoxCompartment.Text = "Наличие отсеков";
|
||||||
|
checkBoxCompartment.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// labelAdvancedObject
|
||||||
|
//
|
||||||
|
labelAdvancedObject.AllowDrop = true;
|
||||||
|
labelAdvancedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelAdvancedObject.Location = new Point(324, 175);
|
||||||
|
labelAdvancedObject.Name = "labelAdvancedObject";
|
||||||
|
labelAdvancedObject.Size = new Size(119, 51);
|
||||||
|
labelAdvancedObject.TabIndex = 9;
|
||||||
|
labelAdvancedObject.Text = "Продвинутый";
|
||||||
|
labelAdvancedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelAdvancedObject.MouseDown += LabelObject_MouseDown;
|
||||||
|
//
|
||||||
|
// labelSimpleObject
|
||||||
|
//
|
||||||
|
labelSimpleObject.AllowDrop = true;
|
||||||
|
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelSimpleObject.Location = new Point(181, 174);
|
||||||
|
labelSimpleObject.Name = "labelSimpleObject";
|
||||||
|
labelSimpleObject.Size = new Size(119, 51);
|
||||||
|
labelSimpleObject.TabIndex = 8;
|
||||||
|
labelSimpleObject.Text = "Простой";
|
||||||
|
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelSimpleObject.MouseDown += LabelObject_MouseDown;
|
||||||
|
//
|
||||||
|
// groupBoxColors
|
||||||
|
//
|
||||||
|
groupBoxColors.Controls.Add(panelColorPurple);
|
||||||
|
groupBoxColors.Controls.Add(panelColorBlack);
|
||||||
|
groupBoxColors.Controls.Add(panelColorGray);
|
||||||
|
groupBoxColors.Controls.Add(panelColorWhite);
|
||||||
|
groupBoxColors.Controls.Add(panelColorYellow);
|
||||||
|
groupBoxColors.Controls.Add(panelColorBlue);
|
||||||
|
groupBoxColors.Controls.Add(panelColorGreen);
|
||||||
|
groupBoxColors.Controls.Add(panelColorRed);
|
||||||
|
groupBoxColors.Location = new Point(181, 18);
|
||||||
|
groupBoxColors.Name = "groupBoxColors";
|
||||||
|
groupBoxColors.Size = new Size(287, 150);
|
||||||
|
groupBoxColors.TabIndex = 7;
|
||||||
|
groupBoxColors.TabStop = false;
|
||||||
|
groupBoxColors.Text = "Цвета";
|
||||||
|
//
|
||||||
|
// panelColorPurple
|
||||||
|
//
|
||||||
|
panelColorPurple.AllowDrop = true;
|
||||||
|
panelColorPurple.BackColor = Color.Purple;
|
||||||
|
panelColorPurple.Location = new Point(199, 84);
|
||||||
|
panelColorPurple.Name = "panelColorPurple";
|
||||||
|
panelColorPurple.Size = new Size(50, 50);
|
||||||
|
panelColorPurple.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// panelColorBlack
|
||||||
|
//
|
||||||
|
panelColorBlack.AllowDrop = true;
|
||||||
|
panelColorBlack.BackColor = Color.Black;
|
||||||
|
panelColorBlack.Location = new Point(143, 84);
|
||||||
|
panelColorBlack.Name = "panelColorBlack";
|
||||||
|
panelColorBlack.Size = new Size(50, 50);
|
||||||
|
panelColorBlack.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// panelColorGray
|
||||||
|
//
|
||||||
|
panelColorGray.AllowDrop = true;
|
||||||
|
panelColorGray.BackColor = Color.Silver;
|
||||||
|
panelColorGray.Location = new Point(87, 84);
|
||||||
|
panelColorGray.Name = "panelColorGray";
|
||||||
|
panelColorGray.Size = new Size(50, 50);
|
||||||
|
panelColorGray.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// panelColorWhite
|
||||||
|
//
|
||||||
|
panelColorWhite.AllowDrop = true;
|
||||||
|
panelColorWhite.BackColor = Color.White;
|
||||||
|
panelColorWhite.Location = new Point(31, 84);
|
||||||
|
panelColorWhite.Name = "panelColorWhite";
|
||||||
|
panelColorWhite.Size = new Size(50, 50);
|
||||||
|
panelColorWhite.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// panelColorYellow
|
||||||
|
//
|
||||||
|
panelColorYellow.AllowDrop = true;
|
||||||
|
panelColorYellow.BackColor = Color.Yellow;
|
||||||
|
panelColorYellow.Location = new Point(199, 28);
|
||||||
|
panelColorYellow.Name = "panelColorYellow";
|
||||||
|
panelColorYellow.Size = new Size(50, 50);
|
||||||
|
panelColorYellow.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// panelColorBlue
|
||||||
|
//
|
||||||
|
panelColorBlue.AllowDrop = true;
|
||||||
|
panelColorBlue.BackColor = Color.Blue;
|
||||||
|
panelColorBlue.Location = new Point(143, 28);
|
||||||
|
panelColorBlue.Name = "panelColorBlue";
|
||||||
|
panelColorBlue.Size = new Size(50, 50);
|
||||||
|
panelColorBlue.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// panelColorGreen
|
||||||
|
//
|
||||||
|
panelColorGreen.AllowDrop = true;
|
||||||
|
panelColorGreen.BackColor = Color.Green;
|
||||||
|
panelColorGreen.Location = new Point(87, 28);
|
||||||
|
panelColorGreen.Name = "panelColorGreen";
|
||||||
|
panelColorGreen.Size = new Size(50, 50);
|
||||||
|
panelColorGreen.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelColorRed
|
||||||
|
//
|
||||||
|
panelColorRed.AllowDrop = true;
|
||||||
|
panelColorRed.BackColor = Color.Red;
|
||||||
|
panelColorRed.Location = new Point(31, 28);
|
||||||
|
panelColorRed.Name = "panelColorRed";
|
||||||
|
panelColorRed.Size = new Size(50, 50);
|
||||||
|
panelColorRed.TabIndex = 0;
|
||||||
|
panelColorRed.MouseDown += PanelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// checkBoxPantograph
|
||||||
|
//
|
||||||
|
checkBoxPantograph.AutoSize = true;
|
||||||
|
checkBoxPantograph.Location = new Point(10, 124);
|
||||||
|
checkBoxPantograph.Name = "checkBoxPantograph";
|
||||||
|
checkBoxPantograph.Size = new Size(172, 19);
|
||||||
|
checkBoxPantograph.TabIndex = 4;
|
||||||
|
checkBoxPantograph.Text = "Наличие токоприемников";
|
||||||
|
checkBoxPantograph.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericUpDownWeight
|
||||||
|
//
|
||||||
|
numericUpDownWeight.Location = new Point(10, 95);
|
||||||
|
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(120, 23);
|
||||||
|
numericUpDownWeight.TabIndex = 3;
|
||||||
|
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// numericUpDownSpeed
|
||||||
|
//
|
||||||
|
numericUpDownSpeed.Location = new Point(10, 51);
|
||||||
|
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(120, 23);
|
||||||
|
numericUpDownSpeed.TabIndex = 2;
|
||||||
|
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// labelWeight
|
||||||
|
//
|
||||||
|
labelWeight.AutoSize = true;
|
||||||
|
labelWeight.Location = new Point(10, 77);
|
||||||
|
labelWeight.Name = "labelWeight";
|
||||||
|
labelWeight.Size = new Size(26, 15);
|
||||||
|
labelWeight.TabIndex = 1;
|
||||||
|
labelWeight.Text = "Вес";
|
||||||
|
//
|
||||||
|
// labelSpeed
|
||||||
|
//
|
||||||
|
labelSpeed.AutoSize = true;
|
||||||
|
labelSpeed.Location = new Point(10, 33);
|
||||||
|
labelSpeed.Name = "labelSpeed";
|
||||||
|
labelSpeed.Size = new Size(59, 15);
|
||||||
|
labelSpeed.TabIndex = 0;
|
||||||
|
labelSpeed.Text = "Скорость";
|
||||||
|
//
|
||||||
|
// pictureBoxLoco
|
||||||
|
//
|
||||||
|
pictureBoxLoco.Location = new Point(14, 38);
|
||||||
|
pictureBoxLoco.Name = "pictureBoxLoco";
|
||||||
|
pictureBoxLoco.Size = new Size(284, 147);
|
||||||
|
pictureBoxLoco.TabIndex = 1;
|
||||||
|
pictureBoxLoco.TabStop = false;
|
||||||
|
//
|
||||||
|
// panelWithPictureBox
|
||||||
|
//
|
||||||
|
panelWithPictureBox.AllowDrop = true;
|
||||||
|
panelWithPictureBox.Controls.Add(labelAdvancedColor);
|
||||||
|
panelWithPictureBox.Controls.Add(labelSimpleColor);
|
||||||
|
panelWithPictureBox.Controls.Add(pictureBoxLoco);
|
||||||
|
panelWithPictureBox.Location = new Point(482, 12);
|
||||||
|
panelWithPictureBox.Name = "panelWithPictureBox";
|
||||||
|
panelWithPictureBox.Size = new Size(316, 195);
|
||||||
|
panelWithPictureBox.TabIndex = 1;
|
||||||
|
panelWithPictureBox.DragDrop += PanelObject_DragDrop;
|
||||||
|
panelWithPictureBox.DragEnter += PanelObject_DragEnter;
|
||||||
|
//
|
||||||
|
// labelAdvancedColor
|
||||||
|
//
|
||||||
|
labelAdvancedColor.AllowDrop = true;
|
||||||
|
labelAdvancedColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelAdvancedColor.Location = new Point(159, 10);
|
||||||
|
labelAdvancedColor.Name = "labelAdvancedColor";
|
||||||
|
labelAdvancedColor.Size = new Size(139, 23);
|
||||||
|
labelAdvancedColor.TabIndex = 3;
|
||||||
|
labelAdvancedColor.Text = "Доп. Цвет";
|
||||||
|
labelAdvancedColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelAdvancedColor.DragDrop += LabelColor_DragDrop;
|
||||||
|
labelAdvancedColor.DragEnter += LabelColor_DragDrop;
|
||||||
|
//
|
||||||
|
// labelSimpleColor
|
||||||
|
//
|
||||||
|
labelSimpleColor.AllowDrop = true;
|
||||||
|
labelSimpleColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelSimpleColor.Location = new Point(14, 10);
|
||||||
|
labelSimpleColor.Name = "labelSimpleColor";
|
||||||
|
labelSimpleColor.Size = new Size(139, 23);
|
||||||
|
labelSimpleColor.TabIndex = 2;
|
||||||
|
labelSimpleColor.Text = "Цвет";
|
||||||
|
labelSimpleColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelSimpleColor.DragDrop += LabelColor_DragDrop;
|
||||||
|
labelSimpleColor.DragEnter += LabelColor_DragDrop;
|
||||||
|
//
|
||||||
|
// buttonAddObject
|
||||||
|
//
|
||||||
|
buttonAddObject.Location = new Point(496, 213);
|
||||||
|
buttonAddObject.Name = "buttonAddObject";
|
||||||
|
buttonAddObject.Size = new Size(139, 41);
|
||||||
|
buttonAddObject.TabIndex = 3;
|
||||||
|
buttonAddObject.Text = "Добавить";
|
||||||
|
buttonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddObject.Click += buttonAddObject_Click;
|
||||||
|
//
|
||||||
|
// buttonCancelObject
|
||||||
|
//
|
||||||
|
buttonCancelObject.Location = new Point(641, 213);
|
||||||
|
buttonCancelObject.Name = "buttonCancelObject";
|
||||||
|
buttonCancelObject.Size = new Size(139, 41);
|
||||||
|
buttonCancelObject.TabIndex = 4;
|
||||||
|
buttonCancelObject.Text = "Отмена";
|
||||||
|
buttonCancelObject.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormLocomotiveConfig
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 266);
|
||||||
|
Controls.Add(buttonCancelObject);
|
||||||
|
Controls.Add(buttonAddObject);
|
||||||
|
Controls.Add(panelWithPictureBox);
|
||||||
|
Controls.Add(groupBoxConfig);
|
||||||
|
Name = "FormLocomotiveConfig";
|
||||||
|
Text = "FormLocomotiveConfig";
|
||||||
|
groupBoxConfig.ResumeLayout(false);
|
||||||
|
groupBoxConfig.PerformLayout();
|
||||||
|
groupBoxColors.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxLoco).EndInit();
|
||||||
|
panelWithPictureBox.ResumeLayout(false);
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxConfig;
|
||||||
|
private Label labelWeight;
|
||||||
|
private Label labelSpeed;
|
||||||
|
private CheckBox checkBox3;
|
||||||
|
private CheckBox checkBox2;
|
||||||
|
private CheckBox checkBoxPantograph;
|
||||||
|
private NumericUpDown numericUpDownWeight;
|
||||||
|
private NumericUpDown numericUpDownSpeed;
|
||||||
|
private GroupBox groupBoxColors;
|
||||||
|
private Panel panelColorYellow;
|
||||||
|
private Panel panelColorBlue;
|
||||||
|
private Panel panelColorGreen;
|
||||||
|
private Panel panelColorRed;
|
||||||
|
private Panel panelColorPurple;
|
||||||
|
private Panel panelColorBlack;
|
||||||
|
private Panel panelColorGray;
|
||||||
|
private Panel panelColorWhite;
|
||||||
|
private Label labelAdvancedObject;
|
||||||
|
private Label labelSimpleObject;
|
||||||
|
private PictureBox pictureBoxLoco;
|
||||||
|
private Panel panelWithPictureBox;
|
||||||
|
private Label labelAdvancedColor;
|
||||||
|
private Label labelSimpleColor;
|
||||||
|
private Button buttonAddObject;
|
||||||
|
private Button buttonCancelObject;
|
||||||
|
private CheckBox checkBoxCompartment;
|
||||||
|
}
|
||||||
|
}
|
131
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs
Normal file
131
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
using Microsoft.VisualBasic.Devices;
|
||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
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 ProjectElectricLocomotive.Entities;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive
|
||||||
|
{
|
||||||
|
public partial class FormLocomotiveConfig : Form
|
||||||
|
{
|
||||||
|
DrawingLocomotive? _locomotive = null;
|
||||||
|
private event Action<DrawingLocomotive>? EventAddLocomotive;
|
||||||
|
|
||||||
|
public FormLocomotiveConfig()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
panelColorBlack.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelColorPurple.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelColorGray.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelColorGreen.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelColorRed.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelColorWhite.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelColorYellow.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelColorBlue.MouseDown += PanelColor_MouseDown;
|
||||||
|
|
||||||
|
buttonCancelObject.Click += (s, e) => Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
public void AddEvent(Action<DrawingLocomotive> ev)
|
||||||
|
{
|
||||||
|
if (EventAddLocomotive == null)
|
||||||
|
{
|
||||||
|
EventAddLocomotive = ev;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventAddLocomotive += ev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DrawLocomotive()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBoxLoco.Width, pictureBoxLoco.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_locomotive?.SetPosition(5, 5);
|
||||||
|
_locomotive?.DrawTransport(gr);
|
||||||
|
pictureBoxLoco.Image = bmp;
|
||||||
|
}
|
||||||
|
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||||
|
{
|
||||||
|
case "labelSimpleObject":
|
||||||
|
_locomotive = new DrawingLocomotive((int)numericUpDownSpeed.Value,
|
||||||
|
(int)numericUpDownWeight.Value, Color.White, pictureBoxLoco.Width,
|
||||||
|
pictureBoxLoco.Height);
|
||||||
|
break;
|
||||||
|
case "labelAdvancedObject":
|
||||||
|
_locomotive = new DrawingElectricLocomotive((int)numericUpDownSpeed.Value,
|
||||||
|
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxPantograph.Checked,
|
||||||
|
checkBoxCompartment.Checked, pictureBoxLoco.Width, pictureBoxLoco.Height);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawLocomotive();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonAddObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
EventAddLocomotive?.Invoke(_locomotive);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LabelColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_locomotive == null)
|
||||||
|
return;
|
||||||
|
switch (((Label)sender).Name)
|
||||||
|
{
|
||||||
|
case "labelSimpleColor":
|
||||||
|
_locomotive.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
break;
|
||||||
|
case "labelAdvancedColor":
|
||||||
|
if (!(_locomotive is DrawingElectricLocomotive))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
(_locomotive as DrawingElectricLocomotive).SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawLocomotive();
|
||||||
|
}
|
||||||
|
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if ((e.Data?.GetDataPresent(typeof(Color)) ?? false))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.resx
Normal file
120
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
||||||
|
</root>
|
22
ElectricLocomotive/ElectricLocomotive/IMoveableObject.cs
Normal file
22
ElectricLocomotive/ElectricLocomotive/IMoveableObject.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ElectricLocomotive;
|
||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
|
int GetStep { get; }
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
bool CheckCanMove(Direction direction);
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class LocomotiveNotFoundException : ApplicationException
|
||||||
|
{
|
||||||
|
public LocomotiveNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
public LocomotiveNotFoundException() : base() { }
|
||||||
|
public LocomotiveNotFoundException(string message) : base(message) { }
|
||||||
|
public LocomotiveNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected LocomotiveNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
using ProjectElectricLocomotive.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.Generics
|
||||||
|
{
|
||||||
|
internal class LocomotivesGenericCollection<T, U>
|
||||||
|
where T : DrawingLocomotive
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
private readonly int _placeSizeWidth = 200;
|
||||||
|
private readonly int _placeSizeHeight = 130;
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
public LocomotivesGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
public static int operator +(LocomotivesGenericCollection<T, U> collect, T? locomotive)
|
||||||
|
{
|
||||||
|
if (locomotive == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect._collection.Insert(locomotive);
|
||||||
|
}
|
||||||
|
public static T? operator -(LocomotivesGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection[pos];
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
public Bitmap ShowLocomotives()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||||
|
1; ++j)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||||
|
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||||
|
_placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||||
|
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int HLoco = _pictureHeight / _placeSizeHeight;
|
||||||
|
int Wloco = _pictureWidth / _placeSizeWidth;
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
T? type = _collection[i];
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
type.SetPosition(
|
||||||
|
(int)(i / HLoco * _placeSizeWidth),
|
||||||
|
(HLoco - 1) * _placeSizeHeight - (int)(i % HLoco * _placeSizeHeight)
|
||||||
|
);
|
||||||
|
type?.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объектов коллекции
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<T?> GetLocomotives => _collection.GetLocomotives();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,142 @@
|
|||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
using ProjectElectricLocomotive.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.Generics
|
||||||
|
{
|
||||||
|
internal class LocomotivesGenericStorage
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> _locomotivesStorage;
|
||||||
|
public List<string> Keys => _locomotivesStorage.Keys.ToList();
|
||||||
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
|
private readonly char _separatorRecords = ';';
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
|
||||||
|
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
public LocomotivesGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_locomotivesStorage = new Dictionary<string, LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
if (!_locomotivesStorage.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_locomotivesStorage.Add(name, new LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (_locomotivesStorage.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_locomotivesStorage.Remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>?
|
||||||
|
this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_locomotivesStorage.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _locomotivesStorage[ind];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<string, LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> record in _locomotivesStorage)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
foreach (DrawingLocomotive? elem in record.Value.GetLocomotives)
|
||||||
|
{
|
||||||
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
|
}
|
||||||
|
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||||
|
}
|
||||||
|
if (data.Length == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Нет данных для записи, ошибка");
|
||||||
|
}
|
||||||
|
using StreamWriter fs = new StreamWriter(filename);
|
||||||
|
{
|
||||||
|
fs.WriteLine($"LocomotiveStorage{Environment.NewLine}");
|
||||||
|
fs.WriteLine(data);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
public void LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Файл не найден");
|
||||||
|
}
|
||||||
|
|
||||||
|
using (StreamReader fs = File.OpenText(filename))
|
||||||
|
{
|
||||||
|
|
||||||
|
string str = fs.ReadLine();
|
||||||
|
|
||||||
|
if (str == null || str.Length == 0)
|
||||||
|
{
|
||||||
|
throw new IOException("Нет данных для загрузки");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!str.StartsWith("LocomotiveStorage"))
|
||||||
|
{
|
||||||
|
//если нет такой записи, то это не те данные
|
||||||
|
throw new FileFormatException("Неверный формат данных");
|
||||||
|
}
|
||||||
|
|
||||||
|
_locomotivesStorage.Clear();
|
||||||
|
string strs = "";
|
||||||
|
|
||||||
|
|
||||||
|
while ((strs = fs.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (strs == null)
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Нет данных для загрузки");
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (record.Length != 2)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (string elem in set)
|
||||||
|
{
|
||||||
|
DrawingLocomotive? loco = elem?.CreateDrawningLocomotive(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (loco != null)
|
||||||
|
{
|
||||||
|
if ((collection + loco) == -1) // for my realization it's -1, for eegov's realization it's boolean
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка добавления ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_locomotivesStorage.Add(record[0], collection);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
56
ElectricLocomotive/ElectricLocomotive/MoveToCenter.cs
Normal file
56
ElectricLocomotive/ElectricLocomotive/MoveToCenter.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
ElectricLocomotive/ElectricLocomotive/MoveToRightEdge.cs
Normal file
29
ElectricLocomotive/ElectricLocomotive/MoveToRightEdge.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToRightEdge : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null) return false;
|
||||||
|
|
||||||
|
return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null) return;
|
||||||
|
if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight();
|
||||||
|
if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
ElectricLocomotive/ElectricLocomotive/ObjectParameters.cs
Normal file
51
ElectricLocomotive/ElectricLocomotive/ObjectParameters.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.MovementStrategy
|
||||||
|
{
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int _x;
|
||||||
|
private readonly int _y;
|
||||||
|
private readonly int _width;
|
||||||
|
private readonly int _height;
|
||||||
|
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,17 +1,43 @@
|
|||||||
|
using ProjectElectricLocomotive;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
|
||||||
namespace ElectricLocomotive
|
namespace ElectricLocomotive
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// The main entry point for the application.
|
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
// 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();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new Form1());
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||||
|
{
|
||||||
|
Application.Run(serviceProvider.GetRequiredService<FormLocomotiveCollection>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<FormLocomotiveCollection>().AddLogging(option =>
|
||||||
|
{
|
||||||
|
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||||
|
string pathNeed = "";
|
||||||
|
for (int i = 0; i < path.Length - 3; i++)
|
||||||
|
{
|
||||||
|
pathNeed += path[i] + "\\";
|
||||||
|
}
|
||||||
|
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: $"{pathNeed}appSettings.json", optional: false, reloadOnChange: true).Build();
|
||||||
|
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddSerilog(logger);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
|
||||||
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Update="Properties\Resources.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
103
ElectricLocomotive/ElectricLocomotive/Properties/Resources.Designer.cs
generated
Normal file
103
ElectricLocomotive/ElectricLocomotive/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код создан программой.
|
||||||
|
// Исполняемая версия:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||||
|
// повторной генерации кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||||
|
/// </summary>
|
||||||
|
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||||
|
// с помощью такого средства, как ResGen или Visual Studio.
|
||||||
|
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||||
|
// с параметром /str или перестройте свой проект VS.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
internal class Resources {
|
||||||
|
|
||||||
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
|
internal Resources() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
|
get {
|
||||||
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectElectricLocomotive.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||||
|
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get {
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap free_icon_down_arrow_54785 {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("free-icon-down-arrow-54785", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap free_icon_left_arrow_line_symbol_54321 {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("free-icon-left-arrow-line-symbol-54321", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap free_icon_right_arrow_angle_54833 {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("free-icon-right-arrow-angle-54833", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap free_icon_up_arrow_angle_54817 {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("free-icon-up-arrow-angle-54817", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
133
ElectricLocomotive/ElectricLocomotive/Properties/Resources.resx
Normal file
133
ElectricLocomotive/ElectricLocomotive/Properties/Resources.resx
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
<?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>
|
||||||
|
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
|
<data name="free-icon-left-arrow-line-symbol-54321" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\free-icon-left-arrow-line-symbol-54321.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="free-icon-down-arrow-54785" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\free-icon-down-arrow-54785.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="free-icon-up-arrow-angle-54817" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\free-icon-up-arrow-angle-54817.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="free-icon-right-arrow-angle-54833" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\free-icon-right-arrow-angle-54833.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
85
ElectricLocomotive/ElectricLocomotive/SetGeneric.cs
Normal file
85
ElectricLocomotive/ElectricLocomotive/SetGeneric.cs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectElectricLocomotive.Exceptions;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.Generics
|
||||||
|
{
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
private readonly List<T?> _places;
|
||||||
|
|
||||||
|
public int Count => _places.Count;
|
||||||
|
|
||||||
|
/// Максимальное количество объектов в списке
|
||||||
|
private readonly int _maxCount;
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
public int Insert(T loco)
|
||||||
|
{
|
||||||
|
return Insert(loco, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T loco, int position)
|
||||||
|
{
|
||||||
|
if (_places.Count >= _maxCount)
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
|
||||||
|
if (position < 0 || position >= _maxCount)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
_places.Insert(position, loco);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Remove(int position)
|
||||||
|
{
|
||||||
|
if (position >= Count || position < 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
T? tmp = _places[position];
|
||||||
|
if (tmp == null)
|
||||||
|
throw new LocomotiveNotFoundException(position);
|
||||||
|
_places[position] = null;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count) return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count || Count == _maxCount) return;
|
||||||
|
_places.Insert(position, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по списку
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T?> GetLocomotives(int? maxLocos = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxLocos.HasValue && i == maxLocos.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
ElectricLocomotive/ElectricLocomotive/Status.cs
Normal file
16
ElectricLocomotive/ElectricLocomotive/Status.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive
|
||||||
|
{
|
||||||
|
[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) { }
|
||||||
|
}
|
||||||
|
}
|
20
ElectricLocomotive/ElectricLocomotive/appsettings.json
Normal file
20
ElectricLocomotive/ElectricLocomotive/appsettings.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"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": "Locomotives"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.7.34031.279
|
VisualStudioVersion = 17.7.34031.279
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectricLocomotive", "ElectricLocomotive\ElectricLocomotive.csproj", "{A7A62158-ECC2-48DA-81F7-565BB5CE1E0D}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectElectricLocomotive", "ElectricLocomotive\ProjectElectricLocomotive.csproj", "{A7A62158-ECC2-48DA-81F7-565BB5CE1E0D}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
Loading…
Reference in New Issue
Block a user