2 этап. Класс MapsCollection
This commit is contained in:
parent
6806a3c9ca
commit
ed2a685f66
@ -50,13 +50,9 @@ namespace WinFormsApp1
|
|||||||
public Bitmap ShowOnMap()
|
public Bitmap ShowOnMap()
|
||||||
{
|
{
|
||||||
Shaking();
|
Shaking();
|
||||||
for (int i = 0; i < _setTraktors.Count; i++)
|
foreach (var traktor in _setTraktors.GetTraktor())
|
||||||
{
|
{
|
||||||
var bus = _setTraktors[i];
|
return _map.CreateMap(_pictureWidth, _pictureHeight, traktor);
|
||||||
if (bus != null)
|
|
||||||
{
|
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, bus);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new(_pictureWidth, _pictureHeight);
|
return new(_pictureWidth, _pictureHeight);
|
||||||
}
|
}
|
||||||
@ -113,31 +109,31 @@ namespace WinFormsApp1
|
|||||||
|
|
||||||
private void DrawTraktors(Graphics g)
|
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(
|
traktor?.SetObject(
|
||||||
_pictureWidth - _placeSizeWidth * curWidth - 60,
|
currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||||
curHeight * _placeSizeHeight + 30, _pictureWidth, _pictureHeight);
|
traktor?.DrawningObject(g);
|
||||||
_setTraktors[i]?.DrawningObject(g);
|
|
||||||
|
|
||||||
if (curWidth < widthEl)
|
if (currentWidth > 0)
|
||||||
curWidth++;
|
{
|
||||||
|
currentWidth -= 1;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
curWidth = 1;
|
if (currentHeight > 0)
|
||||||
curHeight++;
|
{
|
||||||
|
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)
|
foreach (var traktor in _places)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user