diff --git a/Trolleybus/Trolleybus/AbstractMap.cs b/Trolleybus/Trolleybus/AbstractMap.cs
index 39a1034..d4f0c87 100644
--- a/Trolleybus/Trolleybus/AbstractMap.cs
+++ b/Trolleybus/Trolleybus/AbstractMap.cs
@@ -86,8 +86,8 @@ namespace Trolleybus
return false;
}
- float airplaneWidth = rightX - leftX;
- float airplaneHeight = bottomY - topY;
+ float trolleybusWidth = rightX - leftX;
+ float trolleybusHeight = bottomY - topY;
int x = _random.Next(0, 10);
int y = _random.Next(0, 10);
@@ -97,7 +97,7 @@ namespace Trolleybus
{
if (_map[i, j] == _barrier)
{
- if (x + airplaneWidth >= _size_x * i && x <= _size_x * i && y + airplaneHeight > _size_y * j && y <= _size_y * j)
+ if (x + trolleybusWidth >= _size_x * i && x <= _size_x * i && y + trolleybusHeight > _size_y * j && y <= _size_y * j)
{
return false;
}
diff --git a/Trolleybus/Trolleybus/DrawingTrolleybus.cs b/Trolleybus/Trolleybus/DrawingTrolleybus.cs
index 38c81ca..cd3a288 100644
--- a/Trolleybus/Trolleybus/DrawingTrolleybus.cs
+++ b/Trolleybus/Trolleybus/DrawingTrolleybus.cs
@@ -56,9 +56,9 @@ namespace Trolleybus
{
Trolleybus = new EntityTrolleybus(speed, weight, bodyColor);
}
- protected DrawingTrolleybus(int speed, float weight, Color bodyColor, int trolleybusWidth, int trolleybusHeight)
+ protected DrawingTrolleybus(int speed, float weight, Color bodyColor, int trolleybusWidth, int trolleybusHeight) :
+ this(speed, weight, bodyColor)
{
- Trolleybus = new EntityTrolleybus(speed, weight, bodyColor);
_trolleybusWidth = trolleybusWidth;
_trolleybusHeight = trolleybusHeight;
}
@@ -69,13 +69,10 @@ namespace Trolleybus
/// Координата Y
/// Ширина картинки
/// Высота картинки
-// public void SetPosition(int x, int y, int startX, int startY, int width, int height)
public void SetPosition(int x, int y, int width, int height)
{
_startPosX = x;
_startPosY = y;
-// _startX = startX;
-// _startY = startY;
_pictureWidth = width;
_pictureHeight = height;
}
@@ -93,22 +90,20 @@ namespace Trolleybus
{
//вправо
case Direction.Right:
- if(_startPosX + _trolleybusWidth + Trolleybus.Step < _pictureWidth)
+ if (_startPosX + _trolleybusWidth + Trolleybus.Step < _pictureWidth)
{
_startPosX += Trolleybus.Step;
}
break;
//влево
case Direction.Left:
-// if (_startPosX > _startX)
if (_startPosX - Trolleybus.Step > 0)
- {
- _startPosX -= Trolleybus.Step;
+ {
+ _startPosX -= Trolleybus.Step;
}
break;
//вверх
case Direction.Up:
-// if (_startPosY > _startY)
if (_startPosY - Trolleybus.Step > 0)
{
_startPosY -= Trolleybus.Step;
diff --git a/Trolleybus/Trolleybus/DrawningObjectTrolleybus.cs b/Trolleybus/Trolleybus/DrawningObjectTrolleybus.cs
index 183441f..b23f0b0 100644
--- a/Trolleybus/Trolleybus/DrawningObjectTrolleybus.cs
+++ b/Trolleybus/Trolleybus/DrawningObjectTrolleybus.cs
@@ -45,9 +45,6 @@ namespace Trolleybus
public string GetInfo() => _trolleybus?.GetDataForSave();
- public static IDrawningObject Create(string data)
- {
- return new DrawningObjectTrolleybus(data.CreateDrawingTrolleybus());
- }
+ public static IDrawningObject Create(string data) => new DrawningObjectTrolleybus(data.CreateDrawingTrolleybus());
}
}
diff --git a/Trolleybus/Trolleybus/ExtentionTrolleybus.cs b/Trolleybus/Trolleybus/ExtentionTrolleybus.cs
index a4253aa..2721475 100644
--- a/Trolleybus/Trolleybus/ExtentionTrolleybus.cs
+++ b/Trolleybus/Trolleybus/ExtentionTrolleybus.cs
@@ -19,7 +19,7 @@ namespace Trolleybus
return new DrawingTrolleybus(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
- if (strs.Length == 6)
+ if (strs.Length == 7)
{
return new DrawningSmallTrolleybus(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
@@ -37,7 +37,7 @@ namespace Trolleybus
{
return str;
}
- return $"{str}{_separatorForObject}{smallTrolleybus.DopColor.Name}{_separatorForObject}{smallTrolleybus.Horns}{_separatorForObject}{smallTrolleybus.Battary}";
+ return $"{str}{_separatorForObject}{smallTrolleybus.DopColor.Name}{_separatorForObject}{smallTrolleybus.BodyKit}{_separatorForObject}{smallTrolleybus.Horns}{_separatorForObject}{smallTrolleybus.Battary}";
}
}
}
diff --git a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs
index 8eb25ac..9377e39 100644
--- a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs
+++ b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs
@@ -62,6 +62,11 @@ namespace Trolleybus
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
+ if (textBoxNewMapName.Text.Contains('|') || textBoxNewMapName.Text.Contains(':') || textBoxNewMapName.Text.Contains(';'))
+ {
+ MessageBox.Show("Присутствуют символы, недопустимые для имени карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
_logger.LogInformation($"Добвлена карта {textBoxNewMapName.Text}");
diff --git a/Trolleybus/Trolleybus/MapWithSetTrolleybusGeneric.cs b/Trolleybus/Trolleybus/MapWithSetTrolleybusGeneric.cs
index 6e082f9..07f276b 100644
--- a/Trolleybus/Trolleybus/MapWithSetTrolleybusGeneric.cs
+++ b/Trolleybus/Trolleybus/MapWithSetTrolleybusGeneric.cs
@@ -89,13 +89,9 @@ namespace Trolleybus
public Bitmap ShowOnMap()
{
Shaking();
- for (int i = 0; i < _setTrolleybus.Count; i++)
+ foreach (var trolleybus in _setTrolleybus.GetTrolleybus())
{
- var car = _setTrolleybus[i];
- if (car != null)
- {
- return _map.CreateMap(_pictureWidth, _pictureHeight, car);
- }
+ return _map.CreateMap(_pictureWidth, _pictureHeight, trolleybus);
}
return new(_pictureWidth, _pictureHeight);
}
@@ -116,9 +112,9 @@ namespace Trolleybus
public string GetData(char separatorType, char separatorData)
{
string data = $"{_map.GetType().Name}{separatorType}";
- foreach (var tractor in _setTrolleybus.GetTrolleybus())
+ foreach(var trolleybus in _setTrolleybus.GetTrolleybus())
{
- data += $"{tractor.GetInfo()}{separatorData}";
+ data += $"{trolleybus.GetInfo()}{separatorData}";
}
return data;
}
@@ -127,7 +123,8 @@ namespace Trolleybus
{
foreach (var rec in records)
{
- _setTrolleybus.Insert(DrawningObjectTrolleybus.Create(rec) as T);
+ if (rec != "")
+ _setTrolleybus.Insert(DrawningObjectTrolleybus.Create(rec) as T);
}
}
///
@@ -180,24 +177,24 @@ namespace Trolleybus
///
private void DrawTrolleybus(Graphics g)
{
- int xForLocomotive = _pictureWidth - 2 * _placeSizeWidth + 60;
- int yForLocomotive = 10;
+ int xForTrolleybus = _pictureWidth - 2 * _placeSizeWidth + 60;
+ int yForTrolleybus = 10;
int countInRow = 0;
for (int i = 0; i < _setTrolleybus.Count; i++)
{
if (countInRow >= _pictureWidth / (_placeSizeWidth + 30))
{
- xForLocomotive = _pictureWidth - 2 * _placeSizeWidth + 60;
- yForLocomotive += _placeSizeHeight;
+ xForTrolleybus = _pictureWidth - 2 * _placeSizeWidth + 60;
+ yForTrolleybus += _placeSizeHeight;
countInRow = 0;
}
if (_setTrolleybus[i] != null)
{
- T locomotive = _setTrolleybus[i];
- locomotive.SetObject(xForLocomotive, yForLocomotive, _pictureWidth, _pictureHeight);
- locomotive.DrawningObject(g);
+ T trolleybus = _setTrolleybus[i];
+ trolleybus.SetObject(xForTrolleybus, yForTrolleybus, _pictureWidth, _pictureHeight);
+ trolleybus.DrawningObject(g);
}
- xForLocomotive -= _placeSizeWidth + 30;
+ xForTrolleybus -= _placeSizeWidth + 30;
countInRow++;
}
diff --git a/Trolleybus/Trolleybus/MapsCollection.cs b/Trolleybus/Trolleybus/MapsCollection.cs
index 7824eda..86d5080 100644
--- a/Trolleybus/Trolleybus/MapsCollection.cs
+++ b/Trolleybus/Trolleybus/MapsCollection.cs
@@ -36,15 +36,16 @@ namespace Trolleybus
/// Карта
public void AddMap(string name, AbstractMap map)
{
- if (Keys.Contains(name))
- return;
- _mapStorages.Add(name, new(_pictureWidth, _pictureHeight, map));
+ if (!_mapStorages.ContainsKey(name))
+ {
+ _mapStorages.Add(name, new MapWithSetTrolleybusGeneric(_pictureWidth, _pictureHeight, map));
+ }
}
/// Удаление карты
/// Название карты
public void DelMap(string name)
{
- _mapStorages.Remove(name);
+ if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name);
}
/// Доступ к депо
///
@@ -53,8 +54,11 @@ namespace Trolleybus
{
get
{
- _mapStorages.TryGetValue(ind, out var mapWithSetTrolleybusGeneric);
- return mapWithSetTrolleybusGeneric;
+ if (_mapStorages.ContainsKey(ind))
+ {
+ return _mapStorages[ind];
+ }
+ return null;
}
}
diff --git a/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs b/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs
index d4317e9..679c3e8 100644
--- a/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs
+++ b/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs
@@ -51,15 +51,15 @@ namespace Trolleybus
}
// Удаление объекта из набора с конкретной позиции
public T Remove(int position)
- {
- // проверка позиции
- if (!CorrectPos(position))
- return null;
- // удаление объекта из массива, присовив элементу массива значение null
- T temp = _places[position];
- _places.RemoveAt(position);
- return temp;
- }
+ {
+ // проверка позиции
+ if (!CorrectPos(position))
+ return null;
+ // удаление объекта из массива, присовив элементу массива значение null
+ T temp = _places[position];
+ _places.RemoveAt(position);
+ return temp;
+ }
// Получение объекта из набора по позиции
public T this[int position]
{