Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
3a2be882a3 | |||
56317ae39d | |||
1228e1bdbe | |||
ddf5a2547f | |||
4f448847d7 | |||
81399704cd | |||
7207d73a7f | |||
291a63f52e | |||
05acd6e9a2 | |||
cfe37b3d42 | |||
8cf45a8ea4 | |||
231a6be0b5 | |||
98e70fff81 | |||
60ee97faad | |||
986512d2fc | |||
a1f0b7d534 | |||
036252a578 | |||
4deea7f26c | |||
2e9c0700ed | |||
f3f9e536bc | |||
2915ef8a0b | |||
642287a5e7 | |||
307d615227 |
25
Laba1Loco/Laba1Loco.sln
Normal file
25
Laba1Loco/Laba1Loco.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.33424.131
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Laba1Loco", "Laba1Loco\Laba1Loco.csproj", "{9F9C9603-3EF7-403E-A895-04EA0CBC5586}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9F9C9603-3EF7-403E-A895-04EA0CBC5586}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9F9C9603-3EF7-403E-A895-04EA0CBC5586}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9F9C9603-3EF7-403E-A895-04EA0CBC5586}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9F9C9603-3EF7-403E-A895-04EA0CBC5586}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {EF8E2621-D5D1-4E60-BC18-2388B1EB5E59}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
131
Laba1Loco/Laba1Loco/AbstractStrategy.cs
Normal file
131
Laba1Loco/Laba1Loco/AbstractStrategy.cs
Normal file
@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private Status _state = Status.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public Status GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int
|
||||
height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(Direction.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(Direction.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(Direction.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(Direction.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="Direction">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||
private bool MoveTo(Direction Direction)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(Direction) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(Direction);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
6
Laba1Loco/Laba1Loco/App.config
Normal file
6
Laba1Loco/Laba1Loco/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
</configuration>
|
29
Laba1Loco/Laba1Loco/Direction.cs
Normal file
29
Laba1Loco/Laba1Loco/Direction.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
public enum Direction
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
|
||||
}
|
174
Laba1Loco/Laba1Loco/DrawingLoco.cs
Normal file
174
Laba1Loco/Laba1Loco/DrawingLoco.cs
Normal file
@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class DrawingLoco : DrawingTrain
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="tube">Признак наличия трубы</param>
|
||||
/// <param name="fuelTank">Признак наличия бака</param>
|
||||
/// <param name="locoLine">Признак наличия паровозной полосы</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawingLoco(int speed, double weight, Color bodyColor, Color additionalColor, bool tube, bool fuelTank, bool locoLine, int width, int height)
|
||||
: base(speed, weight, bodyColor, width, height)
|
||||
{
|
||||
EntityTrain = new EntityLoco(speed, weight, bodyColor, additionalColor, tube, fuelTank, locoLine);
|
||||
_locoWidth = ((EntityTrain as EntityLoco)?.FuelTank ?? false) ? 169 : 83;
|
||||
}
|
||||
/// <summary>
|
||||
/// шаг времени для облаков
|
||||
/// </summary>
|
||||
public override void timeTick()
|
||||
{
|
||||
if (EntityTrain != null)
|
||||
{
|
||||
if (clouds.Count < 10)
|
||||
clouds.Add(new cloud(_startPosX+40, (EntityTrain as EntityLoco).Tube ? _startPosY : _startPosY + 9));
|
||||
}
|
||||
for (int i = 0; i < clouds.Count; i++)
|
||||
{
|
||||
if (i < clouds.Count)
|
||||
{
|
||||
clouds[i].timeTick();
|
||||
if (clouds[i].opasity < 20)
|
||||
{
|
||||
clouds.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTrain == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (!(EntityTrain is EntityLoco))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(EntityTrain.BodyColor);
|
||||
Brush brush = new SolidBrush(EntityTrain.BodyColor);
|
||||
Pen additionalPen = new Pen((EntityTrain as EntityLoco).AdditionalColor);
|
||||
Brush additionalBrush = new SolidBrush((EntityTrain as EntityLoco).AdditionalColor);
|
||||
|
||||
if ((EntityTrain as EntityLoco).Tube)
|
||||
{
|
||||
g.DrawLines(additionalPen,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 40, _startPosY+9),
|
||||
new Point(_startPosX + 40, _startPosY+3),
|
||||
new Point(_startPosX + 45, _startPosY+3),
|
||||
new Point(_startPosX + 41, _startPosY+3),
|
||||
new Point(_startPosX + 41, _startPosY),
|
||||
new Point(_startPosX + 44, _startPosY),
|
||||
new Point(_startPosX + 44, _startPosY+3),
|
||||
new Point(_startPosX + 45, _startPosY+3),
|
||||
new Point(_startPosX + 45, _startPosY+9),
|
||||
});
|
||||
}
|
||||
if ((EntityTrain as EntityLoco).LocoLine)
|
||||
{
|
||||
g.DrawLines(additionalPen,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 60, _startPosY+10),
|
||||
new Point(_startPosX + 38, _startPosY+32),
|
||||
});
|
||||
g.DrawLines(additionalPen,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 65, _startPosY+10),
|
||||
new Point(_startPosX + 43, _startPosY+32),
|
||||
});
|
||||
g.DrawLines(additionalPen,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 70, _startPosY+10),
|
||||
new Point(_startPosX + 48, _startPosY+32),
|
||||
});
|
||||
}
|
||||
if ((EntityTrain as EntityLoco).FuelTank)
|
||||
{
|
||||
// body
|
||||
g.DrawLines(pen,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 89, _startPosY+10),
|
||||
new Point(_startPosX + 164, _startPosY+10),
|
||||
new Point(_startPosX + 164, _startPosY+32),
|
||||
new Point(_startPosX + 89, _startPosY+32),
|
||||
new Point(_startPosX + 89, _startPosY+10),
|
||||
}
|
||||
);
|
||||
g.DrawLines(pen,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 89, _startPosY+21),
|
||||
new Point(_startPosX + 164, _startPosY+21),
|
||||
}
|
||||
);
|
||||
|
||||
// trucks
|
||||
g.FillPolygon(brush,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 0+85, _startPosY+37),
|
||||
new Point(_startPosX + 5+85, _startPosY+33),
|
||||
new Point(_startPosX + 32+85, _startPosY+33),
|
||||
new Point(_startPosX + 36+85, _startPosY+37),
|
||||
}
|
||||
);
|
||||
g.FillPolygon(brush,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 44+85, _startPosY+37),
|
||||
new Point(_startPosX + 49+85, _startPosY+33),
|
||||
new Point(_startPosX + 76+85, _startPosY+33),
|
||||
new Point(_startPosX + 80+85, _startPosY+37),
|
||||
}
|
||||
);
|
||||
|
||||
//front
|
||||
g.FillPolygon(brush,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 86, _startPosY+12),
|
||||
new Point(_startPosX + 89, _startPosY+12),
|
||||
new Point(_startPosX + 89, _startPosY+30),
|
||||
new Point(_startPosX + 86, _startPosY+30),
|
||||
}
|
||||
);
|
||||
|
||||
//back
|
||||
g.FillPolygon(brush,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 79+85, _startPosY+12),
|
||||
new Point(_startPosX + 82+85, _startPosY+12),
|
||||
new Point(_startPosX + 82+85, _startPosY+30),
|
||||
new Point(_startPosX + 79+85, _startPosY+30),
|
||||
}
|
||||
);
|
||||
|
||||
//wheels
|
||||
g.FillEllipse(brush, _startPosX + 3 + 85, _startPosY + 34, 8, 8);
|
||||
g.FillEllipse(brush, _startPosX + 26 + 85, _startPosY + 34, 8, 8);
|
||||
g.FillEllipse(brush, _startPosX + 46 + 85, _startPosY + 34, 8, 8);
|
||||
g.FillEllipse(brush, _startPosX + 72 + 85, _startPosY + 34, 8, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
316
Laba1Loco/Laba1Loco/DrawingTrain.cs
Normal file
316
Laba1Loco/Laba1Loco/DrawingTrain.cs
Normal file
@ -0,0 +1,316 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class DrawingTrain
|
||||
{
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectTrain(this);
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityTrain EntityTrain { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
public int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
public int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки локомотива
|
||||
/// </summary>
|
||||
protected int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки локомотива
|
||||
/// </summary>
|
||||
protected int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки локомотива
|
||||
/// </summary>
|
||||
protected int _locoWidth = 83;
|
||||
/// <summary>
|
||||
/// Высота прорисовки локомотива
|
||||
/// </summary>
|
||||
protected readonly int _locoHeight = 41;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawingTrain(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureHeight < _locoHeight || _pictureWidth < _locoWidth)
|
||||
return;
|
||||
EntityTrain = new EntityTrain(speed, weight, bodyColor);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
_startPosX = Math.Min(x, _pictureWidth - _locoWidth);
|
||||
_startPosY = Math.Min(y, _pictureHeight - _locoHeight);
|
||||
clouds = new List<cloud>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _locoWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _locoHeight;
|
||||
/// <summary>
|
||||
/// Проверка, что объект может переместится по указанному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||
public bool CanMove(Direction direction)
|
||||
{
|
||||
if (EntityTrain == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Left:
|
||||
return _startPosX - EntityTrain.Step > 0;
|
||||
case Direction.Right:
|
||||
return _startPosX + _locoWidth + EntityTrain.Step < _pictureWidth;
|
||||
case Direction.Up:
|
||||
return _startPosY - EntityTrain.Step > 0;
|
||||
case Direction.Down:
|
||||
return _startPosY + _locoHeight + EntityTrain.Step < _pictureHeight;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityTrain == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case Direction.Left:
|
||||
_startPosX -= (int)EntityTrain.Step;
|
||||
break;
|
||||
//вверх
|
||||
case Direction.Up:
|
||||
_startPosY -= (int)EntityTrain.Step;
|
||||
break;
|
||||
// вправо
|
||||
case Direction.Right:
|
||||
_startPosX += (int)EntityTrain.Step;
|
||||
break;
|
||||
//вниз
|
||||
case Direction.Down:
|
||||
_startPosY += (int)EntityTrain.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// класс облака
|
||||
/// </summary>
|
||||
protected class cloud
|
||||
{
|
||||
/// <summary>
|
||||
/// просто рандом
|
||||
/// </summary>
|
||||
Random random;
|
||||
/// <summary>
|
||||
/// координаты облака
|
||||
/// </summary>
|
||||
int x, y;
|
||||
/// <summary>
|
||||
/// размер облака
|
||||
/// </summary>
|
||||
int size;
|
||||
/// <summary>
|
||||
/// прозрачность облака
|
||||
/// </summary>
|
||||
public int opasity;
|
||||
/// <summary>
|
||||
/// intialisation облака
|
||||
/// </summary>
|
||||
/// <param name="x_">координата облака по горизонтали</param>
|
||||
/// <param name="y_">координата облака по вертикали</param>
|
||||
public cloud(int x_, int y_)
|
||||
{
|
||||
random = new Random();
|
||||
x = x_;
|
||||
y = y_ - 5;
|
||||
size = 10;
|
||||
opasity = 255;
|
||||
}
|
||||
/// <summary>
|
||||
/// шаг времени для облака
|
||||
/// </summary>
|
||||
public void timeTick()
|
||||
{
|
||||
y -= 3;
|
||||
size += 5;
|
||||
opasity -= 20;
|
||||
|
||||
/// добавляем случайности
|
||||
y += random.Next(-1, 2);
|
||||
x += random.Next(-1, 2);
|
||||
size += random.Next(-1, 2);
|
||||
opasity += random.Next(-1, 2);
|
||||
}
|
||||
/// <summary>
|
||||
/// отрисовка облака
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void Draw(Graphics g)
|
||||
{
|
||||
g.DrawEllipse(new Pen(Color.FromArgb(opasity, Pens.Gray.Color)), x - size / 2, y - size / 2, size, size);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// массив облачков
|
||||
/// </summary>
|
||||
protected List<cloud> clouds = new List<cloud>();
|
||||
|
||||
/// <summary>
|
||||
/// шаг времени для облаков
|
||||
/// </summary>
|
||||
public virtual void timeTick()
|
||||
{
|
||||
if (EntityTrain != null)
|
||||
{
|
||||
if (clouds.Count < 10)
|
||||
clouds.Add(new cloud(_startPosX + 40, _startPosY + 9));
|
||||
}
|
||||
for (int i = 0; i < clouds.Count; i++)
|
||||
{
|
||||
if (i < clouds.Count)
|
||||
{
|
||||
clouds[i].timeTick();
|
||||
if (clouds[i].opasity < 20)
|
||||
{
|
||||
clouds.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTrain == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//smoke
|
||||
foreach (var it in clouds)
|
||||
{
|
||||
it.Draw(g);
|
||||
}
|
||||
|
||||
Pen pen = new Pen(EntityTrain.BodyColor);
|
||||
Brush brush = new SolidBrush(EntityTrain.BodyColor);
|
||||
|
||||
|
||||
// body
|
||||
g.DrawLines(pen,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 8, _startPosY+10),
|
||||
new Point(_startPosX + 79, _startPosY+10),
|
||||
new Point(_startPosX + 79, _startPosY+32),
|
||||
new Point(_startPosX + 4, _startPosY+32),
|
||||
new Point(_startPosX + 4, _startPosY+20),
|
||||
new Point(_startPosX + 8, _startPosY+10),
|
||||
}
|
||||
);
|
||||
g.DrawLines(pen,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 4, _startPosY+21),
|
||||
new Point(_startPosX + 29, _startPosY+21),
|
||||
new Point(_startPosX + 29, _startPosY+14),
|
||||
new Point(_startPosX + 37, _startPosY+14),
|
||||
new Point(_startPosX + 37, _startPosY+21),
|
||||
new Point(_startPosX + 79, _startPosY+21),
|
||||
new Point(_startPosX + 37, _startPosY+21),
|
||||
new Point(_startPosX + 37, _startPosY+29),
|
||||
new Point(_startPosX + 29, _startPosY+29),
|
||||
new Point(_startPosX + 29, _startPosY+21),
|
||||
}
|
||||
);
|
||||
|
||||
// trucks
|
||||
g.FillPolygon(brush,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 0, _startPosY+37),
|
||||
new Point(_startPosX + 5, _startPosY+33),
|
||||
new Point(_startPosX + 32, _startPosY+33),
|
||||
new Point(_startPosX + 36, _startPosY+37),
|
||||
}
|
||||
);
|
||||
g.FillPolygon(brush,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 44, _startPosY+37),
|
||||
new Point(_startPosX + 49, _startPosY+33),
|
||||
new Point(_startPosX + 76, _startPosY+33),
|
||||
new Point(_startPosX + 80, _startPosY+37),
|
||||
}
|
||||
);
|
||||
|
||||
//back
|
||||
g.FillPolygon(brush,
|
||||
new Point[] {
|
||||
new Point(_startPosX + 79, _startPosY+12),
|
||||
new Point(_startPosX + 82, _startPosY+12),
|
||||
new Point(_startPosX + 82, _startPosY+30),
|
||||
new Point(_startPosX + 79, _startPosY+30),
|
||||
}
|
||||
);
|
||||
|
||||
//windows
|
||||
g.DrawRectangle(Pens.Blue, _startPosX + 10, _startPosY + 12, 6, 7);
|
||||
g.DrawRectangle(Pens.Blue, _startPosX + 19, _startPosY + 12, 6, 7);
|
||||
g.DrawRectangle(Pens.Blue, _startPosX + 72, _startPosY + 12, 6, 7);
|
||||
|
||||
//wheels
|
||||
g.FillEllipse(brush, _startPosX + 3, _startPosY + 34, 8, 8);
|
||||
g.FillEllipse(brush, _startPosX + 26, _startPosY + 34, 8, 8);
|
||||
g.FillEllipse(brush, _startPosX + 46, _startPosY + 34, 8, 8);
|
||||
g.FillEllipse(brush, _startPosX + 72, _startPosY + 34, 8, 8);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
34
Laba1Loco/Laba1Loco/DrawningObjectTrain.cs
Normal file
34
Laba1Loco/Laba1Loco/DrawningObjectTrain.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class DrawningObjectTrain : IMoveableObject
|
||||
{
|
||||
private readonly DrawingTrain _drawingTrain = null;
|
||||
public DrawningObjectTrain(DrawingTrain drawningCar)
|
||||
{
|
||||
_drawingTrain = drawningCar;
|
||||
}
|
||||
public ObjectParameters GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawingTrain == null || _drawingTrain.EntityTrain ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawingTrain.GetPosX,
|
||||
_drawingTrain.GetPosY, _drawingTrain.GetWidth, _drawingTrain.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawingTrain?.EntityTrain?.Step ?? 0);
|
||||
public bool CheckCanMove(Direction direction) => _drawingTrain?.CanMove(direction) ?? false;
|
||||
public void MoveObject(Direction direction) => _drawingTrain?.MoveTransport(direction);
|
||||
|
||||
}
|
||||
}
|
49
Laba1Loco/Laba1Loco/EntityLoco.cs
Normal file
49
Laba1Loco/Laba1Loco/EntityLoco.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class EntityLoco : EntityTrain
|
||||
{
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
public void setAdditionalColor(Color color) { AdditionalColor = color; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия трубы
|
||||
/// </summary>
|
||||
public bool Tube { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия топливного бака
|
||||
/// </summary>
|
||||
public bool FuelTank { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия паровозной полосы
|
||||
/// </summary>
|
||||
public bool LocoLine { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса Локомотива
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="tube">Признак наличия трубы</param>
|
||||
/// <param name="fuelTank">Признак наличия бака</param>
|
||||
/// <param name="locoLine">Признак наличия паровозной полосы</param>
|
||||
public EntityLoco(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool tube, bool fuelTank, bool locoLine)
|
||||
: base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Tube = tube;
|
||||
FuelTank = fuelTank;
|
||||
LocoLine = locoLine;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
44
Laba1Loco/Laba1Loco/EntityTrain.cs
Normal file
44
Laba1Loco/Laba1Loco/EntityTrain.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class EntityTrain
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
public void setBodyColor(Color color) { BodyColor = color; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения поезда
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса Локомотива
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityTrain(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
61
Laba1Loco/Laba1Loco/ExtentionDrawingTrain.cs
Normal file
61
Laba1Loco/Laba1Loco/ExtentionDrawingTrain.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal static class ExtentionDrawingTrain
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawingTrain CreateDrawingTrain(this string info, char separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingTrain(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 7)
|
||||
{
|
||||
return new DrawingLoco(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]),
|
||||
Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]),
|
||||
Convert.ToBoolean(strs[6]), width, height);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningtrain">Сохраняемый объект</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawingTrain drawningTrain, char separatorForObject)
|
||||
{
|
||||
var train = drawningTrain.EntityTrain;
|
||||
if (train == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = $"{train.Speed}{separatorForObject}{train.Weight}{separatorForObject}{train.BodyColor.Name}";
|
||||
if (!(train is EntityLoco))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{separatorForObject}{(train as EntityLoco).AdditionalColor.Name}{separatorForObject}{(train as EntityLoco).Tube}{separatorForObject}{(train as EntityLoco).FuelTank}{separatorForObject}{(train as EntityLoco).LocoLine}";
|
||||
}
|
||||
}
|
||||
}
|
196
Laba1Loco/Laba1Loco/FormLocomotive.Designer.cs
generated
Normal file
196
Laba1Loco/Laba1Loco/FormLocomotive.Designer.cs
generated
Normal file
@ -0,0 +1,196 @@
|
||||
namespace Laba1Loco
|
||||
{
|
||||
partial class FormLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором форм Windows
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.create = new System.Windows.Forms.Button();
|
||||
this.left = new System.Windows.Forms.Button();
|
||||
this.up = new System.Windows.Forms.Button();
|
||||
this.down = new System.Windows.Forms.Button();
|
||||
this.right = new System.Windows.Forms.Button();
|
||||
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.strategysstep = new System.Windows.Forms.Button();
|
||||
this.createLocomotive = new System.Windows.Forms.Button();
|
||||
this.SelectTrain = new System.Windows.Forms.Button();
|
||||
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// 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(800, 450);
|
||||
this.pictureBox.TabIndex = 0;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// create
|
||||
//
|
||||
this.create.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.create.Location = new System.Drawing.Point(12, 415);
|
||||
this.create.Name = "create";
|
||||
this.create.Size = new System.Drawing.Size(75, 23);
|
||||
this.create.TabIndex = 1;
|
||||
this.create.Text = "create train";
|
||||
this.create.UseVisualStyleBackColor = true;
|
||||
this.create.Click += new System.EventHandler(this.create_Click);
|
||||
//
|
||||
// left
|
||||
//
|
||||
this.left.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.left.Image = global::Laba1Loco.Properties.Resources.arowL340x259;
|
||||
this.left.Location = new System.Drawing.Point(632, 390);
|
||||
this.left.Name = "left";
|
||||
this.left.Size = new System.Drawing.Size(48, 48);
|
||||
this.left.TabIndex = 3;
|
||||
this.left.UseVisualStyleBackColor = true;
|
||||
this.left.Click += new System.EventHandler(this.Click);
|
||||
//
|
||||
// up
|
||||
//
|
||||
this.up.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.up.Image = global::Laba1Loco.Properties.Resources.arowUp340x259;
|
||||
this.up.Location = new System.Drawing.Point(686, 336);
|
||||
this.up.Name = "up";
|
||||
this.up.Size = new System.Drawing.Size(48, 48);
|
||||
this.up.TabIndex = 4;
|
||||
this.up.UseVisualStyleBackColor = true;
|
||||
this.up.Click += new System.EventHandler(this.Click);
|
||||
//
|
||||
// down
|
||||
//
|
||||
this.down.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.down.Image = global::Laba1Loco.Properties.Resources.arowDown340x259;
|
||||
this.down.Location = new System.Drawing.Point(686, 390);
|
||||
this.down.Name = "down";
|
||||
this.down.Size = new System.Drawing.Size(48, 48);
|
||||
this.down.TabIndex = 5;
|
||||
this.down.UseVisualStyleBackColor = true;
|
||||
this.down.Click += new System.EventHandler(this.Click);
|
||||
//
|
||||
// right
|
||||
//
|
||||
this.right.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.right.Image = global::Laba1Loco.Properties.Resources.arowR340x259;
|
||||
this.right.Location = new System.Drawing.Point(740, 390);
|
||||
this.right.Name = "right";
|
||||
this.right.Size = new System.Drawing.Size(48, 48);
|
||||
this.right.TabIndex = 6;
|
||||
this.right.UseVisualStyleBackColor = true;
|
||||
this.right.Click += new System.EventHandler(this.Click);
|
||||
//
|
||||
// timer1
|
||||
//
|
||||
this.timer1.Enabled = true;
|
||||
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxStrategy.FormattingEnabled = true;
|
||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||
"to center",
|
||||
"to bottom right"});
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(667, 12);
|
||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 21);
|
||||
this.comboBoxStrategy.TabIndex = 8;
|
||||
//
|
||||
// strategysstep
|
||||
//
|
||||
this.strategysstep.Location = new System.Drawing.Point(705, 40);
|
||||
this.strategysstep.Name = "strategysstep";
|
||||
this.strategysstep.Size = new System.Drawing.Size(83, 23);
|
||||
this.strategysstep.TabIndex = 9;
|
||||
this.strategysstep.Text = "strategy\'s step";
|
||||
this.strategysstep.UseVisualStyleBackColor = true;
|
||||
this.strategysstep.Click += new System.EventHandler(this.strategysstep_Click);
|
||||
//
|
||||
// createLocomotive
|
||||
//
|
||||
this.createLocomotive.Location = new System.Drawing.Point(93, 415);
|
||||
this.createLocomotive.Name = "createLocomotive";
|
||||
this.createLocomotive.Size = new System.Drawing.Size(113, 23);
|
||||
this.createLocomotive.TabIndex = 10;
|
||||
this.createLocomotive.Text = "create Locomotive";
|
||||
this.createLocomotive.UseVisualStyleBackColor = true;
|
||||
this.createLocomotive.Click += new System.EventHandler(this.createLocomotive_Click);
|
||||
//
|
||||
// SelectTrain
|
||||
//
|
||||
this.SelectTrain.Location = new System.Drawing.Point(346, 415);
|
||||
this.SelectTrain.Name = "SelectTrain";
|
||||
this.SelectTrain.Size = new System.Drawing.Size(75, 23);
|
||||
this.SelectTrain.TabIndex = 11;
|
||||
this.SelectTrain.Text = "Select Train";
|
||||
this.SelectTrain.UseVisualStyleBackColor = true;
|
||||
this.SelectTrain.Click += new System.EventHandler(this.ButtonSelectTrain_Click);
|
||||
//
|
||||
// FormLocomotive
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.SelectTrain);
|
||||
this.Controls.Add(this.createLocomotive);
|
||||
this.Controls.Add(this.strategysstep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.right);
|
||||
this.Controls.Add(this.down);
|
||||
this.Controls.Add(this.up);
|
||||
this.Controls.Add(this.left);
|
||||
this.Controls.Add(this.create);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Name = "FormLocomotive";
|
||||
this.Text = "Locomotive(moving)";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.PictureBox pictureBox;
|
||||
private System.Windows.Forms.Button create;
|
||||
private System.Windows.Forms.Button left;
|
||||
private System.Windows.Forms.Button up;
|
||||
private System.Windows.Forms.Button down;
|
||||
private System.Windows.Forms.Button right;
|
||||
public System.Windows.Forms.Timer timer1;
|
||||
private System.Windows.Forms.ComboBox comboBoxStrategy;
|
||||
private System.Windows.Forms.Button strategysstep;
|
||||
private System.Windows.Forms.Button createLocomotive;
|
||||
private System.Windows.Forms.Button SelectTrain;
|
||||
private System.ComponentModel.BackgroundWorker backgroundWorker1;
|
||||
}
|
||||
}
|
||||
|
208
Laba1Loco/Laba1Loco/FormLocomotive.cs
Normal file
208
Laba1Loco/Laba1Loco/FormLocomotive.cs
Normal file
@ -0,0 +1,208 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
public partial class FormLocomotive : Form
|
||||
{
|
||||
AbstractStrategy abstractStrategy;
|
||||
internal DrawingTrain SelectedTrain { get; private set; }
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawingTrain _drawingTrain;
|
||||
/// <summary>
|
||||
/// Инициализация формы
|
||||
/// </summary>
|
||||
public FormLocomotive()
|
||||
{
|
||||
InitializeComponent();
|
||||
abstractStrategy = null;
|
||||
SelectedTrain = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод прорисовки локомотива
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingTrain == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new Bitmap(pictureBox.Width, pictureBox.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
if (_drawingTrain is DrawingLoco)
|
||||
(_drawingTrain as DrawingLoco).DrawTransport(gr);
|
||||
else
|
||||
_drawingTrain.DrawTransport(gr);
|
||||
pictureBox.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать локомотив"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void create_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
Color color = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new ColorDialog();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawingTrain = new DrawingTrain(
|
||||
random.Next(100, 300), random.Next(2000, 4000),
|
||||
color,
|
||||
pictureBox.Width, pictureBox.Height
|
||||
);
|
||||
_drawingTrain.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// клик движения мышки
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingTrain == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "up":
|
||||
_drawingTrain.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "down":
|
||||
_drawingTrain.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "left":
|
||||
_drawingTrain.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "right":
|
||||
_drawingTrain.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// таймер для дымка
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void timer1_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingTrain != null)
|
||||
_drawingTrain.timeTick();
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// нажатие кнопки: "создание поезда"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void createLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
Color color1 = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog1 = new ColorDialog();
|
||||
if (dialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color1 = dialog1.Color;
|
||||
}
|
||||
Color color2 = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog2 = new ColorDialog();
|
||||
if (dialog2.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color2 = dialog2.Color;
|
||||
}
|
||||
_drawingTrain = new DrawingLoco(
|
||||
random.Next(100, 300), random.Next(2000, 4000),
|
||||
color1,
|
||||
color2,
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBox.Width, pictureBox.Height
|
||||
);
|
||||
_drawingTrain.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Шаг"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void strategysstep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingTrain == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
switch (comboBoxStrategy.SelectedIndex)
|
||||
{
|
||||
case 0:
|
||||
abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
abstractStrategy = new MoveToBorder();
|
||||
break;
|
||||
default:
|
||||
abstractStrategy = null;
|
||||
break;
|
||||
};
|
||||
if (abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
abstractStrategy.SetData(new
|
||||
DrawningObjectTrain(_drawingTrain), pictureBox.Width,
|
||||
pictureBox.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
abstractStrategy = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор автомобиля
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSelectTrain_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedTrain = _drawingTrain;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
126
Laba1Loco/Laba1Loco/FormLocomotive.resx
Normal file
126
Laba1Loco/Laba1Loco/FormLocomotive.resx
Normal file
@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>104, 17</value>
|
||||
</metadata>
|
||||
</root>
|
256
Laba1Loco/Laba1Loco/FormTrainCollection.Designer.cs
generated
Normal file
256
Laba1Loco/Laba1Loco/FormTrainCollection.Designer.cs
generated
Normal file
@ -0,0 +1,256 @@
|
||||
namespace Laba1Loco
|
||||
{
|
||||
partial class FormTrainCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
panel1 = new System.Windows.Forms.Panel();
|
||||
panel2 = new System.Windows.Forms.Panel();
|
||||
buttonRemoveSet = new System.Windows.Forms.Button();
|
||||
listBoxStorage = new System.Windows.Forms.ListBox();
|
||||
buttonAddSet = new System.Windows.Forms.Button();
|
||||
textBoxSetName = new System.Windows.Forms.TextBox();
|
||||
maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||
ButtonAddTrain = new System.Windows.Forms.Button();
|
||||
ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
ButtonRemoveTrain = new System.Windows.Forms.Button();
|
||||
menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
filesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
panel1.SuspendLayout();
|
||||
panel2.SuspendLayout();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||
pictureBoxCollection.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new System.Drawing.Size(738, 546);
|
||||
pictureBoxCollection.TabIndex = 0;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.AccessibleName = "";
|
||||
panel1.Controls.Add(panel2);
|
||||
panel1.Controls.Add(maskedTextBoxNumber);
|
||||
panel1.Controls.Add(ButtonAddTrain);
|
||||
panel1.Controls.Add(ButtonRefreshCollection);
|
||||
panel1.Controls.Add(ButtonRemoveTrain);
|
||||
panel1.Controls.Add(menuStrip1);
|
||||
panel1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
panel1.Location = new System.Drawing.Point(745, 0);
|
||||
panel1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new System.Drawing.Size(194, 546);
|
||||
panel1.TabIndex = 1;
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
panel2.AccessibleName = "";
|
||||
panel2.Controls.Add(buttonRemoveSet);
|
||||
panel2.Controls.Add(listBoxStorage);
|
||||
panel2.Controls.Add(buttonAddSet);
|
||||
panel2.Controls.Add(textBoxSetName);
|
||||
panel2.Location = new System.Drawing.Point(18, 98);
|
||||
panel2.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panel2.Name = "panel2";
|
||||
panel2.Size = new System.Drawing.Size(163, 240);
|
||||
panel2.TabIndex = 5;
|
||||
//
|
||||
// buttonRemoveSet
|
||||
//
|
||||
buttonRemoveSet.Location = new System.Drawing.Point(9, 194);
|
||||
buttonRemoveSet.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
buttonRemoveSet.Name = "buttonRemoveSet";
|
||||
buttonRemoveSet.Size = new System.Drawing.Size(140, 27);
|
||||
buttonRemoveSet.TabIndex = 3;
|
||||
buttonRemoveSet.Text = "Remove set";
|
||||
buttonRemoveSet.UseVisualStyleBackColor = true;
|
||||
buttonRemoveSet.Click += buttonRemoveSet_Click;
|
||||
//
|
||||
// listBoxStorage
|
||||
//
|
||||
listBoxStorage.FormattingEnabled = true;
|
||||
listBoxStorage.ItemHeight = 15;
|
||||
listBoxStorage.Location = new System.Drawing.Point(9, 77);
|
||||
listBoxStorage.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
listBoxStorage.Name = "listBoxStorage";
|
||||
listBoxStorage.Size = new System.Drawing.Size(139, 109);
|
||||
listBoxStorage.TabIndex = 2;
|
||||
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
|
||||
//
|
||||
// buttonAddSet
|
||||
//
|
||||
buttonAddSet.Location = new System.Drawing.Point(9, 44);
|
||||
buttonAddSet.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
buttonAddSet.Name = "buttonAddSet";
|
||||
buttonAddSet.Size = new System.Drawing.Size(140, 27);
|
||||
buttonAddSet.TabIndex = 1;
|
||||
buttonAddSet.Text = "Add set";
|
||||
buttonAddSet.UseVisualStyleBackColor = true;
|
||||
buttonAddSet.Click += buttonAddSet_Click;
|
||||
//
|
||||
// textBoxSetName
|
||||
//
|
||||
textBoxSetName.Location = new System.Drawing.Point(9, 14);
|
||||
textBoxSetName.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
textBoxSetName.Name = "textBoxSetName";
|
||||
textBoxSetName.Size = new System.Drawing.Size(139, 23);
|
||||
textBoxSetName.TabIndex = 0;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new System.Drawing.Point(38, 421);
|
||||
maskedTextBoxNumber.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new System.Drawing.Size(116, 23);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
//
|
||||
// ButtonAddTrain
|
||||
//
|
||||
ButtonAddTrain.Location = new System.Drawing.Point(50, 377);
|
||||
ButtonAddTrain.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
ButtonAddTrain.Name = "ButtonAddTrain";
|
||||
ButtonAddTrain.Size = new System.Drawing.Size(88, 27);
|
||||
ButtonAddTrain.TabIndex = 3;
|
||||
ButtonAddTrain.Text = "Add Train";
|
||||
ButtonAddTrain.UseVisualStyleBackColor = true;
|
||||
ButtonAddTrain.Click += ButtonAddTrain_Click;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Location = new System.Drawing.Point(24, 505);
|
||||
ButtonRefreshCollection.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new System.Drawing.Size(141, 27);
|
||||
ButtonRefreshCollection.TabIndex = 2;
|
||||
ButtonRefreshCollection.Text = "Refresh Collection";
|
||||
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// ButtonRemoveTrain
|
||||
//
|
||||
ButtonRemoveTrain.Location = new System.Drawing.Point(38, 462);
|
||||
ButtonRemoveTrain.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
ButtonRemoveTrain.Name = "ButtonRemoveTrain";
|
||||
ButtonRemoveTrain.Size = new System.Drawing.Size(117, 27);
|
||||
ButtonRemoveTrain.TabIndex = 0;
|
||||
ButtonRemoveTrain.Text = "Remove Train";
|
||||
ButtonRemoveTrain.UseVisualStyleBackColor = true;
|
||||
ButtonRemoveTrain.Click += ButtonRemoveTrain_Click;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { filesToolStripMenuItem });
|
||||
menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new System.Drawing.Size(194, 24);
|
||||
menuStrip1.TabIndex = 6;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// filesToolStripMenuItem
|
||||
//
|
||||
filesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
|
||||
filesToolStripMenuItem.Name = "filesToolStripMenuItem";
|
||||
filesToolStripMenuItem.Size = new System.Drawing.Size(42, 20);
|
||||
filesToolStripMenuItem.Text = "Files";
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
saveToolStripMenuItem.Text = "Save";
|
||||
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// loadToolStripMenuItem
|
||||
//
|
||||
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
loadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
loadToolStripMenuItem.Text = "Load";
|
||||
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.FileName = "TrainSave.txt";
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.FileName = "TrainSave.txt";
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormTrainCollection
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(939, 546);
|
||||
Controls.Add(panel1);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
Name = "FormTrainCollection";
|
||||
Text = "FormTrainCollection";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
panel1.ResumeLayout(false);
|
||||
panel1.PerformLayout();
|
||||
panel2.ResumeLayout(false);
|
||||
panel2.PerformLayout();
|
||||
menuStrip1.ResumeLayout(false);
|
||||
menuStrip1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.PictureBox pictureBoxCollection;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.Button ButtonRefreshCollection;
|
||||
private System.Windows.Forms.Button ButtonRemoveTrain;
|
||||
private System.Windows.Forms.Button ButtonAddTrain;
|
||||
private System.Windows.Forms.TextBox maskedTextBoxNumber;
|
||||
private System.Windows.Forms.Panel panel2;
|
||||
private System.Windows.Forms.Button buttonRemoveSet;
|
||||
private System.Windows.Forms.ListBox listBoxStorage;
|
||||
private System.Windows.Forms.Button buttonAddSet;
|
||||
private System.Windows.Forms.TextBox textBoxSetName;
|
||||
private System.Windows.Forms.MenuStrip menuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem filesToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem loadToolStripMenuItem;
|
||||
private System.Windows.Forms.OpenFileDialog openFileDialog;
|
||||
private System.Windows.Forms.SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
238
Laba1Loco/Laba1Loco/FormTrainCollection.cs
Normal file
238
Laba1Loco/Laba1Loco/FormTrainCollection.cs
Normal file
@ -0,0 +1,238 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
public partial class FormTrainCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly TrainsGenericStorage _storage;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormTrainCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new TrainsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxObjects
|
||||
/// </summary>
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorage.SelectedIndex;
|
||||
listBoxStorage.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorage.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorage.Items.Count > 0 && (index == -1 || index >= listBoxStorage.Items.Count))
|
||||
{
|
||||
listBoxStorage.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorage.Items.Count > 0 && index > -1 && index < listBoxStorage.Items.Count)
|
||||
{
|
||||
listBoxStorage.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddTrain(DrawingTrain train)
|
||||
{
|
||||
//проверка что бы ничего не сломалось
|
||||
if (listBoxStorage.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ((obj + train) != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowTrains();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddTrain_Click(object sender, EventArgs e)
|
||||
{
|
||||
//проверка что бы не вызывалась формочка
|
||||
if (listBoxStorage.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormTrainConfig form = new FormTrainConfig();
|
||||
form.Show();
|
||||
form.AddEvent(AddTrain);
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveTrain_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorage.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var it in maskedTextBoxNumber.Text)
|
||||
if (it < '0' || it > '9')
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
return;
|
||||
}
|
||||
if (maskedTextBoxNumber.Text.Length == 0)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowTrains();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorage.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
pictureBoxCollection.Image = obj.ShowTrains();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление набора в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonAddSet_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxSetName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxSetName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void listBoxStorage_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowTrains();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonRemoveSet_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorage.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект { listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorage.SelectedItem.ToString()?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.SaveData(saveFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Сохранение прошло успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Загрузка прошла успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
129
Laba1Loco/Laba1Loco/FormTrainCollection.resx
Normal file
129
Laba1Loco/Laba1Loco/FormTrainCollection.resx
Normal file
@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>132, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>271, 17</value>
|
||||
</metadata>
|
||||
</root>
|
397
Laba1Loco/Laba1Loco/FormTrainConfig.Designer.cs
generated
Normal file
397
Laba1Loco/Laba1Loco/FormTrainConfig.Designer.cs
generated
Normal file
@ -0,0 +1,397 @@
|
||||
namespace Laba1Loco
|
||||
{
|
||||
partial class FormTrainConfig
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
ParamsGroup = new System.Windows.Forms.GroupBox();
|
||||
labelLoco = new System.Windows.Forms.Label();
|
||||
labelTrain = new System.Windows.Forms.Label();
|
||||
groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||
panelPurple = new System.Windows.Forms.Panel();
|
||||
panelYellow = new System.Windows.Forms.Panel();
|
||||
panelBlue = new System.Windows.Forms.Panel();
|
||||
panelRed = new System.Windows.Forms.Panel();
|
||||
panelDarkBlue = new System.Windows.Forms.Panel();
|
||||
panelOrange = new System.Windows.Forms.Panel();
|
||||
panelGreen = new System.Windows.Forms.Panel();
|
||||
panelGray = new System.Windows.Forms.Panel();
|
||||
checkBoxFuelTank = new System.Windows.Forms.CheckBox();
|
||||
checkBoxSmokeTube = new System.Windows.Forms.CheckBox();
|
||||
checkBoxLocoLine = new System.Windows.Forms.CheckBox();
|
||||
numericWeight = new System.Windows.Forms.NumericUpDown();
|
||||
numericSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
weightLabel = new System.Windows.Forms.Label();
|
||||
speedLabel = new System.Windows.Forms.Label();
|
||||
panel9 = new System.Windows.Forms.Panel();
|
||||
pictureBox = new System.Windows.Forms.PictureBox();
|
||||
buttonAdd = new System.Windows.Forms.Button();
|
||||
buttonCancel = new System.Windows.Forms.Button();
|
||||
labelColor = new System.Windows.Forms.Label();
|
||||
labelAdditionalColor = new System.Windows.Forms.Label();
|
||||
ParamsGroup.SuspendLayout();
|
||||
groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericWeight).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericSpeed).BeginInit();
|
||||
panel9.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// ParamsGroup
|
||||
//
|
||||
ParamsGroup.Controls.Add(labelLoco);
|
||||
ParamsGroup.Controls.Add(labelTrain);
|
||||
ParamsGroup.Controls.Add(groupBoxColors);
|
||||
ParamsGroup.Controls.Add(checkBoxFuelTank);
|
||||
ParamsGroup.Controls.Add(checkBoxSmokeTube);
|
||||
ParamsGroup.Controls.Add(checkBoxLocoLine);
|
||||
ParamsGroup.Controls.Add(numericWeight);
|
||||
ParamsGroup.Controls.Add(numericSpeed);
|
||||
ParamsGroup.Controls.Add(weightLabel);
|
||||
ParamsGroup.Controls.Add(speedLabel);
|
||||
ParamsGroup.Location = new System.Drawing.Point(4, 2);
|
||||
ParamsGroup.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
ParamsGroup.Name = "ParamsGroup";
|
||||
ParamsGroup.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
ParamsGroup.Size = new System.Drawing.Size(210, 555);
|
||||
ParamsGroup.TabIndex = 0;
|
||||
ParamsGroup.TabStop = false;
|
||||
ParamsGroup.Text = "Params Group Box";
|
||||
//
|
||||
// labelLoco
|
||||
//
|
||||
labelLoco.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
labelLoco.Location = new System.Drawing.Point(105, 483);
|
||||
labelLoco.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
labelLoco.Name = "labelLoco";
|
||||
labelLoco.Size = new System.Drawing.Size(76, 42);
|
||||
labelLoco.TabIndex = 10;
|
||||
labelLoco.Text = "Loco";
|
||||
labelLoco.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
labelLoco.MouseDown += LabelObject_MouseDown;
|
||||
//
|
||||
// labelTrain
|
||||
//
|
||||
labelTrain.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
labelTrain.Location = new System.Drawing.Point(16, 483);
|
||||
labelTrain.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
labelTrain.Name = "labelTrain";
|
||||
labelTrain.Size = new System.Drawing.Size(76, 42);
|
||||
labelTrain.TabIndex = 9;
|
||||
labelTrain.Text = "Train";
|
||||
labelTrain.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
labelTrain.MouseDown += LabelObject_MouseDown;
|
||||
//
|
||||
// groupBoxColors
|
||||
//
|
||||
groupBoxColors.Controls.Add(panelPurple);
|
||||
groupBoxColors.Controls.Add(panelYellow);
|
||||
groupBoxColors.Controls.Add(panelBlue);
|
||||
groupBoxColors.Controls.Add(panelRed);
|
||||
groupBoxColors.Controls.Add(panelDarkBlue);
|
||||
groupBoxColors.Controls.Add(panelOrange);
|
||||
groupBoxColors.Controls.Add(panelGreen);
|
||||
groupBoxColors.Controls.Add(panelGray);
|
||||
groupBoxColors.Location = new System.Drawing.Point(14, 201);
|
||||
groupBoxColors.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
groupBoxColors.Name = "groupBoxColors";
|
||||
groupBoxColors.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
groupBoxColors.Size = new System.Drawing.Size(184, 261);
|
||||
groupBoxColors.TabIndex = 8;
|
||||
groupBoxColors.TabStop = false;
|
||||
groupBoxColors.Text = "Colors";
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
panelPurple.BackColor = System.Drawing.Color.Fuchsia;
|
||||
panelPurple.Location = new System.Drawing.Point(94, 207);
|
||||
panelPurple.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panelPurple.Name = "panelPurple";
|
||||
panelPurple.Size = new System.Drawing.Size(49, 46);
|
||||
panelPurple.TabIndex = 3;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||
panelYellow.Location = new System.Drawing.Point(94, 81);
|
||||
panelYellow.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panelYellow.Name = "panelYellow";
|
||||
panelYellow.Size = new System.Drawing.Size(49, 46);
|
||||
panelYellow.TabIndex = 1;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
panelBlue.BackColor = System.Drawing.Color.Cyan;
|
||||
panelBlue.Location = new System.Drawing.Point(94, 144);
|
||||
panelBlue.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panelBlue.Name = "panelBlue";
|
||||
panelBlue.Size = new System.Drawing.Size(49, 46);
|
||||
panelBlue.TabIndex = 4;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
panelRed.BackColor = System.Drawing.Color.Red;
|
||||
panelRed.Location = new System.Drawing.Point(94, 18);
|
||||
panelRed.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panelRed.Name = "panelRed";
|
||||
panelRed.Size = new System.Drawing.Size(49, 46);
|
||||
panelRed.TabIndex = 1;
|
||||
//
|
||||
// panelDarkBlue
|
||||
//
|
||||
panelDarkBlue.BackColor = System.Drawing.Color.Blue;
|
||||
panelDarkBlue.Location = new System.Drawing.Point(29, 207);
|
||||
panelDarkBlue.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panelDarkBlue.Name = "panelDarkBlue";
|
||||
panelDarkBlue.Size = new System.Drawing.Size(49, 46);
|
||||
panelDarkBlue.TabIndex = 5;
|
||||
//
|
||||
// panelOrange
|
||||
//
|
||||
panelOrange.BackColor = System.Drawing.Color.LightSalmon;
|
||||
panelOrange.Location = new System.Drawing.Point(29, 81);
|
||||
panelOrange.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panelOrange.Name = "panelOrange";
|
||||
panelOrange.Size = new System.Drawing.Size(49, 46);
|
||||
panelOrange.TabIndex = 1;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
panelGreen.BackColor = System.Drawing.Color.Lime;
|
||||
panelGreen.Location = new System.Drawing.Point(29, 144);
|
||||
panelGreen.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panelGreen.Name = "panelGreen";
|
||||
panelGreen.Size = new System.Drawing.Size(49, 46);
|
||||
panelGreen.TabIndex = 2;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
panelGray.BackColor = System.Drawing.Color.Silver;
|
||||
panelGray.Location = new System.Drawing.Point(29, 18);
|
||||
panelGray.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panelGray.Name = "panelGray";
|
||||
panelGray.Size = new System.Drawing.Size(49, 46);
|
||||
panelGray.TabIndex = 0;
|
||||
//
|
||||
// checkBoxFuelTank
|
||||
//
|
||||
checkBoxFuelTank.AutoSize = true;
|
||||
checkBoxFuelTank.Location = new System.Drawing.Point(16, 135);
|
||||
checkBoxFuelTank.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
checkBoxFuelTank.Name = "checkBoxFuelTank";
|
||||
checkBoxFuelTank.Size = new System.Drawing.Size(74, 19);
|
||||
checkBoxFuelTank.TabIndex = 7;
|
||||
checkBoxFuelTank.Text = "Fuel tank";
|
||||
checkBoxFuelTank.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxSmokeTube
|
||||
//
|
||||
checkBoxSmokeTube.AutoSize = true;
|
||||
checkBoxSmokeTube.Location = new System.Drawing.Point(16, 112);
|
||||
checkBoxSmokeTube.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
checkBoxSmokeTube.Name = "checkBoxSmokeTube";
|
||||
checkBoxSmokeTube.Size = new System.Drawing.Size(89, 19);
|
||||
checkBoxSmokeTube.TabIndex = 6;
|
||||
checkBoxSmokeTube.Text = "Smoke tube";
|
||||
checkBoxSmokeTube.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxLocoLine
|
||||
//
|
||||
checkBoxLocoLine.AutoSize = true;
|
||||
checkBoxLocoLine.Location = new System.Drawing.Point(16, 162);
|
||||
checkBoxLocoLine.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
checkBoxLocoLine.Name = "checkBoxLocoLine";
|
||||
checkBoxLocoLine.Size = new System.Drawing.Size(74, 19);
|
||||
checkBoxLocoLine.TabIndex = 5;
|
||||
checkBoxLocoLine.Text = "Loco line";
|
||||
checkBoxLocoLine.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericWeight
|
||||
//
|
||||
numericWeight.Location = new System.Drawing.Point(58, 59);
|
||||
numericWeight.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
numericWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericWeight.Name = "numericWeight";
|
||||
numericWeight.Size = new System.Drawing.Size(140, 23);
|
||||
numericWeight.TabIndex = 4;
|
||||
numericWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// numericSpeed
|
||||
//
|
||||
numericSpeed.Location = new System.Drawing.Point(58, 27);
|
||||
numericSpeed.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
numericSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericSpeed.Name = "numericSpeed";
|
||||
numericSpeed.Size = new System.Drawing.Size(140, 23);
|
||||
numericSpeed.TabIndex = 3;
|
||||
numericSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// weightLabel
|
||||
//
|
||||
weightLabel.AutoSize = true;
|
||||
weightLabel.Location = new System.Drawing.Point(10, 59);
|
||||
weightLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
weightLabel.Name = "weightLabel";
|
||||
weightLabel.Size = new System.Drawing.Size(39, 15);
|
||||
weightLabel.TabIndex = 2;
|
||||
weightLabel.Text = "weigh";
|
||||
//
|
||||
// speedLabel
|
||||
//
|
||||
speedLabel.AutoSize = true;
|
||||
speedLabel.Location = new System.Drawing.Point(10, 29);
|
||||
speedLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
speedLabel.Name = "speedLabel";
|
||||
speedLabel.Size = new System.Drawing.Size(38, 15);
|
||||
speedLabel.TabIndex = 1;
|
||||
speedLabel.Text = "speed";
|
||||
//
|
||||
// panel9
|
||||
//
|
||||
panel9.AllowDrop = true;
|
||||
panel9.Controls.Add(pictureBox);
|
||||
panel9.Location = new System.Drawing.Point(233, 87);
|
||||
panel9.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panel9.Name = "panel9";
|
||||
panel9.Size = new System.Drawing.Size(686, 390);
|
||||
panel9.TabIndex = 11;
|
||||
panel9.DragDrop += PanelObject_DragDrop;
|
||||
panel9.DragEnter += PanelObject_DragEnter;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Location = new System.Drawing.Point(16, 6);
|
||||
pictureBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new System.Drawing.Size(648, 381);
|
||||
pictureBox.TabIndex = 0;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.Location = new System.Drawing.Point(233, 486);
|
||||
buttonAdd.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new System.Drawing.Size(88, 27);
|
||||
buttonAdd.TabIndex = 12;
|
||||
buttonAdd.Text = "Add";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += ButtonOk_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new System.Drawing.Point(601, 486);
|
||||
buttonCancel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new System.Drawing.Size(88, 27);
|
||||
buttonCancel.TabIndex = 13;
|
||||
buttonCancel.Text = "Cancel";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// labelColor
|
||||
//
|
||||
labelColor.AllowDrop = true;
|
||||
labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
labelColor.Location = new System.Drawing.Point(233, 29);
|
||||
labelColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
labelColor.Name = "labelColor";
|
||||
labelColor.Size = new System.Drawing.Size(116, 26);
|
||||
labelColor.TabIndex = 14;
|
||||
labelColor.Text = "Color";
|
||||
labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
labelColor.DragDrop += labelColor_DragDrop;
|
||||
labelColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// labelAdditionalColor
|
||||
//
|
||||
labelAdditionalColor.AllowDrop = true;
|
||||
labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
labelAdditionalColor.Location = new System.Drawing.Point(601, 28);
|
||||
labelAdditionalColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||
labelAdditionalColor.Size = new System.Drawing.Size(116, 26);
|
||||
labelAdditionalColor.TabIndex = 15;
|
||||
labelAdditionalColor.Text = "Additional color";
|
||||
labelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
labelAdditionalColor.DragDrop += labelColor_DragDrop;
|
||||
labelAdditionalColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// FormTrainConfig
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(933, 558);
|
||||
Controls.Add(labelAdditionalColor);
|
||||
Controls.Add(labelColor);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonAdd);
|
||||
Controls.Add(panel9);
|
||||
Controls.Add(ParamsGroup);
|
||||
Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
Name = "FormTrainConfig";
|
||||
Text = "FormTrainConfig";
|
||||
ParamsGroup.ResumeLayout(false);
|
||||
ParamsGroup.PerformLayout();
|
||||
groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)numericWeight).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericSpeed).EndInit();
|
||||
panel9.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox ParamsGroup;
|
||||
private System.Windows.Forms.CheckBox checkBoxFuelTank;
|
||||
private System.Windows.Forms.CheckBox checkBoxSmokeTube;
|
||||
private System.Windows.Forms.CheckBox checkBoxLocoLine;
|
||||
private System.Windows.Forms.NumericUpDown numericWeight;
|
||||
private System.Windows.Forms.NumericUpDown numericSpeed;
|
||||
private System.Windows.Forms.Label weightLabel;
|
||||
private System.Windows.Forms.Label speedLabel;
|
||||
private System.Windows.Forms.GroupBox groupBoxColors;
|
||||
private System.Windows.Forms.Panel panelPurple;
|
||||
private System.Windows.Forms.Panel panelYellow;
|
||||
private System.Windows.Forms.Panel panelBlue;
|
||||
private System.Windows.Forms.Panel panelRed;
|
||||
private System.Windows.Forms.Panel panelDarkBlue;
|
||||
private System.Windows.Forms.Panel panelOrange;
|
||||
private System.Windows.Forms.Panel panelGreen;
|
||||
private System.Windows.Forms.Panel panelGray;
|
||||
private System.Windows.Forms.Label labelLoco;
|
||||
private System.Windows.Forms.Label labelTrain;
|
||||
private System.Windows.Forms.Panel panel9;
|
||||
private System.Windows.Forms.PictureBox pictureBox;
|
||||
private System.Windows.Forms.Button buttonAdd;
|
||||
private System.Windows.Forms.Button buttonCancel;
|
||||
private System.Windows.Forms.Label labelColor;
|
||||
private System.Windows.Forms.Label labelAdditionalColor;
|
||||
}
|
||||
}
|
164
Laba1Loco/Laba1Loco/FormTrainConfig.cs
Normal file
164
Laba1Loco/Laba1Loco/FormTrainConfig.cs
Normal file
@ -0,0 +1,164 @@
|
||||
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 Laba1Loco
|
||||
{
|
||||
public partial class FormTrainConfig : Form
|
||||
{
|
||||
Color defaultColor;
|
||||
/// <summary>
|
||||
/// Переменная-выбранный поезд
|
||||
/// </summary>
|
||||
DrawingTrain _train = null;
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event Action<DrawingTrain> EventAddTrain;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormTrainConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
panelGray.MouseDown += panelColor_MouseDown;
|
||||
panelRed.MouseDown += panelColor_MouseDown;
|
||||
panelOrange.MouseDown += panelColor_MouseDown;
|
||||
panelYellow.MouseDown += panelColor_MouseDown;
|
||||
panelGreen.MouseDown += panelColor_MouseDown;
|
||||
panelBlue.MouseDown += panelColor_MouseDown;
|
||||
panelDarkBlue.MouseDown += panelColor_MouseDown;
|
||||
panelPurple.MouseDown += panelColor_MouseDown;
|
||||
|
||||
defaultColor = labelColor.BackColor;
|
||||
buttonCancel.Click += (s, e) => Close();
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовать поезд
|
||||
/// </summary>
|
||||
private void DrawTrain()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(pictureBox.Width, pictureBox.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_train?.SetPosition(5, 5);
|
||||
if (_train is DrawingLoco)
|
||||
(_train as DrawingLoco).DrawTransport(gr);
|
||||
else
|
||||
_train?.DrawTransport(gr);
|
||||
pictureBox.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev">Привязанный метод</param>
|
||||
internal void AddEvent(Action<DrawingTrain> ev)
|
||||
{
|
||||
if (EventAddTrain == null)
|
||||
{
|
||||
EventAddTrain = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddTrain += ev;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Передаем информацию при нажатии на Label
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Действия при приеме перетаскиваемой информации
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelTrain":
|
||||
_train = new DrawingTrain((int)numericSpeed.Value,(int)numericWeight.Value, Color.White, pictureBox.Width,pictureBox.Height);
|
||||
break;
|
||||
case "labelLoco":
|
||||
_train = new DrawingLoco((int)numericSpeed.Value,(int)numericWeight.Value, Color.White, Color.Black, checkBoxSmokeTube.Checked, checkBoxFuelTank.Checked, checkBoxLocoLine.Checked, pictureBox.Width, pictureBox.Height);
|
||||
break;
|
||||
}
|
||||
labelColor.BackColor = defaultColor;
|
||||
labelAdditionalColor.BackColor = defaultColor;
|
||||
DrawTrain();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление поезда
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddTrain?.Invoke(_train);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void panelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void labelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_train == null)
|
||||
return;
|
||||
((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||
switch (((Label)sender).Name)
|
||||
{
|
||||
case "labelColor":
|
||||
_train.EntityTrain.setBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
case "labelAdditionalColor":
|
||||
if (!(_train is DrawingLoco))
|
||||
return;
|
||||
(_train.EntityTrain as EntityLoco).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
}
|
||||
DrawTrain();
|
||||
}
|
||||
}
|
||||
}
|
120
Laba1Loco/Laba1Loco/FormTrainConfig.resx
Normal file
120
Laba1Loco/Laba1Loco/FormTrainConfig.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
32
Laba1Loco/Laba1Loco/IMoveableObject.cs
Normal file
32
Laba1Loco/Laba1Loco/IMoveableObject.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты X объекта
|
||||
/// </summary>
|
||||
ObjectParameters GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Проверка, можно ли переместиться по нужному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool CheckCanMove(Direction direction);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(Direction direction);
|
||||
|
||||
}
|
||||
}
|
13
Laba1Loco/Laba1Loco/Laba1Loco.csproj
Normal file
13
Laba1Loco/Laba1Loco/Laba1Loco.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
56
Laba1Loco/Laba1Loco/MoveToBorder.cs
Normal file
56
Laba1Loco/Laba1Loco/MoveToBorder.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
Laba1Loco/Laba1Loco/MoveToCenter.cs
Normal file
57
Laba1Loco/Laba1Loco/MoveToCenter.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return
|
||||
Math.Abs(objParams.ObjectMiddleHorizontal - FieldWidth / 2) <= GetStep()
|
||||
&&
|
||||
Math.Abs(objParams.ObjectMiddleVertical - FieldHeight / 2) <= GetStep();
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
55
Laba1Loco/Laba1Loco/ObjectParameters.cs
Normal file
55
Laba1Loco/Laba1Loco/ObjectParameters.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
22
Laba1Loco/Laba1Loco/Program.cs
Normal file
22
Laba1Loco/Laba1Loco/Program.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// Главная точка входа для приложения.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormTrainCollection());
|
||||
}
|
||||
}
|
||||
}
|
113
Laba1Loco/Laba1Loco/Properties/Resources.Designer.cs
generated
Normal file
113
Laba1Loco/Laba1Loco/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,113 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Laba1Loco.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Laba1Loco.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arow340x259 {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arow340x259", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arowDown340x259 {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arowDown340x259", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arowL340x259 {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arowL340x259", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arowR340x259 {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arowR340x259", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arowUp340x259 {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arowUp340x259", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
136
Laba1Loco/Laba1Loco/Properties/Resources.resx
Normal file
136
Laba1Loco/Laba1Loco/Properties/Resources.resx
Normal file
@ -0,0 +1,136 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="arow340x259" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\arow340x259.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arowDown340x259" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\arowDown340x259.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arowL340x259" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\arowL340x259.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arowR340x259" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\arowR340x259.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arowUp340x259" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\arowUp340x259.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
26
Laba1Loco/Laba1Loco/Properties/Settings.Designer.cs
generated
Normal file
26
Laba1Loco/Laba1Loco/Properties/Settings.Designer.cs
generated
Normal file
@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Laba1Loco.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.8.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
7
Laba1Loco/Laba1Loco/Properties/Settings.settings
Normal file
7
Laba1Loco/Laba1Loco/Properties/Settings.settings
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
128
Laba1Loco/Laba1Loco/SetGeneric.cs
Normal file
128
Laba1Loco/Laba1Loco/SetGeneric.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Count;
|
||||
/// <summary>
|
||||
/// Максимальное количество объектов в списке
|
||||
/// </summary>
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="train">Добавляемый поезд</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T train)
|
||||
{
|
||||
if (_places.Count >= _maxCount)
|
||||
return -1;
|
||||
_places.Insert(0, train);
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="train">Добавляемый поезд</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T train, int position)
|
||||
{
|
||||
if (_places.Count >= _maxCount)
|
||||
return false;
|
||||
|
||||
if (position < 0 || position > _places.Count)
|
||||
return false;
|
||||
|
||||
if (position == _places.Count)
|
||||
_places.Add(train);
|
||||
else
|
||||
_places.Insert(position, train);
|
||||
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Count)
|
||||
return false;
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Count)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= _places.Count)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
Insert(value, position);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetTrains(int? maxTrains = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxTrains.HasValue && i == maxTrains.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
15
Laba1Loco/Laba1Loco/Status.cs
Normal file
15
Laba1Loco/Laba1Loco/Status.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
143
Laba1Loco/Laba1Loco/TrainsGenericCollection.cs
Normal file
143
Laba1Loco/Laba1Loco/TrainsGenericCollection.cs
Normal file
@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class TrainsGenericCollection<T, U>
|
||||
where T : DrawingTrain
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T> GetTrains => _collection.GetTrains();
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public TrainsGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(TrainsGenericCollection<T, U> collect, T obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static T operator -(TrainsGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U GetU(int pos)
|
||||
{
|
||||
return (U)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowTrains()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var train in _collection.GetTrains())
|
||||
{
|
||||
if (train != null)
|
||||
{
|
||||
train._pictureHeight = _pictureHeight;
|
||||
train._pictureWidth = _pictureWidth;
|
||||
train.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
|
||||
if (train is DrawingLoco)
|
||||
(train as DrawingLoco).DrawTransport(g);
|
||||
else
|
||||
train.DrawTransport(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
167
Laba1Loco/Laba1Loco/TrainsGenericStorage.cs
Normal file
167
Laba1Loco/Laba1Loco/TrainsGenericStorage.cs
Normal file
@ -0,0 +1,167 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class TrainsGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
/// </summary>
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char _separatorRecords = ';';
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение информации по поездам в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при cохранении данных</returns>
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new StringBuilder();
|
||||
foreach (KeyValuePair<string, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>> record in _trainStorages)
|
||||
{
|
||||
StringBuilder records = new StringBuilder();
|
||||
foreach (DrawingTrain elem in record.Value.GetTrains)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamWriter sr = new StreamWriter(filename))
|
||||
{
|
||||
sr.Write($"TrainStorage{Environment.NewLine}{data}");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка информации по поездам в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка призагрузке данных</returns>
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
string s = sr.ReadLine();
|
||||
if (s == null || s.Length == 0)
|
||||
return false;
|
||||
if (!s.StartsWith("TrainStorage"))//если нет такой записи, то это не те данные
|
||||
return false;
|
||||
_trainStorages.Clear();
|
||||
s = sr.ReadLine();
|
||||
while (s != null && s.Length != 0)
|
||||
{
|
||||
string[] record = s.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
s = sr.ReadLine();
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TrainsGenericCollection<DrawingTrain, DrawningObjectTrain> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set.Reverse())
|
||||
{
|
||||
DrawingTrain train = elem?.CreateDrawingTrain(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (train != null)
|
||||
{
|
||||
if (collection + train == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_trainStorages.Add(record[0], collection);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>> _trainStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _trainStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public TrainsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_trainStorages = new Dictionary<string, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (_trainStorages.ContainsKey(name))
|
||||
return;
|
||||
_trainStorages[name] = new TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_trainStorages.ContainsKey(name))
|
||||
return;
|
||||
_trainStorages.Remove(name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>
|
||||
this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_trainStorages.ContainsKey(ind))
|
||||
return _trainStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
BIN
Laba1Loco/Laba1Loco/arow340x259.png
Normal file
BIN
Laba1Loco/Laba1Loco/arow340x259.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 541 B |
BIN
Laba1Loco/Laba1Loco/arowDown340x259.png
Normal file
BIN
Laba1Loco/Laba1Loco/arowDown340x259.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 546 B |
BIN
Laba1Loco/Laba1Loco/arowL340x259.png
Normal file
BIN
Laba1Loco/Laba1Loco/arowL340x259.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 518 B |
BIN
Laba1Loco/Laba1Loco/arowR340x259.png
Normal file
BIN
Laba1Loco/Laba1Loco/arowR340x259.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 513 B |
BIN
Laba1Loco/Laba1Loco/arowUp340x259.png
Normal file
BIN
Laba1Loco/Laba1Loco/arowUp340x259.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 541 B |
Loading…
Reference in New Issue
Block a user