Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
f510c85dc4 | |||
c424860090 | |||
5d9ccfb1db | |||
665230d385 | |||
5510ce31d0 | |||
b4e17fa1f7 | |||
ae6e1074b8 | |||
4b59366b42 | |||
0c626b2cb3 | |||
d533dd8a04 | |||
9957a82e36 | |||
13a3089093 | |||
b9c1c9ca87 | |||
75635ecc48 | |||
7bb13c445e | |||
e4d9e2aed1 | |||
5836ed3278 | |||
a061d56fb9 | |||
42a4585ede | |||
9436161a1a | |||
5669b4e535 |
164
ProjectLocomotive/ProjectLocomotive/AbstractMap.cs
Normal file
164
ProjectLocomotive/ProjectLocomotive/AbstractMap.cs
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||||
|
{
|
||||||
|
private IDrawningObject _drawningObject = null;
|
||||||
|
protected int[,] _map = null;
|
||||||
|
protected int _width;
|
||||||
|
protected int _height;
|
||||||
|
protected float _size_x;
|
||||||
|
protected float _size_y;
|
||||||
|
protected readonly Random _random = new();
|
||||||
|
protected readonly int _freeRoad = 0;
|
||||||
|
protected readonly int _barrier = 1;
|
||||||
|
public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawningObject = drawningObject;
|
||||||
|
GenerateMap();
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
public bool CheckAround(float Left, float Right, float Top, float Bottom)
|
||||||
|
{
|
||||||
|
int startX = (int)(Left / _size_x);
|
||||||
|
int startY = (int)(Right / _size_y);
|
||||||
|
int endX = (int)(Top / _size_x);
|
||||||
|
int endY = (int)(Bottom / _size_y);
|
||||||
|
for (int i = startX; i <= endX; i++)
|
||||||
|
{
|
||||||
|
for (int j = startY; j <= endY; j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_drawningObject.MoveObject(direction);
|
||||||
|
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
|
||||||
|
|
||||||
|
if (CheckAround(Left, Right, Top, Bottom))
|
||||||
|
{
|
||||||
|
_drawningObject.MoveObject(MoveObjectBack(direction));
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
private Direction MoveObjectBack(Direction direction)
|
||||||
|
{
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Direction.Up:
|
||||||
|
return Direction.Down;
|
||||||
|
case Direction.Down:
|
||||||
|
return Direction.Up;
|
||||||
|
case Direction.Left:
|
||||||
|
return Direction.Right;
|
||||||
|
case Direction.Right:
|
||||||
|
return Direction.Left;
|
||||||
|
}
|
||||||
|
return Direction.None;
|
||||||
|
}
|
||||||
|
private bool SetObjectOnMap()
|
||||||
|
{
|
||||||
|
if (_drawningObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int x = _random.Next(0, 10);
|
||||||
|
int y = _random.Next(0, 10);
|
||||||
|
_drawningObject.SetObject(x, y, _width, _height);
|
||||||
|
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
|
||||||
|
if (!CheckAround(Left, Right, Top, Bottom)) return true;
|
||||||
|
float startX = Left;
|
||||||
|
float startY = Right;
|
||||||
|
float lengthX = Top - Left;
|
||||||
|
float lengthY = Bottom - Right;
|
||||||
|
while (CheckAround(startX, startY, startX + lengthX, startY + lengthY))
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
result = CheckAround(startX, startY, startX + lengthX, startY + lengthY);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
_drawningObject.SetObject((int)startX, (int)startY, _width, _height);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startX += _size_x;
|
||||||
|
}
|
||||||
|
} while (result);
|
||||||
|
startX = x;
|
||||||
|
startY += _size_y;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private Bitmap DrawMapWithObject()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_width, _height);
|
||||||
|
if (_drawningObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _freeRoad)
|
||||||
|
{
|
||||||
|
DrawRoadPart(gr, i, j);
|
||||||
|
}
|
||||||
|
else if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
DrawBarrierPart(gr, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_drawningObject.DrawningObject(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
protected abstract void GenerateMap();
|
||||||
|
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||||
|
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||||
|
public bool Equals(AbstractMap? other)
|
||||||
|
{
|
||||||
|
if (other == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (other == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_width != other._width) return false;
|
||||||
|
if (_height != other._height) return false;
|
||||||
|
if (_size_x != other._size_x) return false;
|
||||||
|
if (_size_y != other._size_y) return false;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] != other._map[i, j]) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,8 +6,9 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProjectLocomotive
|
namespace ProjectLocomotive
|
||||||
{
|
{
|
||||||
internal enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
|
None = 0,
|
||||||
Up = 1,
|
Up = 1,
|
||||||
Down = 2,
|
Down = 2,
|
||||||
Left = 3,
|
Left = 3,
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
internal class DrawningElectroLocomotive : DrawningLocomotive
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="electroLines">Признак наличия "рогов" для подключения</param>
|
||||||
|
/// <param name="electroBattery">Признак наличия отсека электро-батарей</param>
|
||||||
|
public DrawningElectroLocomotive(int speed, float weight, Color bodyColor, Color
|
||||||
|
dopColor, bool electroLines, bool electroBattery) :
|
||||||
|
base(speed, weight, bodyColor, 110, 60)
|
||||||
|
{
|
||||||
|
Locomotivе = new EntityElectricLocomotive(speed, weight, bodyColor, dopColor, electroLines,
|
||||||
|
electroBattery);
|
||||||
|
}
|
||||||
|
public void SetExtraColor(Color color)
|
||||||
|
{
|
||||||
|
var LocomotiveElectro = Locomotivе as EntityElectricLocomotive;
|
||||||
|
if (LocomotiveElectro is not null)
|
||||||
|
{
|
||||||
|
LocomotiveElectro = new EntityElectricLocomotive(LocomotiveElectro.Speed, LocomotiveElectro.Weight, LocomotiveElectro.BodyColor, color, LocomotiveElectro.ElectroLines, LocomotiveElectro.ElectroBattery);
|
||||||
|
Locomotivе = LocomotiveElectro;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Locomotivе is not EntityElectricLocomotive elLocc)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
if (elLocc.ElectroLines)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, _startPosX + 20, _startPosY, _startPosX + 5, _startPosY - 12);
|
||||||
|
g.DrawLine(pen, _startPosX + 20, _startPosY, _startPosX + 35, _startPosY - 12);
|
||||||
|
g.DrawLine(pen, _startPosX + 70, _startPosY, _startPosX + 55, _startPosY - 12);
|
||||||
|
g.DrawLine(pen, _startPosX + 70, _startPosY, _startPosX + 85, _startPosY - 12);
|
||||||
|
|
||||||
|
}
|
||||||
|
base.DrawTransport(g);
|
||||||
|
if (elLocc.ElectroBattery)
|
||||||
|
{
|
||||||
|
Brush dopBrush = new SolidBrush(elLocc.DopColor);
|
||||||
|
g.FillRectangle(dopBrush, _startPosX + 40, _startPosY + 25, 15, 5);
|
||||||
|
g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 25, 15, 5);
|
||||||
|
g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 25, 15, 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,20 +9,20 @@ namespace ProjectLocomotive
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class DrawningLocomotive
|
public class DrawningLocomotive
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityLocomotive Locomotivе { private set; get; }
|
public EntityLocomotive Locomotivе { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки локомотива
|
/// Левая координата отрисовки локомотива
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната отрисовки локомотива
|
/// Верхняя кооридната отрисовки локомотива
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -45,10 +45,36 @@ namespace ProjectLocomotive
|
|||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес локомотива</param>
|
/// <param name="weight">Вес локомотива</param>
|
||||||
/// <param name="bodyColor">Цвет кузова</param>
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public DrawningLocomotive(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Locomotivе = new EntityLocomotive();
|
Locomotivе = new EntityLocomotive(speed, weight, bodyColor);
|
||||||
Locomotivе.Init(speed, weight, bodyColor);
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="carWidth">Ширина отрисовки автомобиля</param>
|
||||||
|
/// <param name="carHeight">Высота отрисовки автомобиля</param>
|
||||||
|
protected DrawningLocomotive(int speed, float weight, Color bodyColor, int
|
||||||
|
carWidth, int carHeight) :
|
||||||
|
this(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
_LocWidth = carWidth;
|
||||||
|
_LocHeight = carHeight;
|
||||||
|
}
|
||||||
|
public void SetBaseColor(Color color)
|
||||||
|
{
|
||||||
|
if (Locomotivе is EntityElectricLocomotive)
|
||||||
|
{
|
||||||
|
Locomotivе = (EntityElectricLocomotive)Locomotivе;
|
||||||
|
if (Locomotivе is not null)
|
||||||
|
{
|
||||||
|
Locomotivе = new EntityElectricLocomotive(Locomotivе.Speed, Locomotivе.Weight, color, (Locomotivе as EntityElectricLocomotive).DopColor, (Locomotivе as EntityElectricLocomotive).ElectroLines, (Locomotivе as EntityElectricLocomotive).ElectroBattery);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции автомобиля
|
/// Установка позиции автомобиля
|
||||||
@ -119,7 +145,7 @@ namespace ProjectLocomotive
|
|||||||
/// Отрисовка автомобиля
|
/// Отрисовка автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
@ -128,7 +154,6 @@ namespace ProjectLocomotive
|
|||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
// кузов электролокомотива (верхняя часть)
|
// кузов электролокомотива (верхняя часть)
|
||||||
//g.DrawRectangle(pen, _startPosX - 1, _startPosY - 1, 80, 30);
|
|
||||||
g.DrawLine(pen, _startPosX + 7, _startPosY, _startPosX + 80, _startPosY);
|
g.DrawLine(pen, _startPosX + 7, _startPosY, _startPosX + 80, _startPosY);
|
||||||
g.DrawLine(pen, _startPosX + 80, _startPosY, _startPosX + 80, _startPosY + 15);
|
g.DrawLine(pen, _startPosX + 80, _startPosY, _startPosX + 80, _startPosY + 15);
|
||||||
g.DrawLine(pen, _startPosX + 80, _startPosY + 15, _startPosX + 2, _startPosY + 15);
|
g.DrawLine(pen, _startPosX + 80, _startPosY + 15, _startPosX + 2, _startPosY + 15);
|
||||||
@ -178,5 +203,9 @@ namespace ProjectLocomotive
|
|||||||
_startPosY = _pictureHeight.Value - _LocHeight;
|
_startPosY = _pictureHeight.Value - _LocHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return (_startPosX, _startPosY, _startPosX + _LocWidth, _startPosY + _LocHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
73
ProjectLocomotive/ProjectLocomotive/DrawningObject.cs
Normal file
73
ProjectLocomotive/ProjectLocomotive/DrawningObject.cs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
internal class DrawningObject : IDrawningObject
|
||||||
|
{
|
||||||
|
private DrawningLocomotive _loc = null;
|
||||||
|
public DrawningObject(DrawningLocomotive loc)
|
||||||
|
{
|
||||||
|
_loc = loc;
|
||||||
|
}
|
||||||
|
public float Step => _loc?.Locomotivе?.Step ?? 0;
|
||||||
|
|
||||||
|
public DrawningLocomotive GetLocomotive => _loc;
|
||||||
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return _loc?.GetCurrentPosition() ?? default;
|
||||||
|
}
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_loc?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
public void SetObject(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_loc.SetPosition(x, y, width, height);
|
||||||
|
}
|
||||||
|
public string getInfo() => _loc?.getDataForSave();
|
||||||
|
public static IDrawningObject Create(string data) => new DrawningObject(data.createDrawningLocomotive());
|
||||||
|
public bool Equals(IDrawningObject? other)
|
||||||
|
{
|
||||||
|
if (other == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var otherLocomotive = other as DrawningObject;
|
||||||
|
if (otherLocomotive == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var locomotive = _loc.Locomotivе;
|
||||||
|
var otherLocomotiveLocomotive = otherLocomotive._loc.Locomotivе;
|
||||||
|
if (locomotive.GetType().Name != otherLocomotiveLocomotive.GetType().Name) return false;
|
||||||
|
if (locomotive.Speed != otherLocomotiveLocomotive.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (locomotive.Weight != otherLocomotiveLocomotive.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (locomotive.BodyColor != otherLocomotiveLocomotive.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// проверка в случае продвинутого объекта
|
||||||
|
if (locomotive is EntityElectricLocomotive entityWarmlyLocomotive && otherLocomotiveLocomotive is EntityElectricLocomotive otherEntityWarmlyLocomotive)
|
||||||
|
{
|
||||||
|
if (entityWarmlyLocomotive.DopColor != otherEntityWarmlyLocomotive.DopColor) return false;
|
||||||
|
if (entityWarmlyLocomotive.ElectroLines != otherEntityWarmlyLocomotive.ElectroLines) return false;
|
||||||
|
if (entityWarmlyLocomotive.ElectroBattery != otherEntityWarmlyLocomotive.ElectroBattery) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
void IDrawningObject.DrawningObject(Graphics g)
|
||||||
|
{
|
||||||
|
_loc.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
public class EntityElectricLocomotive : EntityLocomotive
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color DopColor { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия "рогов" для подключения
|
||||||
|
/// </summary>
|
||||||
|
public bool ElectroLines { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия отсека электро-батарей
|
||||||
|
/// </summary>
|
||||||
|
public bool ElectroBattery { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="electroLines">Признак наличия "рогов" для подключения</param>
|
||||||
|
/// <param name="electroBattery">Признак наличия отсека электро-батарей</param>
|
||||||
|
public EntityElectricLocomotive(int speed, float weight, Color bodyColor, Color
|
||||||
|
dopColor, bool electroLines, bool electroBattery) :
|
||||||
|
base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
DopColor = dopColor;
|
||||||
|
ElectroLines = electroLines;
|
||||||
|
ElectroBattery = electroBattery;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProjectLocomotive
|
namespace ProjectLocomotive
|
||||||
{
|
{
|
||||||
internal class EntityLocomotive
|
public class EntityLocomotive
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Скорость
|
/// Скорость
|
||||||
@ -19,7 +19,7 @@ namespace ProjectLocomotive
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Цвет кузова
|
/// Цвет кузова
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг передвижения локомотива
|
/// Шаг передвижения локомотива
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -31,7 +31,7 @@ namespace ProjectLocomotive
|
|||||||
/// <param name="weight"></param>
|
/// <param name="weight"></param>
|
||||||
/// <param name="bodyColor"></param>
|
/// <param name="bodyColor"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public EntityLocomotive(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||||
|
47
ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs
Normal file
47
ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
internal static class ExtentionLocomotive
|
||||||
|
{
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
public static string getDataForSave(this DrawningLocomotive drawningLocomotive)
|
||||||
|
{
|
||||||
|
var locomotive = drawningLocomotive.Locomotivе;
|
||||||
|
var str = $"{locomotive.Speed}{_separatorForObject}{locomotive.Weight}{_separatorForObject}{locomotive.BodyColor.Name}";
|
||||||
|
if (locomotive is not EntityElectricLocomotive warmlyLocomotive)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return $"{str}{_separatorForObject}{warmlyLocomotive.DopColor.Name}{_separatorForObject}{warmlyLocomotive.ElectroLines}{_separatorForObject}{warmlyLocomotive.ElectroBattery}";
|
||||||
|
}
|
||||||
|
public static DrawningLocomotive createDrawningLocomotive(this string info)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(_separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawningLocomotive(
|
||||||
|
Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawningElectroLocomotive(
|
||||||
|
Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]),
|
||||||
|
Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,9 +19,7 @@
|
|||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
@ -38,6 +36,8 @@
|
|||||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
this.statusStrip = new System.Windows.Forms.StatusStrip();
|
this.statusStrip = new System.Windows.Forms.StatusStrip();
|
||||||
|
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSelectLocomotive = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
||||||
this.statusStrip.SuspendLayout();
|
this.statusStrip.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -88,19 +88,6 @@
|
|||||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
this.buttonLeft.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
|
this.buttonLeft.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
|
||||||
//
|
//
|
||||||
// buttonRight
|
|
||||||
//
|
|
||||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.buttonRight.BackgroundImage = global::ProjectLocomotive.Properties.Resources.right;
|
|
||||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
|
||||||
this.buttonRight.Location = new System.Drawing.Point(711, 375);
|
|
||||||
this.buttonRight.Name = "buttonRight";
|
|
||||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
|
||||||
this.buttonRight.TabIndex = 5;
|
|
||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
|
||||||
this.buttonRight.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
|
|
||||||
//
|
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
@ -114,6 +101,19 @@
|
|||||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
this.buttonDown.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
|
this.buttonDown.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
|
||||||
//
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonRight.BackgroundImage = global::ProjectLocomotive.Properties.Resources.right;
|
||||||
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonRight.Location = new System.Drawing.Point(711, 375);
|
||||||
|
this.buttonRight.Name = "buttonRight";
|
||||||
|
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonRight.TabIndex = 5;
|
||||||
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
this.buttonRight.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
|
||||||
|
//
|
||||||
// toolStripStatusLabelSpeed
|
// toolStripStatusLabelSpeed
|
||||||
//
|
//
|
||||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||||
@ -144,11 +144,33 @@
|
|||||||
this.statusStrip.Size = new System.Drawing.Size(800, 32);
|
this.statusStrip.Size = new System.Drawing.Size(800, 32);
|
||||||
this.statusStrip.TabIndex = 1;
|
this.statusStrip.TabIndex = 1;
|
||||||
//
|
//
|
||||||
|
// buttonCreateModif
|
||||||
|
//
|
||||||
|
this.buttonCreateModif.Location = new System.Drawing.Point(120, 375);
|
||||||
|
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||||
|
this.buttonCreateModif.Size = new System.Drawing.Size(138, 30);
|
||||||
|
this.buttonCreateModif.TabIndex = 7;
|
||||||
|
this.buttonCreateModif.Text = "Модификация";
|
||||||
|
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||||
|
//
|
||||||
|
// buttonSelectLocomotive
|
||||||
|
//
|
||||||
|
this.buttonSelectLocomotive.Location = new System.Drawing.Point(495, 370);
|
||||||
|
this.buttonSelectLocomotive.Name = "buttonSelectLocomotive";
|
||||||
|
this.buttonSelectLocomotive.Size = new System.Drawing.Size(104, 36);
|
||||||
|
this.buttonSelectLocomotive.TabIndex = 8;
|
||||||
|
this.buttonSelectLocomotive.Text = "Выбрать";
|
||||||
|
this.buttonSelectLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSelectLocomotive.Click += new System.EventHandler(this.buttonSelectLocomotive_Click);
|
||||||
|
//
|
||||||
// FormLocomotive
|
// FormLocomotive
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonSelectLocomotive);
|
||||||
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
@ -163,11 +185,8 @@
|
|||||||
this.statusStrip.PerformLayout();
|
this.statusStrip.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxLocomotive;
|
private PictureBox pictureBoxLocomotive;
|
||||||
private Button buttonCreate;
|
private Button buttonCreate;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
@ -178,5 +197,7 @@
|
|||||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||||
private StatusStrip statusStrip;
|
private StatusStrip statusStrip;
|
||||||
|
private Button buttonCreateModif;
|
||||||
|
private Button buttonSelectLocomotive;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,12 +3,14 @@ namespace ProjectLocomotive
|
|||||||
public partial class FormLocomotive : Form
|
public partial class FormLocomotive : Form
|
||||||
{
|
{
|
||||||
private DrawningLocomotive _elloc;
|
private DrawningLocomotive _elloc;
|
||||||
|
/// <summary>
|
||||||
|
/// Âűáđŕííűé îáúĺęň
|
||||||
|
/// </summary>
|
||||||
|
public DrawningLocomotive SelectedLocomotive { get; private set; }
|
||||||
public FormLocomotive()
|
public FormLocomotive()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ìåòîä ïðîðèñîâêè ýëåêòðîëîêîìîòèâà
|
/// Ìåòîä ïðîðèñîâêè ýëåêòðîëîêîìîòèâà
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -20,20 +22,33 @@ namespace ProjectLocomotive
|
|||||||
pictureBoxLocomotive.Image = bmp;
|
pictureBoxLocomotive.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
/// Ěĺňîä óńňŕíîâęč äŕííűő
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
private void SetData()
|
||||||
/// <param name="e"></param>
|
|
||||||
|
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_elloc = new DrawningLocomotive();
|
|
||||||
_elloc.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
||||||
_elloc.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
_elloc.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_elloc.Locomotivå.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_elloc.Locomotivå.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_elloc.Locomotivå.Weight}";
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_elloc.Locomotivå.Weight}";
|
||||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_elloc.Locomotivå.BodyColor.Name}";
|
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_elloc.Locomotivå.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Îáđŕáîňęŕ íŕćŕňč˙ ęíîďęč "Ńîçäŕňü"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_elloc = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||||
|
_elloc.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -72,5 +87,37 @@ namespace ProjectLocomotive
|
|||||||
_elloc?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
_elloc?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Îáđŕáîňęŕ íŕćŕňč˙ ęíîďęč "Ěîäčôčęŕöč˙"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialogDop = new();
|
||||||
|
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogDop.Color;
|
||||||
|
}
|
||||||
|
_elloc = new DrawningElectroLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
color,
|
||||||
|
dopColor,
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0, 1)));
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void buttonSelectLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedLocomotive = _elloc;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
391
ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs
generated
Normal file
391
ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs
generated
Normal file
@ -0,0 +1,391 @@
|
|||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
this.groupBoxConfig = new System.Windows.Forms.GroupBox();
|
||||||
|
this.labelModifiedObject = new System.Windows.Forms.Label();
|
||||||
|
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||||
|
this.groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||||
|
this.panelPurple = new System.Windows.Forms.Panel();
|
||||||
|
this.panelBlack = new System.Windows.Forms.Panel();
|
||||||
|
this.panelGray = new System.Windows.Forms.Panel();
|
||||||
|
this.panelWhite = new System.Windows.Forms.Panel();
|
||||||
|
this.panelYellow = new System.Windows.Forms.Panel();
|
||||||
|
this.panelGreen = new System.Windows.Forms.Panel();
|
||||||
|
this.panelBlue = new System.Windows.Forms.Panel();
|
||||||
|
this.panelRed = new System.Windows.Forms.Panel();
|
||||||
|
this.checkBoxFuelStorage = new System.Windows.Forms.CheckBox();
|
||||||
|
this.checkBoxPipe = new System.Windows.Forms.CheckBox();
|
||||||
|
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.labelWeight = new System.Windows.Forms.Label();
|
||||||
|
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.labelSpeed = new System.Windows.Forms.Label();
|
||||||
|
this.panelObject = new System.Windows.Forms.Panel();
|
||||||
|
this.labelDopColor = new System.Windows.Forms.Label();
|
||||||
|
this.labelBaseColor = new System.Windows.Forms.Label();
|
||||||
|
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.groupBoxConfig.SuspendLayout();
|
||||||
|
this.groupBoxColors.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||||
|
this.panelObject.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxConfig
|
||||||
|
//
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.checkBoxFuelStorage);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.checkBoxPipe);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelWeight);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelSpeed);
|
||||||
|
this.groupBoxConfig.Location = new System.Drawing.Point(15, 15);
|
||||||
|
this.groupBoxConfig.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.groupBoxConfig.Name = "groupBoxConfig";
|
||||||
|
this.groupBoxConfig.Padding = new System.Windows.Forms.Padding(4);
|
||||||
|
this.groupBoxConfig.Size = new System.Drawing.Size(566, 325);
|
||||||
|
this.groupBoxConfig.TabIndex = 0;
|
||||||
|
this.groupBoxConfig.TabStop = false;
|
||||||
|
this.groupBoxConfig.Text = "Конфигурация";
|
||||||
|
//
|
||||||
|
// labelModifiedObject
|
||||||
|
//
|
||||||
|
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelModifiedObject.Location = new System.Drawing.Point(390, 250);
|
||||||
|
this.labelModifiedObject.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||||
|
this.labelModifiedObject.Size = new System.Drawing.Size(143, 56);
|
||||||
|
this.labelModifiedObject.TabIndex = 8;
|
||||||
|
this.labelModifiedObject.Text = "Модифицированный";
|
||||||
|
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// labelSimpleObject
|
||||||
|
//
|
||||||
|
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelSimpleObject.Location = new System.Drawing.Point(224, 250);
|
||||||
|
this.labelSimpleObject.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||||
|
this.labelSimpleObject.Size = new System.Drawing.Size(143, 56);
|
||||||
|
this.labelSimpleObject.TabIndex = 7;
|
||||||
|
this.labelSimpleObject.Text = "Простой";
|
||||||
|
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// groupBoxColors
|
||||||
|
//
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelPurple);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelBlack);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelGray);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelWhite);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelYellow);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelBlue);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||||
|
this.groupBoxColors.Location = new System.Drawing.Point(224, 32);
|
||||||
|
this.groupBoxColors.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.groupBoxColors.Name = "groupBoxColors";
|
||||||
|
this.groupBoxColors.Padding = new System.Windows.Forms.Padding(4);
|
||||||
|
this.groupBoxColors.Size = new System.Drawing.Size(310, 195);
|
||||||
|
this.groupBoxColors.TabIndex = 6;
|
||||||
|
this.groupBoxColors.TabStop = false;
|
||||||
|
this.groupBoxColors.Text = "Цвета";
|
||||||
|
//
|
||||||
|
// panelPurple
|
||||||
|
//
|
||||||
|
this.panelPurple.BackColor = System.Drawing.Color.Fuchsia;
|
||||||
|
this.panelPurple.Location = new System.Drawing.Point(241, 128);
|
||||||
|
this.panelPurple.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.panelPurple.Name = "panelPurple";
|
||||||
|
this.panelPurple.Size = new System.Drawing.Size(54, 50);
|
||||||
|
this.panelPurple.TabIndex = 3;
|
||||||
|
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelBlack
|
||||||
|
//
|
||||||
|
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||||
|
this.panelBlack.Location = new System.Drawing.Point(165, 128);
|
||||||
|
this.panelBlack.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.panelBlack.Name = "panelBlack";
|
||||||
|
this.panelBlack.Size = new System.Drawing.Size(54, 50);
|
||||||
|
this.panelBlack.TabIndex = 2;
|
||||||
|
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelGray
|
||||||
|
//
|
||||||
|
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||||
|
this.panelGray.Location = new System.Drawing.Point(90, 128);
|
||||||
|
this.panelGray.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.panelGray.Name = "panelGray";
|
||||||
|
this.panelGray.Size = new System.Drawing.Size(54, 50);
|
||||||
|
this.panelGray.TabIndex = 3;
|
||||||
|
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelWhite
|
||||||
|
//
|
||||||
|
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||||
|
this.panelWhite.Location = new System.Drawing.Point(14, 128);
|
||||||
|
this.panelWhite.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.panelWhite.Name = "panelWhite";
|
||||||
|
this.panelWhite.Size = new System.Drawing.Size(54, 50);
|
||||||
|
this.panelWhite.TabIndex = 2;
|
||||||
|
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelYellow
|
||||||
|
//
|
||||||
|
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||||
|
this.panelYellow.Location = new System.Drawing.Point(241, 39);
|
||||||
|
this.panelYellow.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.panelYellow.Name = "panelYellow";
|
||||||
|
this.panelYellow.Size = new System.Drawing.Size(54, 50);
|
||||||
|
this.panelYellow.TabIndex = 1;
|
||||||
|
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelGreen
|
||||||
|
//
|
||||||
|
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
||||||
|
this.panelGreen.Location = new System.Drawing.Point(90, 39);
|
||||||
|
this.panelGreen.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.panelGreen.Name = "panelGreen";
|
||||||
|
this.panelGreen.Size = new System.Drawing.Size(54, 50);
|
||||||
|
this.panelGreen.TabIndex = 1;
|
||||||
|
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelBlue
|
||||||
|
//
|
||||||
|
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||||
|
this.panelBlue.Location = new System.Drawing.Point(166, 39);
|
||||||
|
this.panelBlue.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.panelBlue.Name = "panelBlue";
|
||||||
|
this.panelBlue.Size = new System.Drawing.Size(54, 50);
|
||||||
|
this.panelBlue.TabIndex = 1;
|
||||||
|
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// panelRed
|
||||||
|
//
|
||||||
|
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||||
|
this.panelRed.Location = new System.Drawing.Point(14, 39);
|
||||||
|
this.panelRed.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.panelRed.Name = "panelRed";
|
||||||
|
this.panelRed.Size = new System.Drawing.Size(54, 50);
|
||||||
|
this.panelRed.TabIndex = 0;
|
||||||
|
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||||
|
//
|
||||||
|
// checkBoxFuelStorage
|
||||||
|
//
|
||||||
|
this.checkBoxFuelStorage.AutoSize = true;
|
||||||
|
this.checkBoxFuelStorage.Location = new System.Drawing.Point(9, 198);
|
||||||
|
this.checkBoxFuelStorage.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.checkBoxFuelStorage.Name = "checkBoxFuelStorage";
|
||||||
|
this.checkBoxFuelStorage.Size = new System.Drawing.Size(207, 29);
|
||||||
|
this.checkBoxFuelStorage.TabIndex = 5;
|
||||||
|
this.checkBoxFuelStorage.Text = "Добавление батарей";
|
||||||
|
this.checkBoxFuelStorage.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxPipe
|
||||||
|
//
|
||||||
|
this.checkBoxPipe.AutoSize = true;
|
||||||
|
this.checkBoxPipe.Location = new System.Drawing.Point(9, 160);
|
||||||
|
this.checkBoxPipe.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.checkBoxPipe.Name = "checkBoxPipe";
|
||||||
|
this.checkBoxPipe.Size = new System.Drawing.Size(192, 29);
|
||||||
|
this.checkBoxPipe.TabIndex = 4;
|
||||||
|
this.checkBoxPipe.Text = "Добавление рогов";
|
||||||
|
this.checkBoxPipe.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericUpDownWeight
|
||||||
|
//
|
||||||
|
this.numericUpDownWeight.Location = new System.Drawing.Point(94, 94);
|
||||||
|
this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||||
|
this.numericUpDownWeight.Size = new System.Drawing.Size(85, 31);
|
||||||
|
this.numericUpDownWeight.TabIndex = 3;
|
||||||
|
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// labelWeight
|
||||||
|
//
|
||||||
|
this.labelWeight.AutoSize = true;
|
||||||
|
this.labelWeight.Location = new System.Drawing.Point(9, 96);
|
||||||
|
this.labelWeight.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.labelWeight.Name = "labelWeight";
|
||||||
|
this.labelWeight.Size = new System.Drawing.Size(48, 25);
|
||||||
|
this.labelWeight.TabIndex = 2;
|
||||||
|
this.labelWeight.Text = "Вес: ";
|
||||||
|
//
|
||||||
|
// numericUpDownSpeed
|
||||||
|
//
|
||||||
|
this.numericUpDownSpeed.Location = new System.Drawing.Point(92, 39);
|
||||||
|
this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||||
|
this.numericUpDownSpeed.Size = new System.Drawing.Size(86, 31);
|
||||||
|
this.numericUpDownSpeed.TabIndex = 1;
|
||||||
|
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// labelSpeed
|
||||||
|
//
|
||||||
|
this.labelSpeed.AutoSize = true;
|
||||||
|
this.labelSpeed.Location = new System.Drawing.Point(8, 41);
|
||||||
|
this.labelSpeed.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.labelSpeed.Name = "labelSpeed";
|
||||||
|
this.labelSpeed.Size = new System.Drawing.Size(98, 25);
|
||||||
|
this.labelSpeed.TabIndex = 0;
|
||||||
|
this.labelSpeed.Text = "Скорость: ";
|
||||||
|
//
|
||||||
|
// panelObject
|
||||||
|
//
|
||||||
|
this.panelObject.AllowDrop = true;
|
||||||
|
this.panelObject.Controls.Add(this.labelDopColor);
|
||||||
|
this.panelObject.Controls.Add(this.labelBaseColor);
|
||||||
|
this.panelObject.Controls.Add(this.pictureBoxObject);
|
||||||
|
this.panelObject.Location = new System.Drawing.Point(589, 28);
|
||||||
|
this.panelObject.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.panelObject.Name = "panelObject";
|
||||||
|
this.panelObject.Size = new System.Drawing.Size(524, 312);
|
||||||
|
this.panelObject.TabIndex = 1;
|
||||||
|
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
|
||||||
|
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter);
|
||||||
|
//
|
||||||
|
// labelDopColor
|
||||||
|
//
|
||||||
|
this.labelDopColor.AllowDrop = true;
|
||||||
|
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelDopColor.Location = new System.Drawing.Point(290, 20);
|
||||||
|
this.labelDopColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.labelDopColor.Name = "labelDopColor";
|
||||||
|
this.labelDopColor.Size = new System.Drawing.Size(143, 56);
|
||||||
|
this.labelDopColor.TabIndex = 9;
|
||||||
|
this.labelDopColor.Text = "Доп Цвет";
|
||||||
|
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelDopColor_DragDrop);
|
||||||
|
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||||
|
//
|
||||||
|
// labelBaseColor
|
||||||
|
//
|
||||||
|
this.labelBaseColor.AllowDrop = true;
|
||||||
|
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelBaseColor.Location = new System.Drawing.Point(86, 20);
|
||||||
|
this.labelBaseColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.labelBaseColor.Name = "labelBaseColor";
|
||||||
|
this.labelBaseColor.Size = new System.Drawing.Size(143, 56);
|
||||||
|
this.labelBaseColor.TabIndex = 8;
|
||||||
|
this.labelBaseColor.Text = "Базовый цвет";
|
||||||
|
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
|
||||||
|
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||||
|
//
|
||||||
|
// pictureBoxObject
|
||||||
|
//
|
||||||
|
this.pictureBoxObject.Location = new System.Drawing.Point(20, 84);
|
||||||
|
this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||||
|
this.pictureBoxObject.Size = new System.Drawing.Size(482, 210);
|
||||||
|
this.pictureBoxObject.TabIndex = 0;
|
||||||
|
this.pictureBoxObject.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(609, 348);
|
||||||
|
this.buttonAdd.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(210, 36);
|
||||||
|
this.buttonAdd.TabIndex = 2;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(879, 348);
|
||||||
|
this.buttonCancel.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(212, 36);
|
||||||
|
this.buttonCancel.TabIndex = 3;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormLocomotiveConfig
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(1128, 394);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.panelObject);
|
||||||
|
this.Controls.Add(this.groupBoxConfig);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.Name = "FormLocomotiveConfig";
|
||||||
|
this.Text = "Object Creation";
|
||||||
|
this.groupBoxConfig.ResumeLayout(false);
|
||||||
|
this.groupBoxConfig.PerformLayout();
|
||||||
|
this.groupBoxColors.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||||
|
this.panelObject.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
private GroupBox groupBoxConfig;
|
||||||
|
private NumericUpDown numericUpDownSpeed;
|
||||||
|
private Label labelSpeed;
|
||||||
|
private NumericUpDown numericUpDownWeight;
|
||||||
|
private Label labelWeight;
|
||||||
|
private CheckBox checkBoxFuelStorage;
|
||||||
|
private CheckBox checkBoxPipe;
|
||||||
|
private GroupBox groupBoxColors;
|
||||||
|
private Panel panelRed;
|
||||||
|
private Panel panelPurple;
|
||||||
|
private Panel panelBlack;
|
||||||
|
private Panel panelGray;
|
||||||
|
private Panel panelWhite;
|
||||||
|
private Panel panelYellow;
|
||||||
|
private Panel panelGreen;
|
||||||
|
private Panel panelBlue;
|
||||||
|
private Label labelSimpleObject;
|
||||||
|
private Label labelModifiedObject;
|
||||||
|
private Panel panelObject;
|
||||||
|
private PictureBox pictureBoxObject;
|
||||||
|
private Label labelDopColor;
|
||||||
|
private Label labelBaseColor;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
124
ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.cs
Normal file
124
ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.cs
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
public partial class FormLocomotiveConfig : Form
|
||||||
|
{
|
||||||
|
DrawningLocomotive _locomotive = null;
|
||||||
|
private event Action<DrawningLocomotive> eventAddLocomotive;
|
||||||
|
public void AddEvent(Action<DrawningLocomotive> ev)
|
||||||
|
{
|
||||||
|
if (eventAddLocomotive == null)
|
||||||
|
{
|
||||||
|
eventAddLocomotive = new Action<DrawningLocomotive>(ev);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eventAddLocomotive += ev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
eventAddLocomotive?.Invoke(_locomotive);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
public FormLocomotiveConfig()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelGray.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelRed.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||||
|
buttonCancel.Click += (object sender, EventArgs e) => Close();
|
||||||
|
}
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
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 DrawningLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
|
||||||
|
break;
|
||||||
|
case "labelModifiedObject":
|
||||||
|
_locomotive = new DrawningElectroLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
|
||||||
|
Color.White, Color.Black,
|
||||||
|
checkBoxPipe.Checked, checkBoxFuelStorage.Checked);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawLocomotive();
|
||||||
|
}
|
||||||
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
private void DrawLocomotive()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_locomotive?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
_locomotive?.DrawTransport(gr);
|
||||||
|
pictureBoxObject.Image = bmp;
|
||||||
|
}
|
||||||
|
private void labelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
// ! - TODO
|
||||||
|
if (_locomotive is DrawningElectroLocomotive)
|
||||||
|
{
|
||||||
|
var locomotive = _locomotive as DrawningElectroLocomotive;
|
||||||
|
locomotive.SetExtraColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
}
|
||||||
|
DrawLocomotive();
|
||||||
|
}
|
||||||
|
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LabelColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
var color = e.Data.GetData(typeof(Color));
|
||||||
|
if (color != null)
|
||||||
|
{
|
||||||
|
(sender as Label).BackColor = (Color)color;
|
||||||
|
}
|
||||||
|
DrawLocomotive();
|
||||||
|
if (_locomotive != null)
|
||||||
|
{
|
||||||
|
_locomotive.Locomotivе.BodyColor = (Color)color;
|
||||||
|
DrawLocomotive();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
370
ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs
generated
Normal file
370
ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs
generated
Normal file
@ -0,0 +1,370 @@
|
|||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
partial class FormMapWithSetLocomotives
|
||||||
|
{
|
||||||
|
/// <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.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||||
|
this.ButtonSortByColor = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonSortByType = new System.Windows.Forms.Button();
|
||||||
|
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||||
|
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||||
|
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
|
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||||
|
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRemoveLocomotive = new System.Windows.Forms.Button();
|
||||||
|
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.buttonAddLocomotive = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||||
|
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.loadFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||||
|
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||||
|
this.groupBoxTools.SuspendLayout();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.menuStrip.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
this.groupBoxTools.Controls.Add(this.ButtonSortByColor);
|
||||||
|
this.groupBoxTools.Controls.Add(this.ButtonSortByType);
|
||||||
|
this.groupBoxTools.Controls.Add(this.groupBox1);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonRemoveLocomotive);
|
||||||
|
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonAddLocomotive);
|
||||||
|
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
|
this.groupBoxTools.Location = new System.Drawing.Point(585, 33);
|
||||||
|
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.groupBoxTools.Name = "groupBoxTools";
|
||||||
|
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(4);
|
||||||
|
this.groupBoxTools.Size = new System.Drawing.Size(220, 481);
|
||||||
|
this.groupBoxTools.TabIndex = 0;
|
||||||
|
this.groupBoxTools.TabStop = false;
|
||||||
|
this.groupBoxTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// ButtonSortByColor
|
||||||
|
//
|
||||||
|
this.ButtonSortByColor.Location = new System.Drawing.Point(7, 524);
|
||||||
|
this.ButtonSortByColor.Name = "ButtonSortByColor";
|
||||||
|
this.ButtonSortByColor.Size = new System.Drawing.Size(207, 37);
|
||||||
|
this.ButtonSortByColor.TabIndex = 10;
|
||||||
|
this.ButtonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
this.ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||||
|
//
|
||||||
|
// ButtonSortByType
|
||||||
|
//
|
||||||
|
this.ButtonSortByType.Location = new System.Drawing.Point(6, 567);
|
||||||
|
this.ButtonSortByType.Name = "ButtonSortByType";
|
||||||
|
this.ButtonSortByType.Size = new System.Drawing.Size(207, 39);
|
||||||
|
this.ButtonSortByType.TabIndex = 9;
|
||||||
|
this.ButtonSortByType.Text = "Сортировка по типу";
|
||||||
|
this.ButtonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.buttonDeleteMap);
|
||||||
|
this.groupBox1.Controls.Add(this.listBoxMaps);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonAddMap);
|
||||||
|
this.groupBox1.Controls.Add(this.textBoxNewMapName);
|
||||||
|
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
|
||||||
|
this.groupBox1.Location = new System.Drawing.Point(6, 26);
|
||||||
|
this.groupBox1.Name = "groupBox1";
|
||||||
|
this.groupBox1.Size = new System.Drawing.Size(208, 250);
|
||||||
|
this.groupBox1.TabIndex = 8;
|
||||||
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "Карты";
|
||||||
|
//
|
||||||
|
// buttonDeleteMap
|
||||||
|
//
|
||||||
|
this.buttonDeleteMap.Location = new System.Drawing.Point(6, 198);
|
||||||
|
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||||
|
this.buttonDeleteMap.Size = new System.Drawing.Size(196, 34);
|
||||||
|
this.buttonDeleteMap.TabIndex = 3;
|
||||||
|
this.buttonDeleteMap.Text = "Удалить карту";
|
||||||
|
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
|
||||||
|
//
|
||||||
|
// listBoxMaps
|
||||||
|
//
|
||||||
|
this.listBoxMaps.FormattingEnabled = true;
|
||||||
|
this.listBoxMaps.ItemHeight = 25;
|
||||||
|
this.listBoxMaps.Location = new System.Drawing.Point(6, 128);
|
||||||
|
this.listBoxMaps.Name = "listBoxMaps";
|
||||||
|
this.listBoxMaps.Size = new System.Drawing.Size(196, 54);
|
||||||
|
this.listBoxMaps.TabIndex = 2;
|
||||||
|
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// buttonAddMap
|
||||||
|
//
|
||||||
|
this.buttonAddMap.Location = new System.Drawing.Point(6, 93);
|
||||||
|
this.buttonAddMap.Name = "buttonAddMap";
|
||||||
|
this.buttonAddMap.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.buttonAddMap.TabIndex = 1;
|
||||||
|
this.buttonAddMap.Text = "Добавить карту";
|
||||||
|
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
|
||||||
|
//
|
||||||
|
// textBoxNewMapName
|
||||||
|
//
|
||||||
|
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 26);
|
||||||
|
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||||
|
this.textBoxNewMapName.Size = new System.Drawing.Size(196, 31);
|
||||||
|
this.textBoxNewMapName.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// comboBoxSelectorMap
|
||||||
|
//
|
||||||
|
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
|
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||||
|
"Simple Map",
|
||||||
|
"Spike Map",
|
||||||
|
"Rail Map"});
|
||||||
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 59);
|
||||||
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(196, 33);
|
||||||
|
this.comboBoxSelectorMap.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
this.buttonLeft.BackgroundImage = global::ProjectLocomotive.Properties.Resources.left;
|
||||||
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonLeft.Location = new System.Drawing.Point(42, 661);
|
||||||
|
this.buttonLeft.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
|
this.buttonLeft.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.buttonLeft.TabIndex = 7;
|
||||||
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
this.buttonRight.BackgroundImage = global::ProjectLocomotive.Properties.Resources.right;
|
||||||
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonRight.Location = new System.Drawing.Point(157, 661);
|
||||||
|
this.buttonRight.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.buttonRight.Name = "buttonRight";
|
||||||
|
this.buttonRight.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.buttonRight.TabIndex = 7;
|
||||||
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
this.buttonDown.BackgroundImage = global::ProjectLocomotive.Properties.Resources.down;
|
||||||
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonDown.Location = new System.Drawing.Point(100, 661);
|
||||||
|
this.buttonDown.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.buttonDown.Name = "buttonDown";
|
||||||
|
this.buttonDown.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.buttonDown.TabIndex = 7;
|
||||||
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
this.buttonUp.BackgroundImage = global::ProjectLocomotive.Properties.Resources.up;
|
||||||
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonUp.Location = new System.Drawing.Point(100, 613);
|
||||||
|
this.buttonUp.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.buttonUp.Name = "buttonUp";
|
||||||
|
this.buttonUp.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.buttonUp.TabIndex = 6;
|
||||||
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonShowOnMap
|
||||||
|
//
|
||||||
|
this.buttonShowOnMap.Location = new System.Drawing.Point(0, 481);
|
||||||
|
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
|
this.buttonShowOnMap.Size = new System.Drawing.Size(220, 36);
|
||||||
|
this.buttonShowOnMap.TabIndex = 5;
|
||||||
|
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||||
|
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
|
||||||
|
//
|
||||||
|
// buttonShowStorage
|
||||||
|
//
|
||||||
|
this.buttonShowStorage.Location = new System.Drawing.Point(7, 410);
|
||||||
|
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
|
this.buttonShowStorage.Size = new System.Drawing.Size(208, 63);
|
||||||
|
this.buttonShowStorage.TabIndex = 4;
|
||||||
|
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||||
|
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
|
||||||
|
//
|
||||||
|
// buttonRemoveLocomotive
|
||||||
|
//
|
||||||
|
this.buttonRemoveLocomotive.Location = new System.Drawing.Point(7, 356);
|
||||||
|
this.buttonRemoveLocomotive.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
|
||||||
|
this.buttonRemoveLocomotive.Size = new System.Drawing.Size(207, 46);
|
||||||
|
this.buttonRemoveLocomotive.TabIndex = 3;
|
||||||
|
this.buttonRemoveLocomotive.Text = "Удалить локомотив";
|
||||||
|
this.buttonRemoveLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRemoveLocomotive.Click += new System.EventHandler(this.buttonRemoveLocomotive_Click);
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 317);
|
||||||
|
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
this.maskedTextBoxPosition.Size = new System.Drawing.Size(259, 31);
|
||||||
|
this.maskedTextBoxPosition.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// buttonAddLocomotive
|
||||||
|
//
|
||||||
|
this.buttonAddLocomotive.Location = new System.Drawing.Point(6, 282);
|
||||||
|
this.buttonAddLocomotive.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.buttonAddLocomotive.Name = "buttonAddLocomotive";
|
||||||
|
this.buttonAddLocomotive.Size = new System.Drawing.Size(208, 40);
|
||||||
|
this.buttonAddLocomotive.TabIndex = 1;
|
||||||
|
this.buttonAddLocomotive.Text = "Добавить локомотив";
|
||||||
|
this.buttonAddLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddLocomotive.Click += new System.EventHandler(this.buttonAddLocomotive_Click);
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pictureBox.Location = new System.Drawing.Point(0, 33);
|
||||||
|
this.pictureBox.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.pictureBox.Name = "pictureBox";
|
||||||
|
this.pictureBox.Size = new System.Drawing.Size(585, 481);
|
||||||
|
this.pictureBox.TabIndex = 1;
|
||||||
|
this.pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||||
|
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.fileToolStripMenuItem});
|
||||||
|
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.menuStrip.Name = "menuStrip";
|
||||||
|
this.menuStrip.Size = new System.Drawing.Size(805, 33);
|
||||||
|
this.menuStrip.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// fileToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.saveToolStripMenuItem,
|
||||||
|
this.loadToolStripMenuItem});
|
||||||
|
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||||
|
this.fileToolStripMenuItem.Size = new System.Drawing.Size(69, 29);
|
||||||
|
this.fileToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// saveToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||||
|
this.saveToolStripMenuItem.Size = new System.Drawing.Size(200, 34);
|
||||||
|
this.saveToolStripMenuItem.Text = "Сохранить";
|
||||||
|
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// loadToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||||
|
this.loadToolStripMenuItem.Size = new System.Drawing.Size(200, 34);
|
||||||
|
this.loadToolStripMenuItem.Text = "Загрузить";
|
||||||
|
this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// loadFileDialog
|
||||||
|
//
|
||||||
|
this.loadFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// FormMapWithSetLocomotives
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(805, 514);
|
||||||
|
this.Controls.Add(this.pictureBox);
|
||||||
|
this.Controls.Add(this.groupBoxTools);
|
||||||
|
this.Controls.Add(this.menuStrip);
|
||||||
|
this.MainMenuStrip = this.menuStrip;
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(4);
|
||||||
|
this.Name = "FormMapWithSetLocomotives";
|
||||||
|
this.Text = "Карта с набором объектов";
|
||||||
|
this.groupBoxTools.ResumeLayout(false);
|
||||||
|
this.groupBoxTools.PerformLayout();
|
||||||
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
this.groupBox1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.menuStrip.ResumeLayout(false);
|
||||||
|
this.menuStrip.PerformLayout();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private ComboBox comboBoxSelectorMap;
|
||||||
|
private Button buttonAddLocomotive;
|
||||||
|
private MaskedTextBox maskedTextBoxPosition;
|
||||||
|
private Button buttonRemoveLocomotive;
|
||||||
|
private Button buttonShowStorage;
|
||||||
|
private Button buttonShowOnMap;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private TextBox textBoxNewMapName;
|
||||||
|
private Button buttonAddMap;
|
||||||
|
private Button buttonDeleteMap;
|
||||||
|
private ListBox listBoxMaps;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem fileToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem saveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
|
private OpenFileDialog loadFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button ButtonSortByType;
|
||||||
|
private Button ButtonSortByColor;
|
||||||
|
}
|
||||||
|
}
|
276
ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs
Normal file
276
ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs
Normal file
@ -0,0 +1,276 @@
|
|||||||
|
using Locomotive;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
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;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
public partial class FormMapWithSetLocomotives : Form
|
||||||
|
{
|
||||||
|
///// Объект от класса карты с набором объектов
|
||||||
|
/// Словарь для выпадающего списка
|
||||||
|
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||||
|
{
|
||||||
|
{ "Simple Map", new SimpleMap() },
|
||||||
|
{ "Spike Map", new SpikeMap() },
|
||||||
|
{ "Rail Map", new RailroadMap() }
|
||||||
|
};
|
||||||
|
/// Объект от коллекции карт
|
||||||
|
private readonly MapsCollection _mapsCollection;
|
||||||
|
/// Логер
|
||||||
|
/// </summary>
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
public FormMapWithSetLocomotives(ILogger<FormMapWithSetLocomotives> logger)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||||
|
_logger = logger;
|
||||||
|
comboBoxSelectorMap.Items.Clear();
|
||||||
|
foreach (var elem in _mapsDict)
|
||||||
|
{
|
||||||
|
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
///// Выбор карты
|
||||||
|
/// Заполнение listBoxMaps
|
||||||
|
private void ReloadMaps()
|
||||||
|
{
|
||||||
|
int index = listBoxMaps.SelectedIndex;
|
||||||
|
listBoxMaps.Items.Clear();
|
||||||
|
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Добавление объекта
|
||||||
|
private void buttonAddLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var formCarConfig = new FormLocomotiveConfig();
|
||||||
|
formCarConfig.AddEvent(new(AddLocomotive));
|
||||||
|
formCarConfig.Show();
|
||||||
|
}
|
||||||
|
private void AddLocomotive(DrawningLocomotive locomotive)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Перед добавлением объекта необходимо создать карту");
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObject(locomotive) != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
_logger.LogInformation("Добавлен объект {@locomotive}", locomotive);
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
_logger.LogInformation("Не удалось добавить объект {@locomotive}", locomotive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(StorageOverflowException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
_logger.LogWarning("Ошибка переполнения хранилища: {0}", ex.Message);
|
||||||
|
MessageBox.Show($"Ошибка переполнения хранилища: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Ошибка добавления: {0}. Объект: {@Ship}", ex.Message, locomotive);
|
||||||
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Удаление объекта
|
||||||
|
private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var deletedLocomotive = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
|
||||||
|
if (deletedLocomotive != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удалён");
|
||||||
|
_logger.LogInformation("Из текущей карты удалён объект {@locomotive}", deletedLocomotive);
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Не удалось добавить объект по позиции {0} равен null", pos);
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (LocomotiveNotFoundException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Ошибка удаления: {0}", ex.Message);
|
||||||
|
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Вывод набора
|
||||||
|
private void buttonShowStorage_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image =
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
/// Вывод карты
|
||||||
|
private void buttonShowOnMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image =
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||||
|
}
|
||||||
|
/// Перемещение
|
||||||
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//получаем имя кнопки
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
Direction dir = Direction.None;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
dir = Direction.Up;
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
dir = Direction.Down;
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
dir = Direction.Left;
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
dir = Direction.Right;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||||
|
}
|
||||||
|
/// Удаление карты
|
||||||
|
private void buttonDeleteMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
|
_logger.LogInformation("Удалена карта {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Выбор карты
|
||||||
|
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
_logger.LogInformation("Был осуществлен переход на карту под названием: {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
|
}
|
||||||
|
/// Добавление карты
|
||||||
|
private void buttonAddMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogInformation("При добавлении карты {0}", comboBoxSelectorMap.SelectedIndex == -1 ? "Не была выбрана карта" : "Не была названа карта");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning("Нет карты с названием: {0}", textBoxNewMapName.Text);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||||
|
ReloadMaps();
|
||||||
|
_logger.LogInformation("Добавлена карта {0}", textBoxNewMapName.Text);
|
||||||
|
}
|
||||||
|
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||||
|
_logger.LogInformation("Сохранение прошло успешно. Файл находится: {0}", saveFileDialog.FileName);
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning("Не удалось сохранить файл '{0}'. Текст ошибки: {1}", saveFileDialog.FileName, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (loadFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_mapsCollection.LoadData(loadFileDialog.FileName);
|
||||||
|
MessageBox.Show("Открытие прошло успешно", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogInformation("Открытие файла '{0}' прошло успешно", loadFileDialog.FileName);
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Не удалось открыть: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning("Не удалось открыть файл {0}. Текст ошибки: {1}", loadFileDialog.FileName, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new LocomotiveCompareByType());
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new LocomotiveCompareByColor());
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="loadFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>163, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>341, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
46
ProjectLocomotive/ProjectLocomotive/IDrawningObject.cs
Normal file
46
ProjectLocomotive/ProjectLocomotive/IDrawningObject.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||||
|
/// </summary>
|
||||||
|
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения объекта
|
||||||
|
/// </summary>
|
||||||
|
public float Step { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Установка позиции объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
/// <param name="width">Ширина полотна</param>
|
||||||
|
/// <param name="height">Высота полотна</param>
|
||||||
|
void SetObject(int x, int y, int width, int height);
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления пермещения объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
/// <summary>
|
||||||
|
/// Отрисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
void DrawningObject(Graphics g);
|
||||||
|
/// <summary>
|
||||||
|
/// Получение текущей позиции объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||||
|
// Получение информации по объекту
|
||||||
|
string getInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,78 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
internal class LocomotiveCompareByColor : IComparer<IDrawningObject>
|
||||||
|
{
|
||||||
|
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||||
|
{
|
||||||
|
if (x == null && y == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (x == null && y != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (x != null && y == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var xLocomotive = x as DrawningObject;
|
||||||
|
var yLocomotive = y as DrawningObject;
|
||||||
|
if (xLocomotive == null && yLocomotive == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (xLocomotive == null && yLocomotive != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (xLocomotive != null && yLocomotive == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xLocomotive.GetLocomotive.Locomotivе.BodyColor.R.CompareTo(yLocomotive.GetLocomotive.Locomotivе.BodyColor.R) != 0)
|
||||||
|
{
|
||||||
|
return xLocomotive.GetLocomotive.Locomotivе.BodyColor.R.CompareTo(yLocomotive.GetLocomotive.Locomotivе.BodyColor.R);
|
||||||
|
}
|
||||||
|
if (xLocomotive.GetLocomotive.Locomotivе.BodyColor.G.CompareTo(yLocomotive.GetLocomotive.Locomotivе.BodyColor.G) != 0)
|
||||||
|
{
|
||||||
|
return xLocomotive.GetLocomotive.Locomotivе.BodyColor.G.CompareTo(yLocomotive.GetLocomotive.Locomotivе.BodyColor.G);
|
||||||
|
}
|
||||||
|
if (xLocomotive.GetLocomotive.Locomotivе.BodyColor.B.CompareTo(yLocomotive.GetLocomotive.Locomotivе.BodyColor.B) != 0)
|
||||||
|
{
|
||||||
|
return xLocomotive.GetLocomotive.Locomotivе.BodyColor.B.CompareTo(yLocomotive.GetLocomotive.Locomotivе.BodyColor.B);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xLocomotive.GetLocomotive.Locomotivе is EntityElectricLocomotive xWarmlyEntity && yLocomotive.GetLocomotive.Locomotivе is EntityElectricLocomotive yWarmlyEntity)
|
||||||
|
{
|
||||||
|
if (xWarmlyEntity.DopColor.R.CompareTo(yWarmlyEntity.DopColor.R) != 0)
|
||||||
|
{
|
||||||
|
return xWarmlyEntity.DopColor.R.CompareTo(yWarmlyEntity.DopColor.R);
|
||||||
|
}
|
||||||
|
if (xWarmlyEntity.DopColor.G.CompareTo(yWarmlyEntity.DopColor.G) != 0)
|
||||||
|
{
|
||||||
|
return xWarmlyEntity.DopColor.G.CompareTo(yWarmlyEntity.DopColor.G);
|
||||||
|
}
|
||||||
|
if (xWarmlyEntity.DopColor.B.CompareTo(yWarmlyEntity.DopColor.B) != 0)
|
||||||
|
{
|
||||||
|
return xWarmlyEntity.DopColor.B.CompareTo(yWarmlyEntity.DopColor.B);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var speedCompare = xLocomotive.GetLocomotive.Locomotivе.Speed.CompareTo(yLocomotive.GetLocomotive.Locomotivе.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return xLocomotive.GetLocomotive.Locomotivе.Weight.CompareTo(yLocomotive.GetLocomotive.Locomotivе.Weight);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
internal class LocomotiveCompareByType : IComparer<IDrawningObject>
|
||||||
|
{
|
||||||
|
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||||
|
{
|
||||||
|
if (x == null && y == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (x == null && y != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (x != null && y == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var xLocomotive = x as DrawningObject;
|
||||||
|
var yLocomotive = y as DrawningObject;
|
||||||
|
if (xLocomotive == null && yLocomotive == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (xLocomotive == null && yLocomotive != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (xLocomotive != null && yLocomotive == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (xLocomotive.GetLocomotive.GetType().Name != yLocomotive.GetLocomotive.GetType().Name)
|
||||||
|
{
|
||||||
|
if (xLocomotive.GetLocomotive.GetType().Name == "DrawningLocomotive")
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
var speedCompare = xLocomotive.GetLocomotive.Locomotivе.Speed.CompareTo(yLocomotive.GetLocomotive.Locomotivе.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return xLocomotive.GetLocomotive.Locomotivе.Weight.CompareTo(yLocomotive.GetLocomotive.Locomotivе.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
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 context) : base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,173 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
internal class MapWithSetLocomotivesGeneric<T, U>
|
||||||
|
where T : class, IDrawningObject, IEquatable<T>
|
||||||
|
where U : AbstractMap
|
||||||
|
{
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
private readonly int _placeSizeWidth = 210;
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
/// Набор объектов
|
||||||
|
private readonly SetLocomotivesGeneric<T> _setLocomotives;
|
||||||
|
/// Карта
|
||||||
|
private readonly U _map;
|
||||||
|
/// Конструктор
|
||||||
|
public MapWithSetLocomotivesGeneric(int picWidth, int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setLocomotives = new SetLocomotivesGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
public static int operator +(MapWithSetLocomotivesGeneric<T, U> map, T locomotive)
|
||||||
|
{
|
||||||
|
return map._setLocomotives.Insert(locomotive);
|
||||||
|
}
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
public static T operator -(MapWithSetLocomotivesGeneric<T, U> map, int position)
|
||||||
|
{
|
||||||
|
return map._setLocomotives.Remove(position);
|
||||||
|
}
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
public Bitmap ShowSet()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawLocomotives(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// Просмотр объекта на карте
|
||||||
|
public Bitmap ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
/// Перемещение объекта по крате
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
return _map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||||
|
private void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setLocomotives.Count - 1;
|
||||||
|
for (int i = 0; i < _setLocomotives.Count; i++)
|
||||||
|
{
|
||||||
|
if (_setLocomotives[i] == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var locomotive = _setLocomotives[j];
|
||||||
|
if (locomotive != null)
|
||||||
|
{
|
||||||
|
_setLocomotives.Insert(locomotive, i);
|
||||||
|
_setLocomotives.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen;
|
||||||
|
|
||||||
|
for (int j = _placeSizeHeight; j < _pictureHeight; j += _placeSizeHeight)
|
||||||
|
{
|
||||||
|
//нижняя линия рельс
|
||||||
|
pen = new(Color.Black, 5);
|
||||||
|
g.DrawLine(pen, 0, j, _pictureWidth, j);
|
||||||
|
for (int i = 0; i < _pictureWidth; i += 20)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i, j, i, j + 10);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, 0, j + 10, _pictureWidth, j + 10);
|
||||||
|
//верхняя линия рельс
|
||||||
|
pen = new(Color.DarkGray, 4);
|
||||||
|
g.DrawLine(pen, 0, j - 20, _pictureWidth, j - 20);
|
||||||
|
for (int i = 0; i < _pictureWidth; i += 20)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i, j - 20, i, j - 10);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, 0, j - 10, _pictureWidth, j - 10);
|
||||||
|
//фонари
|
||||||
|
for (int i = _placeSizeWidth; i < _pictureWidth; i += _placeSizeWidth)
|
||||||
|
{
|
||||||
|
pen = new(Color.Black, 10);
|
||||||
|
g.DrawLine(pen, i, j - _placeSizeHeight + 20, i, j);
|
||||||
|
pen = new(Color.Yellow, 20);
|
||||||
|
g.DrawLine(pen, i, j - _placeSizeHeight + 18, i, j - _placeSizeHeight + 38);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
private void DrawLocomotives(Graphics g)
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
int curWidth = 0;
|
||||||
|
int curHeight = 0;
|
||||||
|
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||||
|
{
|
||||||
|
locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 380, _pictureWidth, _pictureHeight);
|
||||||
|
locomotive?.DrawningObject(g);
|
||||||
|
if (curWidth < width) curWidth++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curWidth = 0;
|
||||||
|
curHeight--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Получение данных в виде строки
|
||||||
|
public string GetData(char separatorType, char separatorData)
|
||||||
|
{
|
||||||
|
string data = $"{_map.GetType().Name}{separatorType}";
|
||||||
|
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||||
|
{
|
||||||
|
data += $"{locomotive.getInfo()}{separatorData}";
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
/// Загрузка списка из массива строк
|
||||||
|
public void LoadData(string[] records)
|
||||||
|
{
|
||||||
|
foreach (var rec in records)
|
||||||
|
{
|
||||||
|
_setLocomotives.Insert(DrawningObject.Create(rec) as T);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Sort(IComparer<T> comparer)
|
||||||
|
{
|
||||||
|
_setLocomotives.SortSet(comparer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
113
ProjectLocomotive/ProjectLocomotive/MapsCollection.cs
Normal file
113
ProjectLocomotive/ProjectLocomotive/MapsCollection.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
using ProjectLocomotive;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class MapsCollection
|
||||||
|
{
|
||||||
|
/// Словарь (хранилище) с картами
|
||||||
|
readonly Dictionary<string, MapWithSetLocomotivesGeneric<IDrawningObject,
|
||||||
|
AbstractMap>> _mapStorages;
|
||||||
|
/// Возвращение списка названий карт
|
||||||
|
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
// Сепараторы
|
||||||
|
private readonly char separatorDict = '|';
|
||||||
|
private readonly char separatorData = ';';
|
||||||
|
/// Конструктор
|
||||||
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_mapStorages = new Dictionary<string,
|
||||||
|
MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// Добавление карты
|
||||||
|
public void AddMap(string name, AbstractMap map)
|
||||||
|
{
|
||||||
|
// Логика для добавления
|
||||||
|
if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
|
/// Удаление карты
|
||||||
|
public void DelMap(string name)
|
||||||
|
{
|
||||||
|
// Логика для удаления
|
||||||
|
if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name);
|
||||||
|
}
|
||||||
|
/// Доступ к депо
|
||||||
|
public MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap> this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// Логика получения объекта
|
||||||
|
if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Сохранение информации по локомотивам в хранилище в файл
|
||||||
|
public void SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
using (FileStream fs = new(filename, FileMode.Create))
|
||||||
|
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
|
||||||
|
{
|
||||||
|
sw.WriteLine("MapsCollection");
|
||||||
|
foreach (var storage in _mapStorages)
|
||||||
|
{
|
||||||
|
sw.WriteLine(
|
||||||
|
$"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Загрузка информации по локомотивам в депо из файла
|
||||||
|
public void LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Файл не найден");
|
||||||
|
}
|
||||||
|
using (FileStream fs = new(filename, FileMode.Open))
|
||||||
|
using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
|
||||||
|
{
|
||||||
|
string curLine = sr.ReadLine();
|
||||||
|
|
||||||
|
if (!curLine.Contains("MapsCollection"))
|
||||||
|
{
|
||||||
|
throw new FileFormatException("Формат данных в файле неправильный");
|
||||||
|
}
|
||||||
|
_mapStorages.Clear();
|
||||||
|
while ((curLine = sr.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
var elems = curLine.Split(separatorDict);
|
||||||
|
AbstractMap map = null;
|
||||||
|
|
||||||
|
switch (elems[1])
|
||||||
|
{
|
||||||
|
case "Simple Map":
|
||||||
|
map = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "Spike Map":
|
||||||
|
map = new SpikeMap();
|
||||||
|
break;
|
||||||
|
case "Rail Map":
|
||||||
|
map = new RailroadMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_mapStorages.Add(elems[0], new MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
_mapStorages[elems[0]].LoadData(elems[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,9 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace ProjectLocomotive
|
namespace ProjectLocomotive
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -11,7 +17,28 @@ namespace ProjectLocomotive
|
|||||||
// 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 FormLocomotive());
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||||
|
{
|
||||||
|
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetLocomotives>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<FormMapWithSetLocomotives>()
|
||||||
|
.AddLogging(option =>
|
||||||
|
{
|
||||||
|
var configuration = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
|
||||||
|
.Build();
|
||||||
|
var logger = new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(configuration)
|
||||||
|
.CreateLogger();
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddSerilog(logger);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,30 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="nlog.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="nlog.config">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Delegates" Version="1.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
@ -23,4 +47,10 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
59
ProjectLocomotive/ProjectLocomotive/RailroadMap.cs
Normal file
59
ProjectLocomotive/ProjectLocomotive/RailroadMap.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
internal class RailroadMap : AbstractMap
|
||||||
|
{
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
/// Цвет участка открытого
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||||
|
1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||||
|
1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 1)
|
||||||
|
{
|
||||||
|
int y = _random.Next(0, 95);
|
||||||
|
|
||||||
|
for (int x = 0; x < 99; x++)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
_map[x, y + 5] = _barrier;
|
||||||
|
|
||||||
|
if (x % 5 == 0)
|
||||||
|
{
|
||||||
|
_map[x, y + 1] = _barrier;
|
||||||
|
_map[x, y + 2] = _barrier;
|
||||||
|
_map[x, y + 3] = _barrier;
|
||||||
|
_map[x, y + 4] = _barrier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
ProjectLocomotive/ProjectLocomotive/SeaMap.cs
Normal file
50
ProjectLocomotive/ProjectLocomotive/SeaMap.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
internal class SeaMap : AbstractMap
|
||||||
|
{
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.White);
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Blue);
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 25)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 97);
|
||||||
|
int y = _random.Next(0, 97);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y + 1] = _barrier;
|
||||||
|
_map[x + 1, y + 1] = _barrier;
|
||||||
|
_map[x + 2, y + 1] = _barrier;
|
||||||
|
_map[x + 1, y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
83
ProjectLocomotive/ProjectLocomotive/SetLocomotivesGeneric.cs
Normal file
83
ProjectLocomotive/ProjectLocomotive/SetLocomotivesGeneric.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
internal class SetLocomotivesGeneric<T>
|
||||||
|
where T : class, IEquatable<T>
|
||||||
|
{
|
||||||
|
/// Список хранимых объектов
|
||||||
|
private readonly List<T> _places;
|
||||||
|
/// Количество объектов в списке
|
||||||
|
public int Count => _places.Count;
|
||||||
|
private readonly int _maxCount = 15;
|
||||||
|
/// Конструктор
|
||||||
|
public SetLocomotivesGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count = 15;
|
||||||
|
_places = new List<T>();
|
||||||
|
}
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
public int Insert(T locomotive)
|
||||||
|
{
|
||||||
|
return Insert(locomotive, 0);
|
||||||
|
}
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
public int Insert(T locomotive, int position)
|
||||||
|
{
|
||||||
|
if (_places.Contains(locomotive)) return -1; // Проверка на уникальность
|
||||||
|
if (position < 0) return -1;
|
||||||
|
if (Count >= _maxCount) throw new StorageOverflowException(_maxCount);
|
||||||
|
_places.Insert(position, locomotive);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (_places[position] is null) throw new LocomotiveNotFoundException(position);
|
||||||
|
T result = _places[position];
|
||||||
|
_places[position] = null;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// Индексатор
|
||||||
|
public T this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position >= _maxCount || position < 0) return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position >= _maxCount || position < 0) return;
|
||||||
|
Insert(value, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Проход по набору до первого пустого
|
||||||
|
public IEnumerable<T> GetLocomotives()
|
||||||
|
{
|
||||||
|
foreach (var locomotive in _places)
|
||||||
|
{
|
||||||
|
if (locomotive != null)
|
||||||
|
{
|
||||||
|
yield return locomotive;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SortSet(IComparer<T> comparer)
|
||||||
|
{
|
||||||
|
if (comparer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_places.Sort(comparer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
ProjectLocomotive/ProjectLocomotive/SimpleMap.cs
Normal file
55
ProjectLocomotive/ProjectLocomotive/SimpleMap.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Простая реализация абсрактного класса AbstractMap
|
||||||
|
/// </summary>
|
||||||
|
internal class SimpleMap : AbstractMap
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
/// </summary>
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет участка открытого
|
||||||
|
/// </summary>
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 100);
|
||||||
|
int y = _random.Next(0, 100);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
ProjectLocomotive/ProjectLocomotive/SpikeMap.cs
Normal file
54
ProjectLocomotive/ProjectLocomotive/SpikeMap.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
internal class SpikeMap : AbstractMap
|
||||||
|
{
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
/// Цвет участка открытого
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||||
|
1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||||
|
1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 15)
|
||||||
|
{
|
||||||
|
int x = _random.Next(1, 99);
|
||||||
|
int y = _random.Next(1, 99);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
if (_map[x + 1, y] == _freeRoad) _map[x + 1, y] = _barrier;
|
||||||
|
if (_map[x - 1, y] == _freeRoad) _map[x - 1, y] = _barrier;
|
||||||
|
if (_map[x, y + 1] == _freeRoad) _map[x, y + 1] = _barrier;
|
||||||
|
if (_map[x, y - 1] == _freeRoad) _map[x, y - 1] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLocomotive
|
||||||
|
{
|
||||||
|
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 context) : base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
48
ProjectLocomotive/ProjectLocomotive/appsettings.json
Normal file
48
ProjectLocomotive/ProjectLocomotive/appsettings.json
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"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" ],
|
||||||
|
"Destructure": [
|
||||||
|
{
|
||||||
|
"Name": "ByTransforming",
|
||||||
|
"Args": {
|
||||||
|
"returnType": "ProjectLocomotive.EntityLocomotive",
|
||||||
|
"transformation": "r => new { BodyColor = r.BodyColor.Name, r.Speed, r.Weight }"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "ByTransforming",
|
||||||
|
"Args": {
|
||||||
|
"returnType": "ProjectLocomotive.EntityElectricLocomotive",
|
||||||
|
"transformation": "r => new { BodyColor = r.BodyColor.Name, DopColor = r.DopColor.Name, r.ElectroLines, r.ElectroBattery, r.Speed, r.Weight }"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "ToMaximumDepth",
|
||||||
|
"Args": { "maximumDestructuringDepth": 4 }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "ToMaximumStringLength",
|
||||||
|
"Args": { "maximumStringLength": 100 }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "ToMaximumCollectionCount",
|
||||||
|
"Args": { "maximumCollectionCount": 15 }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Properties": {
|
||||||
|
"Application": "ProjectLocomotive"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
ProjectLocomotive/ProjectLocomotive/nlog.config
Normal file
15
ProjectLocomotive/ProjectLocomotive/nlog.config
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<nlog xmlns="http://www.nlog-progect.org/schemas/NLog.xsd"
|
||||||
|
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instanse"
|
||||||
|
autoReload="true" internalLogLevel="Info">
|
||||||
|
|
||||||
|
<targets>
|
||||||
|
<target xsi:type="File" name="tofile" fileName="locomotivelog-${shortdate}.log"/>
|
||||||
|
</targets>
|
||||||
|
|
||||||
|
<rules>
|
||||||
|
<logger name="*" minlevel="Debug" writeTo="tofile"/>
|
||||||
|
</rules>
|
||||||
|
</nlog>
|
||||||
|
</configuration>
|
Loading…
Reference in New Issue
Block a user