Решена проблема с загрузкой

This commit is contained in:
Arklightning 2022-12-24 21:22:08 +04:00
parent 28682f5779
commit b601a626a3
8 changed files with 49 additions and 51 deletions

View File

@ -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;
}

View File

@ -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
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина картинки</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)
{
_startPosX = x;
_startPosY = y;
// _startX = startX;
// _startY = startY;
_pictureWidth = width;
_pictureHeight = height;
}
@ -100,7 +97,6 @@ namespace Trolleybus
break;
//влево
case Direction.Left:
// if (_startPosX > _startX)
if (_startPosX - Trolleybus.Step > 0)
{
_startPosX -= Trolleybus.Step;
@ -108,7 +104,6 @@ namespace Trolleybus
break;
//вверх
case Direction.Up:
// if (_startPosY > _startY)
if (_startPosY - Trolleybus.Step > 0)
{
_startPosY -= Trolleybus.Step;

View File

@ -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());
}
}

View File

@ -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}";
}
}
}

View File

@ -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}");

View File

@ -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,6 +123,7 @@ namespace Trolleybus
{
foreach (var rec in records)
{
if (rec != "")
_setTrolleybus.Insert(DrawningObjectTrolleybus.Create(rec) as T);
}
}
@ -180,24 +177,24 @@ namespace Trolleybus
/// <param name="g"></param>
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++;
}

View File

@ -36,15 +36,16 @@ namespace Trolleybus
/// <param name="map">Карта</param>
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<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
}
/// Удаление карты
/// <param name="name">Название карты</param>
public void DelMap(string name)
{
_mapStorages.Remove(name);
if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name);
}
/// Доступ к депо
/// <param name="ind"></param>
@ -53,8 +54,11 @@ namespace Trolleybus
{
get
{
_mapStorages.TryGetValue(ind, out var mapWithSetTrolleybusGeneric);
return mapWithSetTrolleybusGeneric;
if (_mapStorages.ContainsKey(ind))
{
return _mapStorages[ind];
}
return null;
}
}