Решена проблема с загрузкой
This commit is contained in:
parent
88853b2540
commit
50e5b857f7
@ -86,8 +86,8 @@ namespace Trolleybus
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float airplaneWidth = rightX - leftX;
|
float trolleybusWidth = rightX - leftX;
|
||||||
float airplaneHeight = bottomY - topY;
|
float trolleybusHeight = bottomY - topY;
|
||||||
|
|
||||||
int x = _random.Next(0, 10);
|
int x = _random.Next(0, 10);
|
||||||
int y = _random.Next(0, 10);
|
int y = _random.Next(0, 10);
|
||||||
@ -97,7 +97,7 @@ namespace Trolleybus
|
|||||||
{
|
{
|
||||||
if (_map[i, j] == _barrier)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -56,9 +56,9 @@ namespace Trolleybus
|
|||||||
{
|
{
|
||||||
Trolleybus = new EntityTrolleybus(speed, weight, bodyColor);
|
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;
|
_trolleybusWidth = trolleybusWidth;
|
||||||
_trolleybusHeight = trolleybusHeight;
|
_trolleybusHeight = trolleybusHeight;
|
||||||
}
|
}
|
||||||
@ -69,13 +69,10 @@ namespace Trolleybus
|
|||||||
/// <param name="y">Координата Y</param>
|
/// <param name="y">Координата Y</param>
|
||||||
/// <param name="width">Ширина картинки</param>
|
/// <param name="width">Ширина картинки</param>
|
||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
// 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)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
// _startX = startX;
|
|
||||||
// _startY = startY;
|
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
}
|
}
|
||||||
@ -93,14 +90,13 @@ namespace Trolleybus
|
|||||||
{
|
{
|
||||||
//вправо
|
//вправо
|
||||||
case Direction.Right:
|
case Direction.Right:
|
||||||
if(_startPosX + _trolleybusWidth + Trolleybus.Step < _pictureWidth)
|
if (_startPosX + _trolleybusWidth + Trolleybus.Step < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += Trolleybus.Step;
|
_startPosX += Trolleybus.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//влево
|
//влево
|
||||||
case Direction.Left:
|
case Direction.Left:
|
||||||
// if (_startPosX > _startX)
|
|
||||||
if (_startPosX - Trolleybus.Step > 0)
|
if (_startPosX - Trolleybus.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= Trolleybus.Step;
|
_startPosX -= Trolleybus.Step;
|
||||||
@ -108,7 +104,6 @@ namespace Trolleybus
|
|||||||
break;
|
break;
|
||||||
//вверх
|
//вверх
|
||||||
case Direction.Up:
|
case Direction.Up:
|
||||||
// if (_startPosY > _startY)
|
|
||||||
if (_startPosY - Trolleybus.Step > 0)
|
if (_startPosY - Trolleybus.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= Trolleybus.Step;
|
_startPosY -= Trolleybus.Step;
|
||||||
|
@ -47,10 +47,7 @@ namespace Trolleybus
|
|||||||
|
|
||||||
public string GetInfo() => _trolleybus?.GetDataForSave() ?? string.Empty;
|
public string GetInfo() => _trolleybus?.GetDataForSave() ?? string.Empty;
|
||||||
|
|
||||||
public static IDrawningObject Create(string data)
|
public static IDrawningObject Create(string data) => new DrawningObjectTrolleybus(data.CreateDrawingTrolleybus());
|
||||||
{
|
|
||||||
return new DrawningObjectTrolleybus(data.CreateDrawingTrolleybus());
|
|
||||||
}
|
|
||||||
public bool Equals(IDrawningObject? other)
|
public bool Equals(IDrawningObject? other)
|
||||||
{
|
{
|
||||||
if (other is not DrawningObjectTrolleybus otherAirplane)
|
if (other is not DrawningObjectTrolleybus otherAirplane)
|
||||||
|
@ -19,7 +19,7 @@ namespace Trolleybus
|
|||||||
return new DrawingTrolleybus(Convert.ToInt32(strs[0]),
|
return new DrawingTrolleybus(Convert.ToInt32(strs[0]),
|
||||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||||
}
|
}
|
||||||
if (strs.Length == 6)
|
if (strs.Length == 7)
|
||||||
{
|
{
|
||||||
return new DrawningSmallTrolleybus(Convert.ToInt32(strs[0]),
|
return new DrawningSmallTrolleybus(Convert.ToInt32(strs[0]),
|
||||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
||||||
@ -37,7 +37,7 @@ namespace Trolleybus
|
|||||||
{
|
{
|
||||||
return str;
|
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}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,11 @@ namespace Trolleybus
|
|||||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
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]);
|
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
_logger.LogInformation($"Добвлена карта {textBoxNewMapName.Text}");
|
_logger.LogInformation($"Добвлена карта {textBoxNewMapName.Text}");
|
||||||
|
@ -89,13 +89,9 @@ namespace Trolleybus
|
|||||||
public Bitmap ShowOnMap()
|
public Bitmap ShowOnMap()
|
||||||
{
|
{
|
||||||
Shaking();
|
Shaking();
|
||||||
for (int i = 0; i < _setTrolleybus.Count; i++)
|
foreach (var trolleybus in _setTrolleybus.GetTrolleybus())
|
||||||
{
|
{
|
||||||
var car = _setTrolleybus[i];
|
return _map.CreateMap(_pictureWidth, _pictureHeight, trolleybus);
|
||||||
if (car != null)
|
|
||||||
{
|
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new(_pictureWidth, _pictureHeight);
|
return new(_pictureWidth, _pictureHeight);
|
||||||
}
|
}
|
||||||
@ -116,9 +112,9 @@ namespace Trolleybus
|
|||||||
public string GetData(char separatorType, char separatorData)
|
public string GetData(char separatorType, char separatorData)
|
||||||
{
|
{
|
||||||
string data = $"{_map.GetType().Name}{separatorType}";
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
@ -127,6 +123,7 @@ namespace Trolleybus
|
|||||||
{
|
{
|
||||||
foreach (var rec in records)
|
foreach (var rec in records)
|
||||||
{
|
{
|
||||||
|
if (rec != "")
|
||||||
_setTrolleybus.Insert(DrawningObjectTrolleybus.Create(rec) as T);
|
_setTrolleybus.Insert(DrawningObjectTrolleybus.Create(rec) as T);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,24 +183,24 @@ namespace Trolleybus
|
|||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
private void DrawTrolleybus(Graphics g)
|
private void DrawTrolleybus(Graphics g)
|
||||||
{
|
{
|
||||||
int xForLocomotive = _pictureWidth - 2 * _placeSizeWidth + 60;
|
int xForTrolleybus = _pictureWidth - 2 * _placeSizeWidth + 60;
|
||||||
int yForLocomotive = 10;
|
int yForTrolleybus = 10;
|
||||||
int countInRow = 0;
|
int countInRow = 0;
|
||||||
for (int i = 0; i < _setTrolleybus.Count; i++)
|
for (int i = 0; i < _setTrolleybus.Count; i++)
|
||||||
{
|
{
|
||||||
if (countInRow >= _pictureWidth / (_placeSizeWidth + 30))
|
if (countInRow >= _pictureWidth / (_placeSizeWidth + 30))
|
||||||
{
|
{
|
||||||
xForLocomotive = _pictureWidth - 2 * _placeSizeWidth + 60;
|
xForTrolleybus = _pictureWidth - 2 * _placeSizeWidth + 60;
|
||||||
yForLocomotive += _placeSizeHeight;
|
yForTrolleybus += _placeSizeHeight;
|
||||||
countInRow = 0;
|
countInRow = 0;
|
||||||
}
|
}
|
||||||
if (_setTrolleybus[i] != null)
|
if (_setTrolleybus[i] != null)
|
||||||
{
|
{
|
||||||
T locomotive = _setTrolleybus[i];
|
T trolleybus = _setTrolleybus[i];
|
||||||
locomotive.SetObject(xForLocomotive, yForLocomotive, _pictureWidth, _pictureHeight);
|
trolleybus.SetObject(xForTrolleybus, yForTrolleybus, _pictureWidth, _pictureHeight);
|
||||||
locomotive.DrawningObject(g);
|
trolleybus.DrawningObject(g);
|
||||||
}
|
}
|
||||||
xForLocomotive -= _placeSizeWidth + 30;
|
xForTrolleybus -= _placeSizeWidth + 30;
|
||||||
countInRow++;
|
countInRow++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,15 +36,16 @@ namespace Trolleybus
|
|||||||
/// <param name="map">Карта</param>
|
/// <param name="map">Карта</param>
|
||||||
public void AddMap(string name, AbstractMap map)
|
public void AddMap(string name, AbstractMap map)
|
||||||
{
|
{
|
||||||
if (Keys.Contains(name))
|
if (!_mapStorages.ContainsKey(name))
|
||||||
return;
|
{
|
||||||
_mapStorages.Add(name, new(_pictureWidth, _pictureHeight, map));
|
_mapStorages.Add(name, new MapWithSetTrolleybusGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// Удаление карты
|
/// Удаление карты
|
||||||
/// <param name="name">Название карты</param>
|
/// <param name="name">Название карты</param>
|
||||||
public void DelMap(string name)
|
public void DelMap(string name)
|
||||||
{
|
{
|
||||||
_mapStorages.Remove(name);
|
if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name);
|
||||||
}
|
}
|
||||||
/// Доступ к депо
|
/// Доступ к депо
|
||||||
/// <param name="ind"></param>
|
/// <param name="ind"></param>
|
||||||
@ -53,8 +54,11 @@ namespace Trolleybus
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_mapStorages.TryGetValue(ind, out var mapWithSetTrolleybusGeneric);
|
if (_mapStorages.ContainsKey(ind))
|
||||||
return mapWithSetTrolleybusGeneric;
|
{
|
||||||
|
return _mapStorages[ind];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user