Compare commits
24 Commits
master
...
6b7a6625db
Author | SHA1 | Date | |
---|---|---|---|
6b7a6625db | |||
58fce94948 | |||
f4a5cc3dd2 | |||
f755c40397 | |||
a9d7e440cc | |||
40da0fe01d | |||
ca917f0511 | |||
e1b431152b | |||
d3ec22f37a | |||
498cac4088 | |||
5f94bebf54 | |||
966de1e561 | |||
a2333c47e3 | |||
c3c543ae46 | |||
45bf8f801a | |||
b740601834 | |||
91a3a29949 | |||
f2a5a88b78 | |||
c3947c5007 | |||
65330aaf57 | |||
0991e91205 | |||
760ccf3570 | |||
fc639a1deb | |||
da86c334a4 |
168
Locomotive/Locomotive/AbstractMap.cs
Normal file
168
Locomotive/Locomotive/AbstractMap.cs
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal abstract class 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(); // abstract void
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
bool isFree = true;
|
||||||
|
|
||||||
|
int startPosX = (int)(_drawningObject.GetCurrentPosition().Left / _size_x);
|
||||||
|
int startPosY = (int)(_drawningObject.GetCurrentPosition().Top / _size_y);
|
||||||
|
|
||||||
|
int objectWidth = (int)(_drawningObject.GetCurrentPosition().Right / _size_x);
|
||||||
|
int objectHeight = (int)(_drawningObject.GetCurrentPosition().Bottom / _size_y);
|
||||||
|
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Direction.Right:
|
||||||
|
for (int i = objectWidth; i <= objectWidth + (int)(_drawningObject.Step / _size_x); i++)
|
||||||
|
{
|
||||||
|
for (int j = startPosY; j <= objectHeight; j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
isFree = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Direction.Left:
|
||||||
|
for (int i = startPosX; i >= (int)(_drawningObject.Step / _size_x); i--)
|
||||||
|
{
|
||||||
|
for (int j = startPosY; j <= objectHeight; j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
isFree = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Direction.Up:
|
||||||
|
for (int i = startPosX; i <= objectWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = startPosY; j >= (int)(_drawningObject.Step / _size_y); j--)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
isFree = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Direction.Down:
|
||||||
|
for (int i = startPosX; i <= objectWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = objectHeight; j <= objectHeight + (int)(_drawningObject.Step / _size_y); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
isFree = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (isFree)
|
||||||
|
{
|
||||||
|
_drawningObject.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool SetObjectOnMap()
|
||||||
|
{
|
||||||
|
if (_drawningObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int x = _random.Next(0, 10);
|
||||||
|
int y = _random.Next(0, 10);
|
||||||
|
_drawningObject.SetObject(x, y, _width, _height);
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
if (i * _size_x >= x && j * _size_y >= y &&
|
||||||
|
i * _size_x <= x + _drawningObject.GetCurrentPosition().Right &&
|
||||||
|
j * _size_y <= j + _drawningObject.GetCurrentPosition().Bottom)
|
||||||
|
{
|
||||||
|
if (_map[i,j] == _barrier)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -7,8 +7,9 @@ using System.Threading.Tasks;
|
|||||||
namespace Locomotive
|
namespace Locomotive
|
||||||
{
|
{
|
||||||
//Направление перемещения
|
//Направление перемещения
|
||||||
internal enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
|
None = 0,
|
||||||
Up = 1,
|
Up = 1,
|
||||||
Down = 2,
|
Down = 2,
|
||||||
Left = 3,
|
Left = 3,
|
||||||
|
@ -7,14 +7,14 @@ using System.Threading.Tasks;
|
|||||||
namespace Locomotive
|
namespace Locomotive
|
||||||
{
|
{
|
||||||
//Класс, отвечающий за отрисовку
|
//Класс, отвечающий за отрисовку
|
||||||
internal class DrawningLocomotive
|
public class DrawningLocomotive
|
||||||
{
|
{
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
public EntityLocomotive Locomotive { get; private set; }
|
public EntityLocomotive Locomotive { get; protected set; }
|
||||||
/// Левая координата отрисовки локомотива
|
/// Левая координата отрисовки локомотива
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
/// Верхняя координата отрисовки локомотива
|
/// Верхняя координата отрисовки локомотива
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
private int? _pictureWidth = null;
|
private int? _pictureWidth = null;
|
||||||
/// Высота окна отрисовки
|
/// Высота окна отрисовки
|
||||||
@ -25,11 +25,34 @@ namespace Locomotive
|
|||||||
private readonly int _locomotiveHeight = 50;
|
private readonly int _locomotiveHeight = 50;
|
||||||
|
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
public void Init(int speed, float weight, Color bodyColor, EntityLocomotive entity)
|
public DrawningLocomotive(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Locomotive = entity;
|
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||||
Locomotive.Init(speed, weight, bodyColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Новый конструктор
|
||||||
|
protected DrawningLocomotive (int speed, float weight, Color bodyColor, int locomotiveWidth, int locomotiveHeight)
|
||||||
|
: this (speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
_locomotiveWidth = locomotiveWidth;
|
||||||
|
_locomotiveHeight = locomotiveHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetBaseColor(Color color)
|
||||||
|
{
|
||||||
|
if (Locomotive is EntityWarmlyLocomotive)
|
||||||
|
{
|
||||||
|
var locomotive = Locomotive as EntityWarmlyLocomotive;
|
||||||
|
if (locomotive is not null)
|
||||||
|
{
|
||||||
|
locomotive = new EntityWarmlyLocomotive(locomotive.Speed, locomotive.Weight, color, locomotive.ExtraColor, locomotive.Pipe, locomotive.FuelStorage);
|
||||||
|
Locomotive = locomotive;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Locomotive = new EntityLocomotive(Locomotive.Speed, Locomotive.Weight, color);
|
||||||
|
}
|
||||||
|
|
||||||
/// Установка позиции локомотива
|
/// Установка позиции локомотива
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
@ -90,7 +113,7 @@ namespace Locomotive
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
@ -99,18 +122,18 @@ namespace Locomotive
|
|||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
//тело
|
//тело
|
||||||
g.DrawRectangle(pen, _startPosX , _startPosY, _locomotiveWidth - 10, _locomotiveHeight - 10);
|
g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Brown), _startPosX , _startPosY, 110 - 10, 50 - 10);
|
||||||
//окна
|
//окна
|
||||||
g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 10, _startPosY + 10, 10, 10);
|
g.FillRectangle(new SolidBrush(Color.Blue), _startPosX + 10, _startPosY + 10, 10, 10);
|
||||||
g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 30, _startPosY + 10, 10, 10);
|
g.FillRectangle(new SolidBrush(Color.Blue), _startPosX + 30, _startPosY + 10, 10, 10);
|
||||||
g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 80, _startPosY + 10, 10, 10);
|
g.FillRectangle(new SolidBrush(Color.Blue), _startPosX + 80, _startPosY + 10, 10, 10);
|
||||||
//дверь
|
//дверь
|
||||||
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 10, 10, 20);
|
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 10, 10, 20);
|
||||||
//колеса
|
//колеса
|
||||||
g.DrawEllipse(pen, _startPosX, _startPosY + 40, 10, 10);
|
g.FillEllipse(new SolidBrush(Color.Black), _startPosX, _startPosY + 40, 10, 10);
|
||||||
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 40, 10, 10);
|
g.FillEllipse(new SolidBrush(Color.Black), _startPosX + 20, _startPosY + 40, 10, 10);
|
||||||
g.DrawEllipse(pen, _startPosX + 70, _startPosY + 40, 10, 10);
|
g.FillEllipse(new SolidBrush(Color.Black), _startPosX + 70, _startPosY + 40, 10, 10);
|
||||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 10, 10);
|
g.FillEllipse(new SolidBrush(Color.Black), _startPosX + 90, _startPosY + 40, 10, 10);
|
||||||
//черный прямоугольник
|
//черный прямоугольник
|
||||||
g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 100, _startPosY + 10, 10, 30);
|
g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 100, _startPosY + 10, 10, 30);
|
||||||
}
|
}
|
||||||
@ -134,5 +157,10 @@ namespace Locomotive
|
|||||||
_startPosY = _pictureHeight.Value - _locomotiveHeight;
|
_startPosY = _pictureHeight.Value - _locomotiveHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Получение текущей позиции объекта
|
||||||
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return (_startPosX, _startPosX + _locomotiveWidth, _startPosY, _startPosY + _locomotiveHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
Locomotive/Locomotive/DrawningObjectLocomotive.cs
Normal file
41
Locomotive/Locomotive/DrawningObjectLocomotive.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class DrawningObjectLocomotive : IDrawningObject
|
||||||
|
{
|
||||||
|
private DrawningLocomotive _locomotive = null;
|
||||||
|
|
||||||
|
public DrawningObjectLocomotive(DrawningLocomotive locomotive)
|
||||||
|
{
|
||||||
|
_locomotive = locomotive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Step => _locomotive?.Locomotive?.Step ?? 0;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
62
Locomotive/Locomotive/DrawningWarmlyLocomotive.cs
Normal file
62
Locomotive/Locomotive/DrawningWarmlyLocomotive.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class DrawningWarmlyLocomotive : DrawningLocomotive
|
||||||
|
{
|
||||||
|
public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, Color extraColor, bool pipe, bool storage)
|
||||||
|
: base(speed, weight, bodyColor, locomotiveWidth: 130, locomotiveHeight: 70)
|
||||||
|
{
|
||||||
|
Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetExtraColor(Color color)
|
||||||
|
{
|
||||||
|
var LocomotiveWarmly = Locomotive as EntityWarmlyLocomotive;
|
||||||
|
if (LocomotiveWarmly is not null)
|
||||||
|
{
|
||||||
|
LocomotiveWarmly = new EntityWarmlyLocomotive(LocomotiveWarmly.Speed, LocomotiveWarmly.Weight, LocomotiveWarmly.BodyColor, color, LocomotiveWarmly.Pipe, LocomotiveWarmly.FuelStorage);
|
||||||
|
Locomotive = LocomotiveWarmly;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Locomotive is not EntityWarmlyLocomotive warmlyLocomotive)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush extraBrush = new SolidBrush(warmlyLocomotive.ExtraColor);
|
||||||
|
|
||||||
|
|
||||||
|
if (warmlyLocomotive.FuelStorage)
|
||||||
|
{
|
||||||
|
g.FillRectangle(extraBrush, _startPosX + 10, _startPosY, 30, 20);
|
||||||
|
g.FillRectangle(extraBrush, _startPosX + 60, _startPosY, 20, 20);
|
||||||
|
g.FillRectangle(extraBrush, _startPosX + 60, _startPosY + 10, 30, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warmlyLocomotive.Pipe)
|
||||||
|
{
|
||||||
|
g.FillRectangle(extraBrush, _startPosX + 110, _startPosY + 10, 10, 50);
|
||||||
|
g.FillRectangle(extraBrush, _startPosX + 110, _startPosY + 40, 20, 20);
|
||||||
|
g.FillRectangle(extraBrush, _startPosX + 100, _startPosY, 30, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
_startPosY += 20;
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
_startPosY -= 20;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Locomotive
|
namespace Locomotive
|
||||||
{
|
{
|
||||||
internal class EntityLocomotive
|
public class EntityLocomotive
|
||||||
{
|
{
|
||||||
/// Скорость
|
/// Скорость
|
||||||
public int Speed { get; private set; }
|
public int Speed { get; private set; }
|
||||||
@ -17,7 +17,7 @@ namespace Locomotive
|
|||||||
/// Шаг перемещения локомотива
|
/// Шаг перемещения локомотива
|
||||||
public float Step => Speed * 100 / Weight;
|
public float Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public EntityLocomotive(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||||
|
28
Locomotive/Locomotive/EntityWarmlyLocomotive.cs
Normal file
28
Locomotive/Locomotive/EntityWarmlyLocomotive.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class EntityWarmlyLocomotive : EntityLocomotive
|
||||||
|
{
|
||||||
|
//доп. цвет
|
||||||
|
public Color ExtraColor { get; private set; }
|
||||||
|
//признак наличия трубы
|
||||||
|
public bool Pipe { get; private set; }
|
||||||
|
//признак наличия отсека под топливо
|
||||||
|
public bool FuelStorage { get; private set; }
|
||||||
|
|
||||||
|
public EntityWarmlyLocomotive (int speed, float weight, Color bodyColor, Color extraColor, bool pipe, bool fuelStorage)
|
||||||
|
: base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
ExtraColor = extraColor;
|
||||||
|
Pipe = pipe;
|
||||||
|
FuelStorage = fuelStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
27
Locomotive/Locomotive/FormLocomotive.Designer.cs
generated
27
Locomotive/Locomotive/FormLocomotive.Designer.cs
generated
@ -38,6 +38,8 @@
|
|||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCreateModified = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSelectLocomotive = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -51,7 +53,6 @@
|
|||||||
this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
this.pictureBoxLocomotive.TabIndex = 0;
|
this.pictureBoxLocomotive.TabIndex = 0;
|
||||||
this.pictureBoxLocomotive.TabStop = false;
|
this.pictureBoxLocomotive.TabStop = false;
|
||||||
|
|
||||||
this.pictureBoxLocomotive.Resize += new System.EventHandler(this.pictureBoxLocomotive_Resize);
|
this.pictureBoxLocomotive.Resize += new System.EventHandler(this.pictureBoxLocomotive_Resize);
|
||||||
//
|
//
|
||||||
// statusStrip1
|
// statusStrip1
|
||||||
@ -144,11 +145,33 @@
|
|||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
|
// buttonCreateModified
|
||||||
|
//
|
||||||
|
this.buttonCreateModified.Location = new System.Drawing.Point(112, 377);
|
||||||
|
this.buttonCreateModified.Name = "buttonCreateModified";
|
||||||
|
this.buttonCreateModified.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonCreateModified.TabIndex = 7;
|
||||||
|
this.buttonCreateModified.Text = "Modified";
|
||||||
|
this.buttonCreateModified.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModified.Click += new System.EventHandler(this.buttonCreateModified_Click);
|
||||||
|
//
|
||||||
|
// buttonSelectLocomotive
|
||||||
|
//
|
||||||
|
this.buttonSelectLocomotive.Location = new System.Drawing.Point(507, 377);
|
||||||
|
this.buttonSelectLocomotive.Name = "buttonSelectLocomotive";
|
||||||
|
this.buttonSelectLocomotive.Size = new System.Drawing.Size(105, 29);
|
||||||
|
this.buttonSelectLocomotive.TabIndex = 8;
|
||||||
|
this.buttonSelectLocomotive.Text = "Select";
|
||||||
|
this.buttonSelectLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSelectLocomotive.Click += new System.EventHandler(this.buttonSelectLocomotive_Click);
|
||||||
|
//
|
||||||
// FormLocomotive
|
// FormLocomotive
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(778, 442);
|
this.ClientSize = new System.Drawing.Size(778, 442);
|
||||||
|
this.Controls.Add(this.buttonSelectLocomotive);
|
||||||
|
this.Controls.Add(this.buttonCreateModified);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
@ -178,5 +201,7 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
private Button buttonCreateModified;
|
||||||
|
private Button buttonSelectLocomotive;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ namespace Locomotive
|
|||||||
public partial class FormLocomotive : Form
|
public partial class FormLocomotive : Form
|
||||||
{
|
{
|
||||||
private DrawningLocomotive _locomotive;
|
private DrawningLocomotive _locomotive;
|
||||||
private EntityLocomotive _entity;
|
public DrawningLocomotive SelectedLocomotive { get; private set; }
|
||||||
|
|
||||||
public FormLocomotive()
|
public FormLocomotive()
|
||||||
{
|
{
|
||||||
@ -19,19 +19,27 @@ namespace Locomotive
|
|||||||
pictureBoxLocomotive.Image = bmp;
|
pictureBoxLocomotive.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void SetData()
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
|
||||||
_locomotive = new DrawningLocomotive();
|
|
||||||
_entity = new EntityLocomotive();
|
|
||||||
_locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), _entity);
|
|
||||||
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
|
||||||
toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}";
|
toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}";
|
||||||
toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}";
|
toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}";
|
||||||
Draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||||
|
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
//ïîëó÷àåì èìÿ êíîïêè
|
//ïîëó÷àåì èìÿ êíîïêè
|
||||||
@ -59,5 +67,39 @@ namespace Locomotive
|
|||||||
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonCreateModified_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)));
|
||||||
|
|
||||||
|
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSelectLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedLocomotive = _locomotive;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
361
Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs
generated
Normal file
361
Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs
generated
Normal file
@ -0,0 +1,361 @@
|
|||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
partial class FormLocomotiveConfig
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.groupBoxConfig = new System.Windows.Forms.GroupBox();
|
||||||
|
this.labelModifiedObject = new System.Windows.Forms.Label();
|
||||||
|
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||||
|
this.groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||||
|
this.panelPurple = new System.Windows.Forms.Panel();
|
||||||
|
this.panelBlack = new System.Windows.Forms.Panel();
|
||||||
|
this.panelGray = new System.Windows.Forms.Panel();
|
||||||
|
this.panelWhite = new System.Windows.Forms.Panel();
|
||||||
|
this.panelYellow = new System.Windows.Forms.Panel();
|
||||||
|
this.panelGreen = new System.Windows.Forms.Panel();
|
||||||
|
this.panelBlue = new System.Windows.Forms.Panel();
|
||||||
|
this.panelRed = new System.Windows.Forms.Panel();
|
||||||
|
this.checkBoxFuelStorage = new System.Windows.Forms.CheckBox();
|
||||||
|
this.checkBoxPipe = new System.Windows.Forms.CheckBox();
|
||||||
|
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.labelWeight = new System.Windows.Forms.Label();
|
||||||
|
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.labelSpeed = new System.Windows.Forms.Label();
|
||||||
|
this.panelObject = new System.Windows.Forms.Panel();
|
||||||
|
this.labelDopColor = new System.Windows.Forms.Label();
|
||||||
|
this.labelBaseColor = new System.Windows.Forms.Label();
|
||||||
|
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.groupBoxConfig.SuspendLayout();
|
||||||
|
this.groupBoxColors.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||||
|
this.panelObject.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxConfig
|
||||||
|
//
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.checkBoxFuelStorage);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.checkBoxPipe);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelWeight);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelSpeed);
|
||||||
|
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.groupBoxConfig.Name = "groupBoxConfig";
|
||||||
|
this.groupBoxConfig.Size = new System.Drawing.Size(453, 260);
|
||||||
|
this.groupBoxConfig.TabIndex = 0;
|
||||||
|
this.groupBoxConfig.TabStop = false;
|
||||||
|
this.groupBoxConfig.Text = "Configuration";
|
||||||
|
//
|
||||||
|
// labelModifiedObject
|
||||||
|
//
|
||||||
|
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelModifiedObject.Location = new System.Drawing.Point(312, 200);
|
||||||
|
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||||
|
this.labelModifiedObject.Size = new System.Drawing.Size(115, 45);
|
||||||
|
this.labelModifiedObject.TabIndex = 8;
|
||||||
|
this.labelModifiedObject.Text = "Modified";
|
||||||
|
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(179, 200);
|
||||||
|
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||||
|
this.labelSimpleObject.Size = new System.Drawing.Size(115, 45);
|
||||||
|
this.labelSimpleObject.TabIndex = 7;
|
||||||
|
this.labelSimpleObject.Text = "Simple";
|
||||||
|
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// groupBoxColors
|
||||||
|
//
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelPurple);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelBlack);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelGray);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelWhite);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelYellow);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelBlue);
|
||||||
|
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||||
|
this.groupBoxColors.Location = new System.Drawing.Point(179, 26);
|
||||||
|
this.groupBoxColors.Name = "groupBoxColors";
|
||||||
|
this.groupBoxColors.Size = new System.Drawing.Size(248, 156);
|
||||||
|
this.groupBoxColors.TabIndex = 6;
|
||||||
|
this.groupBoxColors.TabStop = false;
|
||||||
|
this.groupBoxColors.Text = "Colors";
|
||||||
|
//
|
||||||
|
// panelPurple
|
||||||
|
//
|
||||||
|
this.panelPurple.BackColor = System.Drawing.Color.Fuchsia;
|
||||||
|
this.panelPurple.Location = new System.Drawing.Point(193, 102);
|
||||||
|
this.panelPurple.Name = "panelPurple";
|
||||||
|
this.panelPurple.Size = new System.Drawing.Size(43, 40);
|
||||||
|
this.panelPurple.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// panelBlack
|
||||||
|
//
|
||||||
|
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||||
|
this.panelBlack.Location = new System.Drawing.Point(132, 102);
|
||||||
|
this.panelBlack.Name = "panelBlack";
|
||||||
|
this.panelBlack.Size = new System.Drawing.Size(43, 40);
|
||||||
|
this.panelBlack.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// panelGray
|
||||||
|
//
|
||||||
|
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||||
|
this.panelGray.Location = new System.Drawing.Point(72, 102);
|
||||||
|
this.panelGray.Name = "panelGray";
|
||||||
|
this.panelGray.Size = new System.Drawing.Size(43, 40);
|
||||||
|
this.panelGray.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// panelWhite
|
||||||
|
//
|
||||||
|
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||||
|
this.panelWhite.Location = new System.Drawing.Point(11, 102);
|
||||||
|
this.panelWhite.Name = "panelWhite";
|
||||||
|
this.panelWhite.Size = new System.Drawing.Size(43, 40);
|
||||||
|
this.panelWhite.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// panelYellow
|
||||||
|
//
|
||||||
|
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||||
|
this.panelYellow.Location = new System.Drawing.Point(193, 31);
|
||||||
|
this.panelYellow.Name = "panelYellow";
|
||||||
|
this.panelYellow.Size = new System.Drawing.Size(43, 40);
|
||||||
|
this.panelYellow.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelGreen
|
||||||
|
//
|
||||||
|
this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
|
||||||
|
this.panelGreen.Location = new System.Drawing.Point(72, 31);
|
||||||
|
this.panelGreen.Name = "panelGreen";
|
||||||
|
this.panelGreen.Size = new System.Drawing.Size(43, 40);
|
||||||
|
this.panelGreen.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelBlue
|
||||||
|
//
|
||||||
|
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||||
|
this.panelBlue.Location = new System.Drawing.Point(133, 31);
|
||||||
|
this.panelBlue.Name = "panelBlue";
|
||||||
|
this.panelBlue.Size = new System.Drawing.Size(43, 40);
|
||||||
|
this.panelBlue.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelRed
|
||||||
|
//
|
||||||
|
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||||
|
this.panelRed.Location = new System.Drawing.Point(11, 31);
|
||||||
|
this.panelRed.Name = "panelRed";
|
||||||
|
this.panelRed.Size = new System.Drawing.Size(43, 40);
|
||||||
|
this.panelRed.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// checkBoxFuelStorage
|
||||||
|
//
|
||||||
|
this.checkBoxFuelStorage.AutoSize = true;
|
||||||
|
this.checkBoxFuelStorage.Location = new System.Drawing.Point(7, 158);
|
||||||
|
this.checkBoxFuelStorage.Name = "checkBoxFuelStorage";
|
||||||
|
this.checkBoxFuelStorage.Size = new System.Drawing.Size(146, 24);
|
||||||
|
this.checkBoxFuelStorage.TabIndex = 5;
|
||||||
|
this.checkBoxFuelStorage.Text = "Add Fuel Storage";
|
||||||
|
this.checkBoxFuelStorage.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxPipe
|
||||||
|
//
|
||||||
|
this.checkBoxPipe.AutoSize = true;
|
||||||
|
this.checkBoxPipe.Location = new System.Drawing.Point(7, 128);
|
||||||
|
this.checkBoxPipe.Name = "checkBoxPipe";
|
||||||
|
this.checkBoxPipe.Size = new System.Drawing.Size(92, 24);
|
||||||
|
this.checkBoxPipe.TabIndex = 4;
|
||||||
|
this.checkBoxPipe.Text = "Add Pipe";
|
||||||
|
this.checkBoxPipe.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericUpDownWeight
|
||||||
|
//
|
||||||
|
this.numericUpDownWeight.Location = new System.Drawing.Point(75, 75);
|
||||||
|
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||||
|
this.numericUpDownWeight.Size = new System.Drawing.Size(68, 27);
|
||||||
|
this.numericUpDownWeight.TabIndex = 3;
|
||||||
|
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// labelWeight
|
||||||
|
//
|
||||||
|
this.labelWeight.AutoSize = true;
|
||||||
|
this.labelWeight.Location = new System.Drawing.Point(7, 77);
|
||||||
|
this.labelWeight.Name = "labelWeight";
|
||||||
|
this.labelWeight.Size = new System.Drawing.Size(63, 20);
|
||||||
|
this.labelWeight.TabIndex = 2;
|
||||||
|
this.labelWeight.Text = "Weight: ";
|
||||||
|
//
|
||||||
|
// numericUpDownSpeed
|
||||||
|
//
|
||||||
|
this.numericUpDownSpeed.Location = new System.Drawing.Point(74, 31);
|
||||||
|
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||||
|
this.numericUpDownSpeed.Size = new System.Drawing.Size(69, 27);
|
||||||
|
this.numericUpDownSpeed.TabIndex = 1;
|
||||||
|
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// labelSpeed
|
||||||
|
//
|
||||||
|
this.labelSpeed.AutoSize = true;
|
||||||
|
this.labelSpeed.Location = new System.Drawing.Point(6, 33);
|
||||||
|
this.labelSpeed.Name = "labelSpeed";
|
||||||
|
this.labelSpeed.Size = new System.Drawing.Size(62, 20);
|
||||||
|
this.labelSpeed.TabIndex = 0;
|
||||||
|
this.labelSpeed.Text = " Speed: ";
|
||||||
|
//
|
||||||
|
// 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(471, 22);
|
||||||
|
this.panelObject.Name = "panelObject";
|
||||||
|
this.panelObject.Size = new System.Drawing.Size(419, 250);
|
||||||
|
this.panelObject.TabIndex = 1;
|
||||||
|
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
|
||||||
|
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter);
|
||||||
|
//
|
||||||
|
// labelDopColor
|
||||||
|
//
|
||||||
|
this.labelDopColor.AllowDrop = true;
|
||||||
|
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelDopColor.Location = new System.Drawing.Point(232, 16);
|
||||||
|
this.labelDopColor.Name = "labelDopColor";
|
||||||
|
this.labelDopColor.Size = new System.Drawing.Size(115, 45);
|
||||||
|
this.labelDopColor.TabIndex = 9;
|
||||||
|
this.labelDopColor.Text = "Extra Color";
|
||||||
|
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(69, 16);
|
||||||
|
this.labelBaseColor.Name = "labelBaseColor";
|
||||||
|
this.labelBaseColor.Size = new System.Drawing.Size(115, 45);
|
||||||
|
this.labelBaseColor.TabIndex = 8;
|
||||||
|
this.labelBaseColor.Text = "Base Color";
|
||||||
|
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);
|
||||||
|
//
|
||||||
|
// pictureBoxObject
|
||||||
|
//
|
||||||
|
this.pictureBoxObject.Location = new System.Drawing.Point(16, 67);
|
||||||
|
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||||
|
this.pictureBoxObject.Size = new System.Drawing.Size(386, 168);
|
||||||
|
this.pictureBoxObject.TabIndex = 0;
|
||||||
|
this.pictureBoxObject.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(487, 278);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(168, 29);
|
||||||
|
this.buttonAdd.TabIndex = 2;
|
||||||
|
this.buttonAdd.Text = "Add";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(703, 278);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(170, 29);
|
||||||
|
this.buttonCancel.TabIndex = 3;
|
||||||
|
this.buttonCancel.Text = "Cancel";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormLocomotiveConfig
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(902, 315);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.panelObject);
|
||||||
|
this.Controls.Add(this.groupBoxConfig);
|
||||||
|
this.Name = "FormLocomotiveConfig";
|
||||||
|
this.Text = "Object Creation";
|
||||||
|
this.groupBoxConfig.ResumeLayout(false);
|
||||||
|
this.groupBoxConfig.PerformLayout();
|
||||||
|
this.groupBoxColors.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||||
|
this.panelObject.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxConfig;
|
||||||
|
private NumericUpDown numericUpDownSpeed;
|
||||||
|
private Label labelSpeed;
|
||||||
|
private NumericUpDown numericUpDownWeight;
|
||||||
|
private Label labelWeight;
|
||||||
|
private CheckBox checkBoxFuelStorage;
|
||||||
|
private CheckBox checkBoxPipe;
|
||||||
|
private GroupBox groupBoxColors;
|
||||||
|
private Panel panelRed;
|
||||||
|
private Panel panelPurple;
|
||||||
|
private Panel panelBlack;
|
||||||
|
private Panel panelGray;
|
||||||
|
private Panel panelWhite;
|
||||||
|
private Panel panelYellow;
|
||||||
|
private Panel panelGreen;
|
||||||
|
private Panel panelBlue;
|
||||||
|
private Label labelSimpleObject;
|
||||||
|
private Label labelModifiedObject;
|
||||||
|
private Panel panelObject;
|
||||||
|
private PictureBox pictureBoxObject;
|
||||||
|
private Label labelDopColor;
|
||||||
|
private Label labelBaseColor;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
146
Locomotive/Locomotive/FormLocomotiveConfig.cs
Normal file
146
Locomotive/Locomotive/FormLocomotiveConfig.cs
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
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 Locomotive
|
||||||
|
{
|
||||||
|
public partial class FormLocomotiveConfig : Form
|
||||||
|
{
|
||||||
|
DrawningLocomotive _locomotive = null;
|
||||||
|
|
||||||
|
private event LocomotiveDelegate eventAddLocomotive;
|
||||||
|
|
||||||
|
public void AddEvent(LocomotiveDelegate ev)
|
||||||
|
{
|
||||||
|
if (eventAddLocomotive == null)
|
||||||
|
{
|
||||||
|
eventAddLocomotive = new LocomotiveDelegate(ev);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eventAddLocomotive += ev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
eventAddLocomotive?.Invoke(_locomotive);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormLocomotiveConfig()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelGray.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelRed.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||||
|
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||||
|
|
||||||
|
// ! - TODO buttonCancel.Click with lambda
|
||||||
|
buttonCancel.Click += (object sender, EventArgs e) => Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelObject_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void panelObject_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(DataFormats.Text))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void panelObject_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
switch (e.Data.GetData(DataFormats.Text).ToString())
|
||||||
|
{
|
||||||
|
case "labelSimpleObject":
|
||||||
|
_locomotive = new DrawningLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
|
||||||
|
break;
|
||||||
|
case "labelModifiedObject":
|
||||||
|
_locomotive = new DrawningWarmlyLocomotive((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
|
||||||
|
Color.White, Color.Black,
|
||||||
|
checkBoxPipe.Checked, checkBoxFuelStorage.Checked);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawLocomotive();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawLocomotive()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_locomotive?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
_locomotive?.DrawTransport(gr);
|
||||||
|
pictureBoxObject.Image = bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelBaseColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
// ! - TODO Call method from object _car and set color
|
||||||
|
|
||||||
|
_locomotive.SetBaseColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
DrawLocomotive();
|
||||||
|
|
||||||
|
}
|
||||||
|
private void labelDopColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
// ! - TODO
|
||||||
|
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
// ! - TODO
|
||||||
|
if (_locomotive is DrawningWarmlyLocomotive)
|
||||||
|
{
|
||||||
|
var locomotive = _locomotive as DrawningWarmlyLocomotive;
|
||||||
|
locomotive.SetExtraColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
}
|
||||||
|
DrawLocomotive();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
60
Locomotive/Locomotive/FormLocomotiveConfig.resx
Normal file
60
Locomotive/Locomotive/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>
|
275
Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs
generated
Normal file
275
Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs
generated
Normal file
@ -0,0 +1,275 @@
|
|||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
partial class FormMapWithSetLocomotives
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||||
|
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||||
|
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||||
|
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
|
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||||
|
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRemoveLocomotive = new System.Windows.Forms.Button();
|
||||||
|
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.buttonAddLocomotive = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.groupBoxTools.SuspendLayout();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
this.groupBoxTools.Controls.Add(this.groupBox1);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonRemoveLocomotive);
|
||||||
|
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonAddLocomotive);
|
||||||
|
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
|
this.groupBoxTools.Location = new System.Drawing.Point(580, 0);
|
||||||
|
this.groupBoxTools.Name = "groupBoxTools";
|
||||||
|
this.groupBoxTools.Size = new System.Drawing.Size(220, 546);
|
||||||
|
this.groupBoxTools.TabIndex = 0;
|
||||||
|
this.groupBoxTools.TabStop = false;
|
||||||
|
this.groupBoxTools.Text = "Tools";
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.buttonDeleteMap);
|
||||||
|
this.groupBox1.Controls.Add(this.listBoxMaps);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonAddMap);
|
||||||
|
this.groupBox1.Controls.Add(this.textBoxNewMapName);
|
||||||
|
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
|
||||||
|
this.groupBox1.Location = new System.Drawing.Point(6, 26);
|
||||||
|
this.groupBox1.Name = "groupBox1";
|
||||||
|
this.groupBox1.Size = new System.Drawing.Size(208, 250);
|
||||||
|
this.groupBox1.TabIndex = 8;
|
||||||
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "Maps";
|
||||||
|
//
|
||||||
|
// buttonDeleteMap
|
||||||
|
//
|
||||||
|
this.buttonDeleteMap.Location = new System.Drawing.Point(6, 198);
|
||||||
|
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||||
|
this.buttonDeleteMap.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.buttonDeleteMap.TabIndex = 3;
|
||||||
|
this.buttonDeleteMap.Text = "Delete Map";
|
||||||
|
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
|
||||||
|
//
|
||||||
|
// listBoxMaps
|
||||||
|
//
|
||||||
|
this.listBoxMaps.FormattingEnabled = true;
|
||||||
|
this.listBoxMaps.ItemHeight = 20;
|
||||||
|
this.listBoxMaps.Location = new System.Drawing.Point(6, 128);
|
||||||
|
this.listBoxMaps.Name = "listBoxMaps";
|
||||||
|
this.listBoxMaps.Size = new System.Drawing.Size(196, 64);
|
||||||
|
this.listBoxMaps.TabIndex = 2;
|
||||||
|
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// buttonAddMap
|
||||||
|
//
|
||||||
|
this.buttonAddMap.Location = new System.Drawing.Point(6, 93);
|
||||||
|
this.buttonAddMap.Name = "buttonAddMap";
|
||||||
|
this.buttonAddMap.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.buttonAddMap.TabIndex = 1;
|
||||||
|
this.buttonAddMap.Text = "Add Map";
|
||||||
|
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
|
||||||
|
//
|
||||||
|
// textBoxNewMapName
|
||||||
|
//
|
||||||
|
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 26);
|
||||||
|
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||||
|
this.textBoxNewMapName.Size = new System.Drawing.Size(196, 27);
|
||||||
|
this.textBoxNewMapName.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// comboBoxSelectorMap
|
||||||
|
//
|
||||||
|
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
|
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||||
|
"Simple Map",
|
||||||
|
"Spike Map",
|
||||||
|
"Rail Map"});
|
||||||
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 59);
|
||||||
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(196, 28);
|
||||||
|
this.comboBoxSelectorMap.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow;
|
||||||
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonLeft.Location = new System.Drawing.Point(42, 502);
|
||||||
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
|
this.buttonLeft.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.buttonLeft.TabIndex = 7;
|
||||||
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow;
|
||||||
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonRight.Location = new System.Drawing.Point(134, 502);
|
||||||
|
this.buttonRight.Name = "buttonRight";
|
||||||
|
this.buttonRight.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.buttonRight.TabIndex = 7;
|
||||||
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow;
|
||||||
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonDown.Location = new System.Drawing.Point(88, 502);
|
||||||
|
this.buttonDown.Name = "buttonDown";
|
||||||
|
this.buttonDown.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.buttonDown.TabIndex = 7;
|
||||||
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow;
|
||||||
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonUp.Location = new System.Drawing.Point(88, 456);
|
||||||
|
this.buttonUp.Name = "buttonUp";
|
||||||
|
this.buttonUp.Size = new System.Drawing.Size(40, 40);
|
||||||
|
this.buttonUp.TabIndex = 6;
|
||||||
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonShowOnMap
|
||||||
|
//
|
||||||
|
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 421);
|
||||||
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
|
this.buttonShowOnMap.Size = new System.Drawing.Size(207, 29);
|
||||||
|
this.buttonShowOnMap.TabIndex = 5;
|
||||||
|
this.buttonShowOnMap.Text = "Show on Map";
|
||||||
|
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
|
||||||
|
//
|
||||||
|
// buttonShowStorage
|
||||||
|
//
|
||||||
|
this.buttonShowStorage.Location = new System.Drawing.Point(6, 386);
|
||||||
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
|
this.buttonShowStorage.Size = new System.Drawing.Size(208, 29);
|
||||||
|
this.buttonShowStorage.TabIndex = 4;
|
||||||
|
this.buttonShowStorage.Text = "Show Storage";
|
||||||
|
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
|
||||||
|
//
|
||||||
|
// buttonRemoveLocomotive
|
||||||
|
//
|
||||||
|
this.buttonRemoveLocomotive.Location = new System.Drawing.Point(7, 350);
|
||||||
|
this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
|
||||||
|
this.buttonRemoveLocomotive.Size = new System.Drawing.Size(207, 30);
|
||||||
|
this.buttonRemoveLocomotive.TabIndex = 3;
|
||||||
|
this.buttonRemoveLocomotive.Text = "Remove Locomotive";
|
||||||
|
this.buttonRemoveLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRemoveLocomotive.Click += new System.EventHandler(this.buttonRemoveLocomotive_Click);
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 317);
|
||||||
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
this.maskedTextBoxPosition.Size = new System.Drawing.Size(208, 27);
|
||||||
|
this.maskedTextBoxPosition.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// buttonAddLocomotive
|
||||||
|
//
|
||||||
|
this.buttonAddLocomotive.Location = new System.Drawing.Point(6, 282);
|
||||||
|
this.buttonAddLocomotive.Name = "buttonAddLocomotive";
|
||||||
|
this.buttonAddLocomotive.Size = new System.Drawing.Size(208, 29);
|
||||||
|
this.buttonAddLocomotive.TabIndex = 1;
|
||||||
|
this.buttonAddLocomotive.Text = "Add Locomotive";
|
||||||
|
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, 0);
|
||||||
|
this.pictureBox.Name = "pictureBox";
|
||||||
|
this.pictureBox.Size = new System.Drawing.Size(580, 546);
|
||||||
|
this.pictureBox.TabIndex = 1;
|
||||||
|
this.pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormMapWithSetLocomotives
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 546);
|
||||||
|
this.Controls.Add(this.pictureBox);
|
||||||
|
this.Controls.Add(this.groupBoxTools);
|
||||||
|
this.Name = "FormMapWithSetLocomotives";
|
||||||
|
this.Text = "FormMapWithSetLocomotives";
|
||||||
|
this.groupBoxTools.ResumeLayout(false);
|
||||||
|
this.groupBoxTools.PerformLayout();
|
||||||
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
this.groupBox1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private ComboBox comboBoxSelectorMap;
|
||||||
|
private Button buttonAddLocomotive;
|
||||||
|
private MaskedTextBox maskedTextBoxPosition;
|
||||||
|
private Button buttonRemoveLocomotive;
|
||||||
|
private Button buttonShowStorage;
|
||||||
|
private Button buttonShowOnMap;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private TextBox textBoxNewMapName;
|
||||||
|
private Button buttonAddMap;
|
||||||
|
private Button buttonDeleteMap;
|
||||||
|
private ListBox listBoxMaps;
|
||||||
|
}
|
||||||
|
}
|
210
Locomotive/Locomotive/FormMapWithSetLocomotives.cs
Normal file
210
Locomotive/Locomotive/FormMapWithSetLocomotives.cs
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
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 Locomotive
|
||||||
|
{
|
||||||
|
public partial class FormMapWithSetLocomotives : Form
|
||||||
|
{
|
||||||
|
/// Словарь для выпадающего списка
|
||||||
|
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||||
|
{
|
||||||
|
{ "Simple Map", new SimpleMap() },
|
||||||
|
{ "Spike Map", new SpikeMap() },
|
||||||
|
{ "Rail Map", new RailroadMap() }
|
||||||
|
};
|
||||||
|
/// Объект от коллекции карт
|
||||||
|
private readonly MapsCollection _mapsCollection;
|
||||||
|
/// Конструктор
|
||||||
|
public FormMapWithSetLocomotives()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||||
|
comboBoxSelectorMap.Items.Clear();
|
||||||
|
foreach (var elem in _mapsDict)
|
||||||
|
{
|
||||||
|
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Заполнение listBoxMaps
|
||||||
|
private void ReloadMaps()
|
||||||
|
{
|
||||||
|
int index = listBoxMaps.SelectedIndex;
|
||||||
|
listBoxMaps.Items.Clear();
|
||||||
|
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Добавление карты
|
||||||
|
private void buttonAddMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Not all data is complete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("No such map", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
/// Выбор карты
|
||||||
|
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
/// Удаление карты
|
||||||
|
private void buttonDeleteMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?","Deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Добавление объекта
|
||||||
|
private void buttonAddLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
/*if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormLocomotive form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive);
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Object added");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Failed to add object");
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
var formCarConfig = new FormLocomotiveConfig();
|
||||||
|
// TODO Call method AddEvent from formCarConfig
|
||||||
|
formCarConfig.AddEvent(new (AddLocomotive));
|
||||||
|
formCarConfig.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddLocomotive(DrawningLocomotive locomotive)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectLocomotive(locomotive) != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Object added");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Failed to add object");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Удаление объекта
|
||||||
|
private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Remove object?", "Removing", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Object removed");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Failed to remove object");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Вывод набора
|
||||||
|
private void buttonShowStorage_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image =
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
/// Вывод карты
|
||||||
|
private void buttonShowOnMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image =
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||||
|
}
|
||||||
|
/// Перемещение
|
||||||
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//получаем имя кнопки
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
Direction dir = Direction.None;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
dir = Direction.Up;
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
dir = Direction.Down;
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
dir = Direction.Left;
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
dir = Direction.Right;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
60
Locomotive/Locomotive/FormMapWithSetLocomotives.resx
Normal file
60
Locomotive/Locomotive/FormMapWithSetLocomotives.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>
|
23
Locomotive/Locomotive/IDrawningObject.cs
Normal file
23
Locomotive/Locomotive/IDrawningObject.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal interface IDrawningObject
|
||||||
|
{
|
||||||
|
/// Шаг перемещения объекта
|
||||||
|
public float Step { get; }
|
||||||
|
/// Установка позиции объекта
|
||||||
|
void SetObject(int x, int y, int width, int height);
|
||||||
|
/// Изменение направления перемещения объекта
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
/// Отрисовка объекта
|
||||||
|
void DrawningObject(Graphics g);
|
||||||
|
/// Получение текущей позиции объекта
|
||||||
|
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
10
Locomotive/Locomotive/LocomotiveDelegate.cs
Normal file
10
Locomotive/Locomotive/LocomotiveDelegate.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
public delegate void LocomotiveDelegate(DrawningLocomotive locomotive);
|
||||||
|
}
|
162
Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs
Normal file
162
Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class MapWithSetLocomotivesGeneric <T, U>
|
||||||
|
where T : class, IDrawningObject
|
||||||
|
where U : AbstractMap
|
||||||
|
{
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
private readonly int _placeSizeWidth = 210;
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
/// Набор объектов
|
||||||
|
private readonly SetLocomotivesGeneric<T> _setLocomotives;
|
||||||
|
/// Карта
|
||||||
|
private readonly U _map;
|
||||||
|
/// Конструктор
|
||||||
|
public MapWithSetLocomotivesGeneric(int picWidth, int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setLocomotives = new SetLocomotivesGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
public static int operator +(MapWithSetLocomotivesGeneric<T, U> map, T locomotive)
|
||||||
|
{
|
||||||
|
return map._setLocomotives.Insert(locomotive);
|
||||||
|
}
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
public static T operator -(MapWithSetLocomotivesGeneric<T, U> map, int position)
|
||||||
|
{
|
||||||
|
return map._setLocomotives.Remove(position);
|
||||||
|
}
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
public Bitmap ShowSet()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawLocomotives(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// Просмотр объекта на карте
|
||||||
|
public Bitmap ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
/// Перемещение объекта по крате
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
return _map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||||
|
private void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setLocomotives.Count - 1;
|
||||||
|
for (int i = 0; i < _setLocomotives.Count; i++)
|
||||||
|
{
|
||||||
|
if (_setLocomotives[i] == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var locomotive = _setLocomotives[j];
|
||||||
|
if (locomotive != null)
|
||||||
|
{
|
||||||
|
_setLocomotives.Insert(locomotive, i);
|
||||||
|
_setLocomotives.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen;
|
||||||
|
|
||||||
|
for (int j = _placeSizeHeight; j < _pictureHeight; j+= _placeSizeHeight)
|
||||||
|
{
|
||||||
|
//нижняя линия рельс
|
||||||
|
pen = new(Color.Black, 5);
|
||||||
|
|
||||||
|
g.DrawLine(pen, 0, j, _pictureWidth, j);
|
||||||
|
for (int i = 0; i < _pictureWidth; i+=20)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i, j, i, j + 10);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, 0, j + 10, _pictureWidth, j + 10);
|
||||||
|
|
||||||
|
//верхняя линия рельс
|
||||||
|
|
||||||
|
pen = new(Color.DarkGray, 4);
|
||||||
|
|
||||||
|
g.DrawLine(pen, 0, j - 20, _pictureWidth, j - 20);
|
||||||
|
for (int i = 0; i < _pictureWidth; i += 20)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i, j - 20, i, j - 10);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, 0, j - 10, _pictureWidth, j - 10);
|
||||||
|
|
||||||
|
//фонари
|
||||||
|
for (int i = _placeSizeWidth; i < _pictureWidth; i += _placeSizeWidth)
|
||||||
|
{
|
||||||
|
pen = new(Color.Black, 10);
|
||||||
|
g.DrawLine(pen, i, j - _placeSizeHeight + 20, i, j);
|
||||||
|
pen = new(Color.Yellow, 20);
|
||||||
|
g.DrawLine(pen, i, j - _placeSizeHeight + 18, i, j - _placeSizeHeight + 38);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
private void DrawLocomotives(Graphics g)
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
|
int curWidth = 0;
|
||||||
|
int curHeight = 0;
|
||||||
|
|
||||||
|
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||||
|
{
|
||||||
|
// установка позиции
|
||||||
|
locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
|
||||||
|
locomotive?.DrawningObject(g);
|
||||||
|
if (curWidth < width) curWidth++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curWidth = 0;
|
||||||
|
curHeight++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
52
Locomotive/Locomotive/MapsCollection.cs
Normal file
52
Locomotive/Locomotive/MapsCollection.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class MapsCollection
|
||||||
|
{
|
||||||
|
/// Словарь (хранилище) с картами
|
||||||
|
readonly Dictionary<string, MapWithSetLocomotivesGeneric<DrawningObjectLocomotive,
|
||||||
|
AbstractMap>> _mapStorages;
|
||||||
|
/// Возвращение списка названий карт
|
||||||
|
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// Конструктор
|
||||||
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_mapStorages = new Dictionary<string,
|
||||||
|
MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// Добавление карты
|
||||||
|
public void AddMap(string name, AbstractMap map)
|
||||||
|
{
|
||||||
|
// Логика для добавления
|
||||||
|
if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
|
/// Удаление карты
|
||||||
|
public void DelMap(string name)
|
||||||
|
{
|
||||||
|
// Логика для удаления
|
||||||
|
if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name);
|
||||||
|
}
|
||||||
|
/// Доступ к парковке
|
||||||
|
public MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// Логика получения объекта
|
||||||
|
if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ namespace Locomotive
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormLocomotive());
|
Application.Run(new FormMapWithSetLocomotives());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
62
Locomotive/Locomotive/RailroadMap.cs
Normal file
62
Locomotive/Locomotive/RailroadMap.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class RailroadMap : AbstractMap
|
||||||
|
{
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
/// Цвет участка открытого
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Pink);
|
||||||
|
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||||
|
1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||||
|
1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 1)
|
||||||
|
{
|
||||||
|
int y = _random.Next(0, 95);
|
||||||
|
|
||||||
|
for(int x = 0; x < 99; x++)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
_map[x, y + 5] = _barrier;
|
||||||
|
|
||||||
|
if (x % 5 == 0)
|
||||||
|
{
|
||||||
|
_map[x, y + 1] = _barrier;
|
||||||
|
_map[x, y + 2] = _barrier;
|
||||||
|
_map[x, y + 3] = _barrier;
|
||||||
|
_map[x, y + 4] = _barrier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
76
Locomotive/Locomotive/SetLocomotivesGeneric.cs
Normal file
76
Locomotive/Locomotive/SetLocomotivesGeneric.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class SetLocomotivesGeneric <T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// Список хранимых объектов
|
||||||
|
private readonly List<T> _places;
|
||||||
|
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
public int Count => _places.Count;
|
||||||
|
// Ограничение на количество
|
||||||
|
private readonly int _maxCount;
|
||||||
|
/// Конструктор
|
||||||
|
public SetLocomotivesGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new List<T>();
|
||||||
|
}
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
public int Insert(T locomotive)
|
||||||
|
{
|
||||||
|
return Insert(locomotive, 0);
|
||||||
|
}
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
public int Insert(T locomotive, int position)
|
||||||
|
{
|
||||||
|
if (position >= _maxCount|| position < 0) return -1;
|
||||||
|
_places.Insert(position, locomotive);
|
||||||
|
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (position >= _maxCount || position < 0) return null;
|
||||||
|
T result = _places[position];
|
||||||
|
_places.RemoveAt(position);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// Индексатор
|
||||||
|
public T this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position >= _maxCount || position < 0) return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position >= _maxCount || position < 0) return;
|
||||||
|
Insert(value, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Проход по набору до первого пустого
|
||||||
|
public IEnumerable<T> GetLocomotives()
|
||||||
|
{
|
||||||
|
foreach (var locomotive in _places)
|
||||||
|
{
|
||||||
|
if (locomotive != null)
|
||||||
|
{
|
||||||
|
yield return locomotive;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
Locomotive/Locomotive/SimpleMap.cs
Normal file
54
Locomotive/Locomotive/SimpleMap.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class SimpleMap : AbstractMap
|
||||||
|
{
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
/// Цвет участка открытого
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||||
|
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||||
|
1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||||
|
1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 100);
|
||||||
|
int y = _random.Next(0, 100);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
59
Locomotive/Locomotive/SpikeMap.cs
Normal file
59
Locomotive/Locomotive/SpikeMap.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class SpikeMap : AbstractMap
|
||||||
|
{
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
/// Цвет участка открытого
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Green);
|
||||||
|
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||||
|
1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x +
|
||||||
|
1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 15)
|
||||||
|
{
|
||||||
|
int x = _random.Next(1, 99);
|
||||||
|
int y = _random.Next(1, 99);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
|
||||||
|
if (_map[x + 1, y] == _freeRoad) _map[x + 1, y] = _barrier;
|
||||||
|
if (_map[x - 1, y] == _freeRoad) _map[x - 1, y] = _barrier;
|
||||||
|
if (_map[x, y + 1] == _freeRoad) _map[x, y + 1] = _barrier;
|
||||||
|
if (_map[x, y - 1] == _freeRoad) _map[x, y - 1] = _barrier;
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user