From 4498a36c12db02798c8215901f8d5f1e4d487102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D0=B8=D1=80=20=D0=9D=D1=83=D0=B3=D0=B0?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Tue, 1 Nov 2022 23:32:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=203.1=20-=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetDoubleDeckerBus.Designer.cs | 16 +++---- Bus/Bus/FormMapWithSetDoubleDeckerBus.cs | 7 +-- Bus/Bus/MapsCollection.cs | 14 +++++- Bus/Bus/SetDoubleDeckerBusGeneric.cs | 43 ++++++++++--------- 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs b/Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs index 3cc52e0..a4dad44 100644 --- a/Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs +++ b/Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs @@ -44,7 +44,7 @@ this.buttonDeleteMap = new System.Windows.Forms.Button(); this.listBoxMaps = new System.Windows.Forms.ListBox(); this.buttonAddMap = new System.Windows.Forms.Button(); - this.maskedTextBox1 = new System.Windows.Forms.MaskedTextBox(); + this.textBoxNewMapName = new System.Windows.Forms.TextBox(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.groupBox2.SuspendLayout(); @@ -187,10 +187,10 @@ // // groupBox2 // + this.groupBox2.Controls.Add(this.textBoxNewMapName); this.groupBox2.Controls.Add(this.buttonDeleteMap); this.groupBox2.Controls.Add(this.listBoxMaps); this.groupBox2.Controls.Add(this.buttonAddMap); - this.groupBox2.Controls.Add(this.maskedTextBox1); this.groupBox2.Controls.Add(this.comboBoxSelectorMap); this.groupBox2.Location = new System.Drawing.Point(605, 26); this.groupBox2.Name = "groupBox2"; @@ -229,12 +229,12 @@ this.buttonAddMap.UseVisualStyleBackColor = true; this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click); // - // maskedTextBox1 + // textBoxNewMapName // - this.maskedTextBox1.Location = new System.Drawing.Point(8, 26); - this.maskedTextBox1.Name = "maskedTextBox1"; - this.maskedTextBox1.Size = new System.Drawing.Size(125, 27); - this.maskedTextBox1.TabIndex = 1; + this.textBoxNewMapName.Location = new System.Drawing.Point(6, 26); + this.textBoxNewMapName.Name = "textBoxNewMapName"; + this.textBoxNewMapName.Size = new System.Drawing.Size(125, 27); + this.textBoxNewMapName.TabIndex = 5; // // FormMapWithSetDoubleDeckerBus // @@ -273,6 +273,6 @@ private Button buttonDeleteMap; private ListBox listBoxMaps; private Button buttonAddMap; - private MaskedTextBox maskedTextBox1; + private TextBox textBoxNewMapName; } } \ No newline at end of file diff --git a/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs b/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs index 841f593..0150735 100644 --- a/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs +++ b/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs @@ -16,7 +16,8 @@ namespace Bus private readonly Dictionary _mapsDict = new() { - {"Простая карта", new SimpleMap() } + {"Простая карта", new SimpleMap() }, + {"Водная карта", new MyMap() }, }; private readonly MapsCollection _mapsCollection; @@ -135,7 +136,7 @@ namespace Bus { return; } - pictureBox.Image = _mapBusCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } private void ButtonShowOnMap_Click(object sender, EventArgs e) @@ -144,7 +145,7 @@ namespace Bus { return; } - pictureBox.Image = _mapBusCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } private void ButtonMove_Click(object sender, EventArgs e) diff --git a/Bus/Bus/MapsCollection.cs b/Bus/Bus/MapsCollection.cs index d98fde3..a28b8e5 100644 --- a/Bus/Bus/MapsCollection.cs +++ b/Bus/Bus/MapsCollection.cs @@ -25,12 +25,21 @@ namespace Bus public void AddMap(string name, AbstractMap map) { - // TODO Прописать логику для добавления + if (_mapStorages.ContainsKey(name)) return; //уникальное имя + else + { + _mapStorages.Add(name, new MapWithSetDoubleDeckerBusGeneric(_pictureWidth, _pictureHeight, map)); + } } public void DelMap(string name) { // TODO Прописать логику для удаления + if (_mapStorages.ContainsKey(name)) + { + _mapStorages.Remove(name); + } + } public MapWithSetDoubleDeckerBusGeneric this[string ind] @@ -38,7 +47,8 @@ namespace Bus get { // TODO Продумать логику получения объекта - return null; + _mapStorages.TryGetValue(ind, out var MapWithSetDoubleDeckerBusGeneric); + return MapWithSetDoubleDeckerBusGeneric; } } diff --git a/Bus/Bus/SetDoubleDeckerBusGeneric.cs b/Bus/Bus/SetDoubleDeckerBusGeneric.cs index e3f7fa3..3551703 100644 --- a/Bus/Bus/SetDoubleDeckerBusGeneric.cs +++ b/Bus/Bus/SetDoubleDeckerBusGeneric.cs @@ -26,45 +26,48 @@ namespace Bus return Insert(bus, 0); } + private bool isCorrectPosition(int position) + { + return 0 <= position && position < _maxCount; + } + public int Insert(T bus, int position) { - if (position < 0 || position >= _maxCount || BusPlaces == _maxCount) + if (!isCorrectPosition(position)) { return -1; } - BusPlaces++; - while (_places[position] != null) - { - for (int i = _places.Count - 1; i > 0; --i) - { - if (_places[i] == null && _places[i - 1] != null) - { - _places[i] = _places[i - 1]; - _places[i - 1] = null; - } - } - } - _places[position] = bus; + _places.Insert(position, bus); return position; } public T Remove(int position) { - if (position < 0 || position >= _maxCount) return null; - T savedBus = _places[position]; - _places[position] = null; - return savedBus; + if (position < 0 || position >= _maxCount) + { + return null; + } + var result = _places[position]; + _places.RemoveAt(position); + return result; } public T this[int position] { get { - return _places[position]; + if (position >= 0 && position < _maxCount && position < Count) + { + return _places[position]; + } + else + { + return null; + } } set { - // todo + Insert(value, position); } }