Compare commits
33 Commits
master
...
LabWork_08
Author | SHA1 | Date | |
---|---|---|---|
2330ac9aed | |||
14f57eb760 | |||
d83609741b | |||
eb23baf490 | |||
395cf53902 | |||
141ba54299 | |||
971fa53780 | |||
8438c8071d | |||
cc6f49f85d | |||
314d2c3b15 | |||
5c51aa1122 | |||
c789de973c | |||
498ce0d89b | |||
38ae601acc | |||
c9dd2ad472 | |||
a7b048a256 | |||
80c18de5db | |||
56b0d0de6f | |||
6da1444518 | |||
7082b3197b | |||
8380d8b6c4 | |||
9e1d8bf1ac | |||
50c261a24c | |||
e672312abc | |||
33701833e9 | |||
c269ff167a | |||
6e7a53cf74 | |||
eac9710f69 | |||
954aa17666 | |||
cf067f83de | |||
d0c4dedf44 | |||
227307519b | |||
f9ff52e57b |
179
WarmlyLocomotive/WarmlyLocomotive/AbstractMap.cs
Normal file
179
WarmlyLocomotive/WarmlyLocomotive/AbstractMap.cs
Normal file
@ -0,0 +1,179 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
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 Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
(float leftX, float topY, float rightX, float bottomY) = _drawningObject.GetCurrentPosition();
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i,j] == _barrier)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Up:
|
||||
if(_size_y * (j+1) >= topY - _drawningObject.Step && _size_y * (j+1) < topY && _size_x * (i + 1) > leftX
|
||||
&& _size_x * (i + 1) <= rightX)
|
||||
{
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
break;
|
||||
case Direction.Down:
|
||||
if (_size_y * j <= bottomY + _drawningObject.Step && _size_y * j > bottomY && _size_x * (i+1) > leftX
|
||||
&& _size_x * (i+1) <= rightX)
|
||||
{
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
break;
|
||||
case Direction.Left:
|
||||
if (_size_x * (i+1) >= leftX - _drawningObject.Step && _size_x * (i + 1) < leftX && _size_y * (j + 1) < bottomY
|
||||
&& _size_y * (j + 1) >= topY)
|
||||
{
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
break;
|
||||
case Direction.Right:
|
||||
if (_size_x * i <= rightX + _drawningObject.Step && _size_x * i > leftX && _size_y * (j + 1) < bottomY
|
||||
&& _size_y * (j + 1) >= topY)
|
||||
{
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawningObject.MoveObject(direction);
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
(float currentX, float currentY, float locomotiveWidth, float locomotiveHeight) = _drawningObject.GetCurrentPosition();
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(currentX != 0)
|
||||
{
|
||||
locomotiveWidth -= currentX;
|
||||
}
|
||||
if (currentY != 0)
|
||||
{
|
||||
locomotiveHeight -= currentY;
|
||||
}
|
||||
int x = _random.Next(0, 10);
|
||||
int y = _random.Next(0, 10);
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i,j] == _barrier)
|
||||
{
|
||||
if(x + locomotiveWidth >= _size_x * i && x <= _size_x * i && y + locomotiveHeight > _size_y * j && y <= _size_y * j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
var otherMap = other as AbstractMap;
|
||||
if (otherMap == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_width != otherMap._width)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_height != otherMap._height)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_size_x != otherMap._size_x)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_size_y != otherMap._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] != otherMap._map[i, j])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
64
WarmlyLocomotive/WarmlyLocomotive/BigBarriersMap.cs
Normal file
64
WarmlyLocomotive/WarmlyLocomotive/BigBarriersMap.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class BigBarriersMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.SandyBrown);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.LightCyan);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
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(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (x + 2 < 100 && y + 2 < 100)
|
||||
{
|
||||
if (_map[x, y] == _freeRoad && _map[x, y + 1] == _freeRoad && _map[x, y + 2] == _freeRoad && _map[x + 1, y] == _freeRoad && _map[x + 1, y + 1] == _freeRoad
|
||||
&& _map[x + 1, y + 2] == _freeRoad && _map[x + 2, y] == _freeRoad && _map[x + 2, y + 1] == _freeRoad && _map[x + 2, y + 2] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
_map[x, y + 1] = _barrier;
|
||||
_map[x, y + 2] = _barrier;
|
||||
_map[x + 1, y] = _barrier;
|
||||
_map[x + 1, y + 1] = _barrier;
|
||||
_map[x + 1, y + 2] = _barrier;
|
||||
_map[x + 2, y] = _barrier;
|
||||
_map[x + 2, y + 1] = _barrier;
|
||||
_map[x + 2, y + 2] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
65
WarmlyLocomotive/WarmlyLocomotive/CirclesMap.cs
Normal file
65
WarmlyLocomotive/WarmlyLocomotive/CirclesMap.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class CirclesMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Red);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.LightCoral);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
if (i - 1 >= 0 && j - 1 >= 0)
|
||||
{
|
||||
if (_map[i - 1, j - 1] == _barrier && _map[i - 1, j] == _barrier && _map[i, j - 1] == _barrier)
|
||||
{
|
||||
g.FillEllipse(barrierColor, (i-1) * _size_x, (j-1) * _size_y, _size_x * 2, _size_y * 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
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 < 20)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (x + 1 < 100 && y + 1 < 100)
|
||||
{
|
||||
if (_map[x, y] == _freeRoad && _map[x, y + 1] == _freeRoad && _map[x + 1, y] == _freeRoad && _map[x + 1, y + 1] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
_map[x + 1, y] = _barrier;
|
||||
_map[x + 1, y + 1] = _barrier;
|
||||
_map[x, y + 1] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,8 +9,9 @@ namespace WarmlyLocomotive
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
|
@ -9,20 +9,20 @@ namespace WarmlyLocomotive
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
internal class DrawningLocomotive
|
||||
public class DrawningLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityLocomotive Locomotive { get; private set; }
|
||||
public EntityLocomotive Locomotive { get; protected set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки локомотива
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки локомотива
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -45,10 +45,14 @@ namespace WarmlyLocomotive
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес локомотива</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawningLocomotive(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Locomotive = new EntityLocomotive();
|
||||
Locomotive.Init(speed, weight, bodyColor);
|
||||
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawningLocomotive(int speed, float weight, Color bodyColor, int locomotiveWidth, int locomotiveHeight) : this(speed, weight, bodyColor)
|
||||
{
|
||||
_locomotiveWidth = locomotiveWidth;
|
||||
_locomotiveHeight = locomotiveHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции локомотива
|
||||
@ -113,7 +117,7 @@ namespace WarmlyLocomotive
|
||||
/// Отрисовка локомотива
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
@ -179,5 +183,9 @@ namespace WarmlyLocomotive
|
||||
_startPosY = _pictureHeight.Value - _locomotiveHeight;
|
||||
}
|
||||
}
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _locomotiveWidth, _startPosY + _locomotiveHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class DrawningObjectLocomotive : IDrawningObject
|
||||
{
|
||||
private DrawningLocomotive _locomotive = null;
|
||||
public float Step => _locomotive?.Locomotive?.Step ?? 0;
|
||||
public DrawningLocomotive GetLocomotive => _locomotive;
|
||||
public DrawningObjectLocomotive(DrawningLocomotive locomotive)
|
||||
{
|
||||
_locomotive = locomotive;
|
||||
}
|
||||
public void DrawningObject(Graphics g)
|
||||
{
|
||||
_locomotive?.DrawTransport(g);
|
||||
}
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _locomotive?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_locomotive?.MoveTransport(direction);
|
||||
}
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_locomotive.SetPosition(x, y, width, height);
|
||||
}
|
||||
public string GetInfo() => _locomotive?.GetDataForSave();
|
||||
public static IDrawningObject Create(string data) => new DrawningObjectLocomotive(data.CreateDrawningLocomotive());
|
||||
public bool Equals(IDrawningObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherLocomotive = other as DrawningObjectLocomotive;
|
||||
if (otherLocomotive == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var locomotive = _locomotive.Locomotive;
|
||||
var otherLocomotiveLocomotive = otherLocomotive._locomotive.Locomotive;
|
||||
if (locomotive.Speed != otherLocomotiveLocomotive.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (locomotive.Weight != otherLocomotiveLocomotive.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (locomotive.BodyColor != otherLocomotiveLocomotive.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(locomotive is EntityWarmlyLocomotive warmlyLocomotive && otherLocomotiveLocomotive is EntityWarmlyLocomotive otherWarmlyLocomotive)
|
||||
{
|
||||
if(warmlyLocomotive.Pipe != otherWarmlyLocomotive.Pipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (warmlyLocomotive.FuelCompartment != otherWarmlyLocomotive.FuelCompartment)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (warmlyLocomotive.WarmlyLines != otherWarmlyLocomotive.WarmlyLines)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (warmlyLocomotive.DopColor != otherWarmlyLocomotive.DopColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(locomotive is EntityWarmlyLocomotive || otherLocomotiveLocomotive is EntityWarmlyLocomotive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class DrawningWarmlyLocomotive : DrawningLocomotive
|
||||
{
|
||||
public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool pipe, bool fuelCompartment, bool warmlyLines): base(speed, weight, bodyColor, 210, 120)
|
||||
{
|
||||
Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, dopColor, pipe, fuelCompartment, warmlyLines);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if(Locomotive is not EntityWarmlyLocomotive warmlyLocomotive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(warmlyLocomotive.DopColor);
|
||||
if (warmlyLocomotive.Pipe)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 125, _startPosY + 5, 35, 10);
|
||||
g.FillRectangle(dopBrush, _startPosX + 130, _startPosY, 25, 5);
|
||||
g.DrawRectangle(pen, _startPosX + 125, _startPosY + 5, 35, 10);
|
||||
g.DrawRectangle(pen, _startPosX + 130, _startPosY, 25, 5);
|
||||
}
|
||||
if (warmlyLocomotive.FuelCompartment)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 85, 50, 25);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 85, 50, 25);
|
||||
g.FillEllipse(new SolidBrush(Color.Black), _startPosX + 115, _startPosY + 100, 5, 5);
|
||||
}
|
||||
_startPosY += 15;
|
||||
base.DrawTransport(g);
|
||||
_startPosY -= 15;
|
||||
if (warmlyLocomotive.WarmlyLines)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 180, _startPosY + 60, 30, 5);
|
||||
g.FillRectangle(dopBrush, _startPosX + 180, _startPosY + 80, 30, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class EntityLocomotive
|
||||
public class EntityLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -19,7 +19,7 @@ namespace WarmlyLocomotive
|
||||
/// <summary>
|
||||
/// Цвет кузова
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
public Color BodyColor { get; set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения локомотива
|
||||
/// </summary>
|
||||
@ -31,7 +31,7 @@ namespace WarmlyLocomotive
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityLocomotive(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
|
37
WarmlyLocomotive/WarmlyLocomotive/EntityWarmlyLocomotive.cs
Normal file
37
WarmlyLocomotive/WarmlyLocomotive/EntityWarmlyLocomotive.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class EntityWarmlyLocomotive : EntityLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; set; }
|
||||
/// <summary>
|
||||
/// Признак наличия трубы
|
||||
/// </summary>
|
||||
public bool Pipe { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия отсека под топливо
|
||||
/// </summary>
|
||||
public bool FuelCompartment { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия полос на кузове
|
||||
/// </summary>
|
||||
public bool WarmlyLines { get; private set; }
|
||||
public EntityWarmlyLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool pipe, bool fuelCompartment, bool warmlyLines) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Pipe = pipe;
|
||||
FuelCompartment = fuelCompartment;
|
||||
WarmlyLines = warmlyLines;
|
||||
}
|
||||
}
|
||||
}
|
53
WarmlyLocomotive/WarmlyLocomotive/ExtentionLocomotive.cs
Normal file
53
WarmlyLocomotive/WarmlyLocomotive/ExtentionLocomotive.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal static class ExtentionLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
/// <returns></returns>
|
||||
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 == 7)
|
||||
{
|
||||
return new DrawningWarmlyLocomotive(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningLocomotive"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDataForSave(this DrawningLocomotive drawningLocomotive)
|
||||
{
|
||||
var locomotive = drawningLocomotive.Locomotive;
|
||||
var str = $"{locomotive.Speed}{_separatorForObject}{locomotive.Weight}{_separatorForObject}{locomotive.BodyColor.Name}";
|
||||
if (locomotive is not EntityWarmlyLocomotive warmlyLocomotive)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{_separatorForObject}{warmlyLocomotive.DopColor.Name}{_separatorForObject}{warmlyLocomotive.Pipe}{_separatorForObject}{warmlyLocomotive.FuelCompartment}{_separatorForObject}{warmlyLocomotive.WarmlyLines}";
|
||||
}
|
||||
}
|
||||
}
|
@ -38,6 +38,8 @@
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.buttonSelectLocomotive = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -141,11 +143,35 @@
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(105, 418);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(110, 23);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// buttonSelectLocomotive
|
||||
//
|
||||
this.buttonSelectLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonSelectLocomotive.Location = new System.Drawing.Point(618, 415);
|
||||
this.buttonSelectLocomotive.Name = "buttonSelectLocomotive";
|
||||
this.buttonSelectLocomotive.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonSelectLocomotive.TabIndex = 8;
|
||||
this.buttonSelectLocomotive.Text = "Выбрать";
|
||||
this.buttonSelectLocomotive.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click);
|
||||
//
|
||||
// FormLocomotive
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(837, 483);
|
||||
this.Controls.Add(this.buttonSelectLocomotive);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
@ -176,5 +202,7 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonCreateModif;
|
||||
private Button buttonSelectLocomotive;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ namespace WarmlyLocomotive
|
||||
public partial class FormLocomotive : Form
|
||||
{
|
||||
private DrawningLocomotive _locomotive;
|
||||
public DrawningLocomotive SelectedLocomotive { get; private set; }
|
||||
public FormLocomotive()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -17,6 +18,17 @@ namespace WarmlyLocomotive
|
||||
_locomotive?.DrawTransport(gr);
|
||||
pictureBoxLocomotive.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ěĺňîä óńňŕíîâęč äŕííűő
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ńęîđîńňü: {_locomotive.Locomotive.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âĺń: {_locomotive.Locomotive.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâĺň: {_locomotive.Locomotive.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
@ -25,12 +37,14 @@ namespace WarmlyLocomotive
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_locomotive = new DrawningLocomotive();
|
||||
_locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_locomotive.Locomotive.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_locomotive.Locomotive.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_locomotive.Locomotive.BodyColor.Name}";
|
||||
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;
|
||||
}
|
||||
_locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
private void ButtonMove_click(object sender, EventArgs e)
|
||||
@ -58,5 +72,30 @@ namespace WarmlyLocomotive
|
||||
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||
Draw();
|
||||
}
|
||||
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;
|
||||
}
|
||||
_locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedLocomotive = _locomotive;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
382
WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.Designer.cs
generated
Normal file
382
WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.Designer.cs
generated
Normal file
@ -0,0 +1,382 @@
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
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.panelBlue = new System.Windows.Forms.Panel();
|
||||
this.panelGreen = new System.Windows.Forms.Panel();
|
||||
this.panelRed = new System.Windows.Forms.Panel();
|
||||
this.checkBoxWarmlyLines = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxFuelCompartment = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxPipe = new System.Windows.Forms.CheckBox();
|
||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.labelWeight = new System.Windows.Forms.Label();
|
||||
this.labelSpeed = new System.Windows.Forms.Label();
|
||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.panelObject = new System.Windows.Forms.Panel();
|
||||
this.labelDopColor = new System.Windows.Forms.Label();
|
||||
this.labelBaseColor = new System.Windows.Forms.Label();
|
||||
this.buttonOk = 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();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||
this.panelObject.SuspendLayout();
|
||||
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.checkBoxWarmlyLines);
|
||||
this.groupBoxConfig.Controls.Add(this.checkBoxFuelCompartment);
|
||||
this.groupBoxConfig.Controls.Add(this.checkBoxPipe);
|
||||
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
|
||||
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
|
||||
this.groupBoxConfig.Controls.Add(this.labelWeight);
|
||||
this.groupBoxConfig.Controls.Add(this.labelSpeed);
|
||||
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBoxConfig.Name = "groupBoxConfig";
|
||||
this.groupBoxConfig.Size = new System.Drawing.Size(493, 214);
|
||||
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(384, 154);
|
||||
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||
this.labelModifiedObject.Size = new System.Drawing.Size(95, 38);
|
||||
this.labelModifiedObject.TabIndex = 9;
|
||||
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(281, 154);
|
||||
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||
this.labelSimpleObject.Size = new System.Drawing.Size(95, 38);
|
||||
this.labelSimpleObject.TabIndex = 8;
|
||||
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.panelBlue);
|
||||
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||
this.groupBoxColors.Location = new System.Drawing.Point(281, 22);
|
||||
this.groupBoxColors.Name = "groupBoxColors";
|
||||
this.groupBoxColors.Size = new System.Drawing.Size(198, 120);
|
||||
this.groupBoxColors.TabIndex = 7;
|
||||
this.groupBoxColors.TabStop = false;
|
||||
this.groupBoxColors.Text = "Цвета";
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||
this.panelPurple.Location = new System.Drawing.Point(157, 68);
|
||||
this.panelPurple.MaximumSize = new System.Drawing.Size(30, 30);
|
||||
this.panelPurple.Name = "panelPurple";
|
||||
this.panelPurple.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelPurple.TabIndex = 7;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||
this.panelBlack.Location = new System.Drawing.Point(111, 68);
|
||||
this.panelBlack.MaximumSize = new System.Drawing.Size(30, 30);
|
||||
this.panelBlack.Name = "panelBlack";
|
||||
this.panelBlack.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelBlack.TabIndex = 6;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||
this.panelGray.Location = new System.Drawing.Point(65, 68);
|
||||
this.panelGray.MaximumSize = new System.Drawing.Size(30, 30);
|
||||
this.panelGray.Name = "panelGray";
|
||||
this.panelGray.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelGray.TabIndex = 5;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||
this.panelWhite.Location = new System.Drawing.Point(19, 68);
|
||||
this.panelWhite.MaximumSize = new System.Drawing.Size(30, 30);
|
||||
this.panelWhite.Name = "panelWhite";
|
||||
this.panelWhite.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelWhite.TabIndex = 4;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||
this.panelYellow.Location = new System.Drawing.Point(157, 22);
|
||||
this.panelYellow.MaximumSize = new System.Drawing.Size(30, 30);
|
||||
this.panelYellow.Name = "panelYellow";
|
||||
this.panelYellow.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelYellow.TabIndex = 3;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||
this.panelBlue.Location = new System.Drawing.Point(111, 22);
|
||||
this.panelBlue.MaximumSize = new System.Drawing.Size(30, 30);
|
||||
this.panelBlue.Name = "panelBlue";
|
||||
this.panelBlue.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelBlue.TabIndex = 2;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
||||
this.panelGreen.Location = new System.Drawing.Point(65, 22);
|
||||
this.panelGreen.MaximumSize = new System.Drawing.Size(30, 30);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelGreen.TabIndex = 1;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||
this.panelRed.Location = new System.Drawing.Point(19, 22);
|
||||
this.panelRed.MaximumSize = new System.Drawing.Size(30, 30);
|
||||
this.panelRed.Name = "panelRed";
|
||||
this.panelRed.Size = new System.Drawing.Size(30, 30);
|
||||
this.panelRed.TabIndex = 0;
|
||||
//
|
||||
// checkBoxWarmlyLines
|
||||
//
|
||||
this.checkBoxWarmlyLines.AutoSize = true;
|
||||
this.checkBoxWarmlyLines.Location = new System.Drawing.Point(18, 173);
|
||||
this.checkBoxWarmlyLines.Name = "checkBoxWarmlyLines";
|
||||
this.checkBoxWarmlyLines.Size = new System.Drawing.Size(215, 19);
|
||||
this.checkBoxWarmlyLines.TabIndex = 6;
|
||||
this.checkBoxWarmlyLines.Text = "Признак наличия полос на кузове";
|
||||
this.checkBoxWarmlyLines.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxFuelCompartment
|
||||
//
|
||||
this.checkBoxFuelCompartment.AutoSize = true;
|
||||
this.checkBoxFuelCompartment.Location = new System.Drawing.Point(18, 148);
|
||||
this.checkBoxFuelCompartment.Name = "checkBoxFuelCompartment";
|
||||
this.checkBoxFuelCompartment.Size = new System.Drawing.Size(234, 19);
|
||||
this.checkBoxFuelCompartment.TabIndex = 5;
|
||||
this.checkBoxFuelCompartment.Text = "Признак наличия отсека под топливо";
|
||||
this.checkBoxFuelCompartment.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxPipe
|
||||
//
|
||||
this.checkBoxPipe.AutoSize = true;
|
||||
this.checkBoxPipe.Location = new System.Drawing.Point(18, 123);
|
||||
this.checkBoxPipe.Name = "checkBoxPipe";
|
||||
this.checkBoxPipe.Size = new System.Drawing.Size(160, 19);
|
||||
this.checkBoxPipe.TabIndex = 4;
|
||||
this.checkBoxPipe.Text = "Признак наличия трубы";
|
||||
this.checkBoxPipe.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
this.numericUpDownWeight.Location = new System.Drawing.Point(86, 69);
|
||||
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
this.numericUpDownWeight.Size = new System.Drawing.Size(89, 23);
|
||||
this.numericUpDownWeight.TabIndex = 3;
|
||||
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(86, 28);
|
||||
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
this.numericUpDownSpeed.Size = new System.Drawing.Size(89, 23);
|
||||
this.numericUpDownSpeed.TabIndex = 2;
|
||||
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
this.labelWeight.AutoSize = true;
|
||||
this.labelWeight.Location = new System.Drawing.Point(18, 69);
|
||||
this.labelWeight.Name = "labelWeight";
|
||||
this.labelWeight.Size = new System.Drawing.Size(29, 15);
|
||||
this.labelWeight.TabIndex = 1;
|
||||
this.labelWeight.Text = "Вес:";
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
this.labelSpeed.AutoSize = true;
|
||||
this.labelSpeed.Location = new System.Drawing.Point(18, 28);
|
||||
this.labelSpeed.Name = "labelSpeed";
|
||||
this.labelSpeed.Size = new System.Drawing.Size(62, 15);
|
||||
this.labelSpeed.TabIndex = 0;
|
||||
this.labelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
this.pictureBoxObject.Location = new System.Drawing.Point(21, 34);
|
||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||
this.pictureBoxObject.Size = new System.Drawing.Size(230, 130);
|
||||
this.pictureBoxObject.TabIndex = 1;
|
||||
this.pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// 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(511, 12);
|
||||
this.panelObject.Name = "panelObject";
|
||||
this.panelObject.Size = new System.Drawing.Size(271, 182);
|
||||
this.panelObject.TabIndex = 2;
|
||||
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(166, 6);
|
||||
this.labelDopColor.Name = "labelDopColor";
|
||||
this.labelDopColor.Size = new System.Drawing.Size(85, 25);
|
||||
this.labelDopColor.TabIndex = 10;
|
||||
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.LabelDopColor_DragEnter);
|
||||
//
|
||||
// labelBaseColor
|
||||
//
|
||||
this.labelBaseColor.AllowDrop = true;
|
||||
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelBaseColor.Location = new System.Drawing.Point(21, 6);
|
||||
this.labelBaseColor.Name = "labelBaseColor";
|
||||
this.labelBaseColor.Size = new System.Drawing.Size(85, 25);
|
||||
this.labelBaseColor.TabIndex = 9;
|
||||
this.labelBaseColor.Text = "Цвет";
|
||||
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
||||
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
|
||||
//
|
||||
// buttonOk
|
||||
//
|
||||
this.buttonOk.Location = new System.Drawing.Point(542, 200);
|
||||
this.buttonOk.Name = "buttonOk";
|
||||
this.buttonOk.Size = new System.Drawing.Size(89, 30);
|
||||
this.buttonOk.TabIndex = 3;
|
||||
this.buttonOk.Text = "Добавить";
|
||||
this.buttonOk.UseVisualStyleBackColor = true;
|
||||
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(660, 200);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(89, 30);
|
||||
this.buttonCancel.TabIndex = 4;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormLocomotiveConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(792, 238);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonOk);
|
||||
this.Controls.Add(this.panelObject);
|
||||
this.Controls.Add(this.groupBoxConfig);
|
||||
this.Name = "FormLocomotiveConfig";
|
||||
this.Text = "Создание объекта";
|
||||
this.groupBoxConfig.ResumeLayout(false);
|
||||
this.groupBoxConfig.PerformLayout();
|
||||
this.groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||
this.panelObject.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxConfig;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelWeight;
|
||||
private Label labelSpeed;
|
||||
private CheckBox checkBoxWarmlyLines;
|
||||
private CheckBox checkBoxFuelCompartment;
|
||||
private CheckBox checkBoxPipe;
|
||||
private GroupBox groupBoxColors;
|
||||
private Label labelModifiedObject;
|
||||
private Label labelSimpleObject;
|
||||
private Panel panelPurple;
|
||||
private Panel panelBlack;
|
||||
private Panel panelGray;
|
||||
private Panel panelWhite;
|
||||
private Panel panelYellow;
|
||||
private Panel panelBlue;
|
||||
private Panel panelGreen;
|
||||
private Panel panelRed;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Panel panelObject;
|
||||
private Label labelDopColor;
|
||||
private Label labelBaseColor;
|
||||
private Button buttonOk;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
189
WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.cs
Normal file
189
WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.cs
Normal file
@ -0,0 +1,189 @@
|
||||
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 WarmlyLocomotive
|
||||
{
|
||||
public partial class FormLocomotiveConfig : Form
|
||||
{
|
||||
DrawningLocomotive _locomotive = null;
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event Action<DrawningLocomotive> EventAddLocomotive;
|
||||
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();
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовать локомотив
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev"></param>
|
||||
public void AddEvent(Action<DrawningLocomotive> ev)
|
||||
{
|
||||
if (EventAddLocomotive == null)
|
||||
{
|
||||
EventAddLocomotive = new Action<DrawningLocomotive>(ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddLocomotive += ev;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Передаем информацию при нажатии на Label
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Действия при приеме перетаскиваемой информации
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_locomotive = new DrawningLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_locomotive = new DrawningWarmlyLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||||
checkBoxPipe.Checked, checkBoxFuelCompartment.Checked, checkBoxWarmlyLines.Checked);
|
||||
break;
|
||||
}
|
||||
DrawLocomotive();
|
||||
}
|
||||
/// <summary>
|
||||
/// Отправляем цвет с панели
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Принимаем основной цвет
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if(_locomotive != null)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color))) {
|
||||
_locomotive.Locomotive.BodyColor = (Color)e.Data.GetData(typeof(Color));
|
||||
}
|
||||
DrawLocomotive();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Принимаем дополнительный цвет
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_locomotive != null && _locomotive is DrawningWarmlyLocomotive warmlyLocomotive)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
if(warmlyLocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive)
|
||||
{
|
||||
entityWarmlyLocomotive.DopColor = (Color)e.Data.GetData(typeof(Color));
|
||||
}
|
||||
}
|
||||
DrawLocomotive();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление локомотива
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddLocomotive?.Invoke(_locomotive);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.resx
Normal file
60
WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveConfig.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
371
WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.Designer.cs
generated
Normal file
371
WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.Designer.cs
generated
Normal file
@ -0,0 +1,371 @@
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
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.groupBox = new System.Windows.Forms.GroupBox();
|
||||
this.buttonSortByColor = new System.Windows.Forms.Button();
|
||||
this.buttonSortByType = new System.Windows.Forms.Button();
|
||||
this.groupBoxMaps = 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.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = 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.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.groupBox.SuspendLayout();
|
||||
this.groupBoxMaps.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox
|
||||
//
|
||||
this.groupBox.Controls.Add(this.buttonSortByColor);
|
||||
this.groupBox.Controls.Add(this.buttonSortByType);
|
||||
this.groupBox.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBox.Controls.Add(this.buttonDown);
|
||||
this.groupBox.Controls.Add(this.buttonRight);
|
||||
this.groupBox.Controls.Add(this.buttonLeft);
|
||||
this.groupBox.Controls.Add(this.buttonUp);
|
||||
this.groupBox.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBox.Controls.Add(this.buttonShowStorage);
|
||||
this.groupBox.Controls.Add(this.buttonRemoveLocomotive);
|
||||
this.groupBox.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBox.Controls.Add(this.buttonAddLocomotive);
|
||||
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox.Location = new System.Drawing.Point(668, 24);
|
||||
this.groupBox.Name = "groupBox";
|
||||
this.groupBox.Size = new System.Drawing.Size(200, 693);
|
||||
this.groupBox.TabIndex = 0;
|
||||
this.groupBox.TabStop = false;
|
||||
this.groupBox.Text = "Инструменты";
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
this.buttonSortByColor.Location = new System.Drawing.Point(19, 340);
|
||||
this.buttonSortByColor.Name = "buttonSortByColor";
|
||||
this.buttonSortByColor.Size = new System.Drawing.Size(169, 30);
|
||||
this.buttonSortByColor.TabIndex = 12;
|
||||
this.buttonSortByColor.Text = "Сортировать по цвету";
|
||||
this.buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
this.buttonSortByType.Location = new System.Drawing.Point(19, 304);
|
||||
this.buttonSortByType.Name = "buttonSortByType";
|
||||
this.buttonSortByType.Size = new System.Drawing.Size(169, 30);
|
||||
this.buttonSortByType.TabIndex = 11;
|
||||
this.buttonSortByType.Text = "Сортировать по типу";
|
||||
this.buttonSortByType.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// groupBoxMaps
|
||||
//
|
||||
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
|
||||
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
||||
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
|
||||
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
|
||||
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxMaps.Location = new System.Drawing.Point(6, 22);
|
||||
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||
this.groupBoxMaps.Size = new System.Drawing.Size(188, 261);
|
||||
this.groupBoxMaps.TabIndex = 10;
|
||||
this.groupBoxMaps.TabStop = false;
|
||||
this.groupBoxMaps.Text = "Карты";
|
||||
//
|
||||
// buttonDeleteMap
|
||||
//
|
||||
this.buttonDeleteMap.Location = new System.Drawing.Point(13, 220);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(169, 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 = 15;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(13, 120);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(169, 94);
|
||||
this.listBoxMaps.TabIndex = 2;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// buttonAddMap
|
||||
//
|
||||
this.buttonAddMap.Location = new System.Drawing.Point(13, 80);
|
||||
this.buttonAddMap.Name = "buttonAddMap";
|
||||
this.buttonAddMap.Size = new System.Drawing.Size(169, 34);
|
||||
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(13, 22);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(169, 23);
|
||||
this.textBoxNewMapName.TabIndex = 0;
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Карта с большими барьерами",
|
||||
"Карта с круглыми барьерами"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 46);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(169, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(87, 646);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 9;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(123, 646);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 8;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(51, 646);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 7;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(87, 610);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 6;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(19, 554);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(169, 30);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(19, 506);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(169, 30);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// buttonRemoveLocomotive
|
||||
//
|
||||
this.buttonRemoveLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRemoveLocomotive.Location = new System.Drawing.Point(19, 460);
|
||||
this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
|
||||
this.buttonRemoveLocomotive.Size = new System.Drawing.Size(169, 30);
|
||||
this.buttonRemoveLocomotive.TabIndex = 3;
|
||||
this.buttonRemoveLocomotive.Text = "Удалить локомотив";
|
||||
this.buttonRemoveLocomotive.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveLocomotive.Click += new System.EventHandler(this.ButtonRemoveLocomotive_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 431);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(169, 23);
|
||||
this.maskedTextBoxPosition.TabIndex = 2;
|
||||
//
|
||||
// buttonAddLocomotive
|
||||
//
|
||||
this.buttonAddLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonAddLocomotive.Location = new System.Drawing.Point(19, 395);
|
||||
this.buttonAddLocomotive.Name = "buttonAddLocomotive";
|
||||
this.buttonAddLocomotive.Size = new System.Drawing.Size(169, 30);
|
||||
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, 24);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(668, 693);
|
||||
this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
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(868, 24);
|
||||
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(48, 20);
|
||||
this.FileToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(141, 22);
|
||||
this.SaveToolStripMenuItem.Text = "Сохранение";
|
||||
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(141, 22);
|
||||
this.LoadToolStripMenuItem.Text = "Загрузка";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.Filter = "txt file|*.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file|*.txt";
|
||||
//
|
||||
// FormMapWithSetLocomotives
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(868, 717);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormMapWithSetLocomotives";
|
||||
this.Text = "Карта с набором объектов";
|
||||
this.groupBox.ResumeLayout(false);
|
||||
this.groupBox.PerformLayout();
|
||||
this.groupBoxMaps.ResumeLayout(false);
|
||||
this.groupBoxMaps.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonShowOnMap;
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonRemoveLocomotive;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonAddLocomotive;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private PictureBox pictureBox;
|
||||
private GroupBox groupBoxMaps;
|
||||
private Button buttonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private Button buttonAddMap;
|
||||
private TextBox textBoxNewMapName;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem FileToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
351
WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.cs
Normal file
351
WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.cs
Normal file
@ -0,0 +1,351 @@
|
||||
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;
|
||||
using static System.Windows.Forms.DataFormats;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
public partial class FormMapWithSetLocomotives : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь для выпадающего списка
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{"Простая карта", new SimpleMap()},
|
||||
{"Карта с большими барьерами", new BigBarriersMap()},
|
||||
{"Карта с круглыми барьерами", new CirclesMap()}
|
||||
};
|
||||
/// <summary>
|
||||
/// Объект от коллекции карт
|
||||
/// </summary>
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
/// <summary>
|
||||
/// Логер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMapWithSetLocomotives(ILogger<FormMapWithSetLocomotives> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
foreach (var elem in _mapsDict)
|
||||
{
|
||||
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxMaps
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
var formLocomotiveConfig = new FormLocomotiveConfig();
|
||||
formLocomotiveConfig.AddEvent(AddLocomotive);
|
||||
formLocomotiveConfig.Show();
|
||||
}
|
||||
private void AddLocomotive(DrawningLocomotive drawningLocomotive)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawningObjectLocomotive locomotive = new(drawningLocomotive);
|
||||
try
|
||||
{
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1)
|
||||
{
|
||||
_logger.LogInformation($"Добавление объекта {locomotive}");
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Не удалось добавить объект");
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
_logger.LogWarning($"Ошибка переполнения хранилища: {ex.Message}");
|
||||
MessageBox.Show($"Ошибка переполнения хранилища: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
catch(ArgumentException ex)
|
||||
{
|
||||
_logger.LogWarning($"Ошибка при добавлении: {ex.Message}");
|
||||
MessageBox.Show($"Ошибка при добавлении: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning($"Неизвестная ошибка: {ex.Message}");
|
||||
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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)
|
||||
{
|
||||
_logger.LogInformation($"Объект {deletedLocomotive} удалён");
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation($"Не удалось удалить объект по позиции {pos}");
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
catch (LocomotiveNotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning($"Ошибка удаления: {ex.Message}");
|
||||
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning($"Неизвестная ошибка: {ex.Message}");
|
||||
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||
{
|
||||
_logger.LogInformation("Не все данные заполнены при попытке создании карты");
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||
{
|
||||
_logger.LogInformation($"Нет карты с названием {comboBoxSelectorMap.Text}");
|
||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if(textBoxNewMapName.Text.Contains('|') || textBoxNewMapName.Text.Contains(':') || textBoxNewMapName.Text.Contains(';'))
|
||||
{
|
||||
_logger.LogInformation("Присутствуют символы, недопустимые для имени карты");
|
||||
MessageBox.Show("Присутствуют символы, недопустимые для имени карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||
ReloadMaps();
|
||||
_logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
_logger.LogInformation($"Текущая карта сменена на {listBoxMaps.SelectedItem?.ToString() ?? string.Empty}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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);
|
||||
ReloadMaps();
|
||||
_logger.LogInformation($"Удалена карта {listBoxMaps.SelectedItem?.ToString() ?? string.Empty}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
_logger.LogInformation($"Успешное сохранение по пути {saveFileDialog.FileName}");
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning($"Не удалось сохранить данные. Ошибка - {ex.Message}");
|
||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if(openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||
ReloadMaps();
|
||||
_logger.LogInformation($"Успешная загрузка по пути {openFileDialog.FileName}");
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning($"Не удалось загрузить данные. Ошибка - {ex.Message}");
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка по типу
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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();
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка по цвету
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>125, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>265, 17</value>
|
||||
</metadata>
|
||||
</root>
|
45
WarmlyLocomotive/WarmlyLocomotive/IDrawningObject.cs
Normal file
45
WarmlyLocomotive/WarmlyLocomotive/IDrawningObject.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
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();
|
||||
/// <summary>
|
||||
/// Получение информации по объекту
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string GetInfo();
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
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 DrawningObjectLocomotive;
|
||||
var yLocomotive = y as DrawningObjectLocomotive;
|
||||
if (xLocomotive == null && yLocomotive == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xLocomotive == null && yLocomotive != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xLocomotive != null && yLocomotive == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xEntityLocomotive = xLocomotive.GetLocomotive.Locomotive;
|
||||
var yEntityLocomotive = yLocomotive.GetLocomotive.Locomotive;
|
||||
var baseColorCompare = xEntityLocomotive.BodyColor.ToArgb().CompareTo(yEntityLocomotive.BodyColor.ToArgb());
|
||||
if(baseColorCompare != 0)
|
||||
{
|
||||
return baseColorCompare;
|
||||
}
|
||||
if(xEntityLocomotive is EntityWarmlyLocomotive xWarmlyLocomotive && yEntityLocomotive is EntityWarmlyLocomotive yWarmlyLocomotive)
|
||||
{
|
||||
var dopColorCompare = xWarmlyLocomotive.DopColor.ToArgb().CompareTo(yWarmlyLocomotive.DopColor.ToArgb());
|
||||
if (dopColorCompare != 0)
|
||||
{
|
||||
return dopColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = xLocomotive.GetLocomotive.Locomotive.Speed.CompareTo(yLocomotive.GetLocomotive.Locomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xLocomotive.GetLocomotive.Locomotive.Weight.CompareTo(yLocomotive.GetLocomotive.Locomotive.Weight);
|
||||
}
|
||||
}
|
||||
}
|
55
WarmlyLocomotive/WarmlyLocomotive/LocomotiveCompareByType.cs
Normal file
55
WarmlyLocomotive/WarmlyLocomotive/LocomotiveCompareByType.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
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 DrawningObjectLocomotive;
|
||||
var yLocomotive = y as DrawningObjectLocomotive;
|
||||
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.Locomotive.Speed.CompareTo(yLocomotive.GetLocomotive.Locomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xLocomotive.GetLocomotive.Locomotive.Weight.CompareTo(yLocomotive.GetLocomotive.Locomotive.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
[Serializable]
|
||||
internal class LocomotiveNotFoundException : ApplicationException
|
||||
{
|
||||
public LocomotiveNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public LocomotiveNotFoundException() : base() { }
|
||||
public LocomotiveNotFoundException(string message) : base(message) { }
|
||||
public LocomotiveNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected LocomotiveNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class MapWithSetLocomotivesGeneric<T, U>
|
||||
where T : class, IDrawningObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 120;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetLocomotivesGeneric<T> _setLocomotives;
|
||||
/// <summary>
|
||||
/// Карта
|
||||
/// </summary>
|
||||
private readonly U _map;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="map"></param>
|
||||
public MapWithSetLocomotivesGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / (_placeSizeWidth + 30);
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setLocomotives = new SetLocomotivesGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="locomotive"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(MapWithSetLocomotivesGeneric<T, U> map, T locomotive)
|
||||
{
|
||||
return map._setLocomotives.Insert(locomotive);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public static T operator -(MapWithSetLocomotivesGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setLocomotives.Remove(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawLocomotives(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Просмотр объекта на карте
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение объекта по крате
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных в виде строки
|
||||
/// </summary>
|
||||
/// <param name="sep"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка списка из массива строк
|
||||
/// </summary>
|
||||
/// <param name="records"></param>
|
||||
public void LoadData(string[] records)
|
||||
{
|
||||
foreach (var rec in records)
|
||||
{
|
||||
_setLocomotives.Insert(DrawningObjectLocomotive.Create(rec) as T);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setLocomotives.SortSet(comparer);
|
||||
}
|
||||
/// <summary>
|
||||
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
Pen penTwo = new(Color.Black, 2);
|
||||
Brush brushLightGray = new SolidBrush(Color.LightGray);
|
||||
Brush brushBrown = new SolidBrush(Color.Brown);
|
||||
g.FillRectangle(brushLightGray, 0, 0, _pictureWidth, _pictureHeight);
|
||||
int placesInRow = _pictureWidth / (_placeSizeWidth + 30);
|
||||
for (int i = 0; i < placesInRow; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{//линия рамзетки места
|
||||
if (j != 0)
|
||||
{
|
||||
int xForRail = i * (_placeSizeWidth + 30);
|
||||
g.DrawLine(penTwo, xForRail, j * _placeSizeHeight, xForRail + _placeSizeWidth - 20, j * _placeSizeHeight);
|
||||
g.DrawLine(penTwo, xForRail, j * _placeSizeHeight - 20, xForRail + _placeSizeWidth - 20, j * _placeSizeHeight - 20);
|
||||
for (int k = 0; k < (_placeSizeWidth - 20) / 15; ++k)
|
||||
{
|
||||
g.FillRectangle(brushBrown, xForRail, j * _placeSizeHeight - 20, 5, 20);
|
||||
xForRail += 15;
|
||||
}
|
||||
}
|
||||
g.DrawLine(pen, i * (_placeSizeWidth + 30), j * _placeSizeHeight + 10, i * (_placeSizeWidth + 30) + _placeSizeWidth / 2, j * _placeSizeHeight + 10);
|
||||
}
|
||||
g.DrawLine(pen, i * (_placeSizeWidth + 30), 10, i * (_placeSizeWidth + 30), (_pictureHeight / _placeSizeHeight) * _placeSizeHeight + 10);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawLocomotives(Graphics g)
|
||||
{
|
||||
int xForLocomotive = 2;
|
||||
int yForLocomotive = 10;
|
||||
int countInRow = 0;
|
||||
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||
{
|
||||
if (countInRow >= _pictureWidth / (_placeSizeWidth + 30))
|
||||
{
|
||||
xForLocomotive = 2;
|
||||
yForLocomotive += _placeSizeHeight;
|
||||
countInRow = 0;
|
||||
}
|
||||
if (locomotive != null)
|
||||
{
|
||||
locomotive.SetObject(xForLocomotive, yForLocomotive, _pictureWidth, _pictureHeight);
|
||||
locomotive.DrawningObject(g);
|
||||
}
|
||||
xForLocomotive += _placeSizeWidth + 30;
|
||||
countInRow++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
154
WarmlyLocomotive/WarmlyLocomotive/MapsCollection.cs
Normal file
154
WarmlyLocomotive/WarmlyLocomotive/MapsCollection.cs
Normal file
@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции карт
|
||||
/// </summary>
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по элементу словаря в файл
|
||||
/// </summary>
|
||||
private readonly char separatorDict = '|';
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char separatorData = ';';
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (!_mapStorages.ContainsKey(name))
|
||||
{
|
||||
_mapStorages.Add(name, new MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(string name)
|
||||
{
|
||||
if (_mapStorages.ContainsKey(name))
|
||||
{
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к депо
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ind != String.Empty)
|
||||
{
|
||||
MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap> value;
|
||||
if (_mapStorages.TryGetValue(ind, out value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение информации по локомотивам в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns></returns>
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
using (StreamWriter sw = new(filename))
|
||||
{
|
||||
sw.Write($"MapsCollection{Environment.NewLine}");
|
||||
foreach (var storage in _mapStorages)
|
||||
{
|
||||
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка информации по локомотивам в депо из файла
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
string str = sr.ReadLine();
|
||||
if (!str.Contains("MapsCollection"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new FileFormatException("Формат данных в файле не правильный");
|
||||
}
|
||||
_mapStorages.Clear();
|
||||
while ((str = sr.ReadLine()) != null)
|
||||
{
|
||||
var elem = str.Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "BigBarriersMap":
|
||||
map = new BigBarriersMap();
|
||||
break;
|
||||
case "CirclesMap":
|
||||
map = new CirclesMap();
|
||||
break;
|
||||
}
|
||||
_mapStorages.Add(elem[0], new MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using Serilog;
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal static class Program
|
||||
@ -11,7 +16,25 @@ namespace WarmlyLocomotive
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
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 serilogLogger = new LoggerConfiguration()
|
||||
.WriteTo.File("LogOfProgram.txt")
|
||||
.CreateLogger();
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(serilogLogger, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
127
WarmlyLocomotive/WarmlyLocomotive/SetLocomotivesGeneric.cs
Normal file
127
WarmlyLocomotive/WarmlyLocomotive/SetLocomotivesGeneric.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class SetLocomotivesGeneric<T>
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в списке
|
||||
/// </summary>
|
||||
public int Count => _places.Count;
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetLocomotivesGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="locomotive">Добавляемый локомотив</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T locomotive)
|
||||
{
|
||||
return Insert(locomotive, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="locomotive">Добавляемый локомотив</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T locomotive, int position)
|
||||
{
|
||||
if (_places.Contains(locomotive))
|
||||
{
|
||||
throw new ArgumentException($"Объект {locomotive} уже присутствует в наборе");
|
||||
}
|
||||
if (position < 0 || position > Count || _maxCount == Count)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
_places.Insert(position, locomotive);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
throw new LocomotiveNotFoundException(position);
|
||||
}
|
||||
T memoryObj = _places[position];
|
||||
_places.RemoveAt(position);
|
||||
return memoryObj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position >= 0 && position < Count)
|
||||
{
|
||||
return _places[position];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position >= 0 && position < Count)
|
||||
{
|
||||
_places[position] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по набору до первого пустого
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetLocomotives()
|
||||
{
|
||||
foreach (var locomotive in _places)
|
||||
{
|
||||
if (locomotive != null)
|
||||
{
|
||||
yield return locomotive;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка набора объектов
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
52
WarmlyLocomotive/WarmlyLocomotive/SimpleMap.cs
Normal file
52
WarmlyLocomotive/WarmlyLocomotive/SimpleMap.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
[Serializable]
|
||||
internal class StorageOverflowException: ApplicationException
|
||||
{
|
||||
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||
public StorageOverflowException() : base() { }
|
||||
public StorageOverflowException(string message) : base(message) { }
|
||||
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -8,6 +8,15 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
Loading…
Reference in New Issue
Block a user