2 этап. Класс MapsCollection
This commit is contained in:
parent
6806a3c9ca
commit
ed2a685f66
@ -50,13 +50,9 @@ namespace WinFormsApp1
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setTraktors.Count; i++)
|
||||
foreach (var traktor in _setTraktors.GetTraktor())
|
||||
{
|
||||
var bus = _setTraktors[i];
|
||||
if (bus != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, bus);
|
||||
}
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, traktor);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
@ -113,31 +109,31 @@ namespace WinFormsApp1
|
||||
|
||||
private void DrawTraktors(Graphics g)
|
||||
{
|
||||
int widthEl = _pictureWidth / _placeSizeWidth;
|
||||
int heightEl = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
|
||||
int curWidth = 0;
|
||||
int curHeight = 0;
|
||||
|
||||
for (int i = _setTraktors.Count; i >= 0; i--)
|
||||
int currentWidth = _pictureWidth / _placeSizeWidth - 1;
|
||||
int currentHeight = _pictureHeight / _placeSizeHeight - 1;
|
||||
|
||||
foreach (var traktor in _setTraktors.GetTraktor())
|
||||
{
|
||||
_setTraktors[i]?.SetObject(
|
||||
_pictureWidth - _placeSizeWidth * curWidth - 60,
|
||||
curHeight * _placeSizeHeight + 30, _pictureWidth, _pictureHeight);
|
||||
_setTraktors[i]?.DrawningObject(g);
|
||||
traktor?.SetObject(
|
||||
currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
traktor?.DrawningObject(g);
|
||||
|
||||
if (curWidth < widthEl)
|
||||
curWidth++;
|
||||
if (currentWidth > 0)
|
||||
{
|
||||
currentWidth -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
curWidth = 1;
|
||||
curHeight++;
|
||||
if (currentHeight > 0)
|
||||
{
|
||||
currentHeight -= 1;
|
||||
currentWidth = _pictureWidth / _placeSizeWidth - 1;
|
||||
}
|
||||
else return;
|
||||
}
|
||||
if (curHeight > heightEl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
53
WinFormsApp1/MapsCollection.cs
Normal file
53
WinFormsApp1/MapsCollection.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
readonly Dictionary<string, MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>> _mapStorages;
|
||||
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (_mapStorages.ContainsKey(name)) return; //уникальное имя
|
||||
else
|
||||
{
|
||||
_mapStorages.Add(name, new MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
}
|
||||
|
||||
public void DelMap(string name)
|
||||
{
|
||||
if (_mapStorages.ContainsKey(name))
|
||||
{
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
_mapStorages.TryGetValue(ind, out var MapWithSetDoubleDeckerBusGeneric);
|
||||
return MapWithSetDoubleDeckerBusGeneric;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -69,7 +69,7 @@ namespace WinFormsApp1
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetBuses()
|
||||
public IEnumerable<T> GetTraktor()
|
||||
{
|
||||
foreach (var traktor in _places)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user