From ed2a685f667854b120eec32fd9cc6f06786a3c62 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 29 Nov 2022 01:53:02 +0400 Subject: [PATCH] =?UTF-8?q?2=20=D1=8D=D1=82=D0=B0=D0=BF.=20=D0=9A=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81=20MapsCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormsApp1/MapWithSetTraktorGeneric.cs | 44 +++++++++----------- WinFormsApp1/MapsCollection.cs | 53 ++++++++++++++++++++++++ WinFormsApp1/SetTraktorGeneric.cs | 2 +- 3 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 WinFormsApp1/MapsCollection.cs diff --git a/WinFormsApp1/MapWithSetTraktorGeneric.cs b/WinFormsApp1/MapWithSetTraktorGeneric.cs index 328bfaf..750ed9c 100644 --- a/WinFormsApp1/MapWithSetTraktorGeneric.cs +++ b/WinFormsApp1/MapWithSetTraktorGeneric.cs @@ -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; - } - } } } diff --git a/WinFormsApp1/MapsCollection.cs b/WinFormsApp1/MapsCollection.cs new file mode 100644 index 0000000..498b24f --- /dev/null +++ b/WinFormsApp1/MapsCollection.cs @@ -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> _mapStorages; + + public List Keys => _mapStorages.Keys.ToList(); + + private readonly int _pictureWidth; + + private readonly int _pictureHeight; + + public MapsCollection(int pictureWidth, int pictureHeight) + { + _mapStorages = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + + public void AddMap(string name, AbstractMap map) + { + if (_mapStorages.ContainsKey(name)) return; //уникальное имя + else + { + _mapStorages.Add(name, new MapWithSetTraktorGeneric(_pictureWidth, _pictureHeight, map)); + } + } + + public void DelMap(string name) + { + if (_mapStorages.ContainsKey(name)) + { + _mapStorages.Remove(name); + } + } + + public MapWithSetTraktorGeneric this[string ind] + { + get + { + _mapStorages.TryGetValue(ind, out var MapWithSetDoubleDeckerBusGeneric); + return MapWithSetDoubleDeckerBusGeneric; + } + + } + } +} diff --git a/WinFormsApp1/SetTraktorGeneric.cs b/WinFormsApp1/SetTraktorGeneric.cs index 657063a..b4c2e7e 100644 --- a/WinFormsApp1/SetTraktorGeneric.cs +++ b/WinFormsApp1/SetTraktorGeneric.cs @@ -69,7 +69,7 @@ namespace WinFormsApp1 } } - public IEnumerable GetBuses() + public IEnumerable GetTraktor() { foreach (var traktor in _places) {