From a36cba08959a321be2609c86a38ad230e8051300 Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Fri, 25 Nov 2022 15:34:30 +0400 Subject: [PATCH] done --- ContainerShip/ContainerShip/DrawingShip.cs | 2 - ContainerShip/ContainerShip/EntityShip.cs | 2 +- .../FormMapWithSetShip.Designer.cs | 3 +- .../ContainerShip/FormMapWithSetShip.cs | 49 +++++-------------- ContainerShip/ContainerShip/FormShipConfig.cs | 11 ++--- ContainerShip/ContainerShip/ShipDelegate.cs | 10 ---- 6 files changed, 17 insertions(+), 60 deletions(-) delete mode 100644 ContainerShip/ContainerShip/ShipDelegate.cs diff --git a/ContainerShip/ContainerShip/DrawingShip.cs b/ContainerShip/ContainerShip/DrawingShip.cs index 6f1f74a..3ee5aea 100644 --- a/ContainerShip/ContainerShip/DrawingShip.cs +++ b/ContainerShip/ContainerShip/DrawingShip.cs @@ -106,8 +106,6 @@ namespace ContainerShip g.FillPolygon(brRed, shipBorder); //Заливка верхней палубы g.FillRectangle(brMain, _startPosX + 21, _startPosY + 1, 59, 29); - - } public void ChangeBorders(int width, int height) { diff --git a/ContainerShip/ContainerShip/EntityShip.cs b/ContainerShip/ContainerShip/EntityShip.cs index ce39abb..38a79ef 100644 --- a/ContainerShip/ContainerShip/EntityShip.cs +++ b/ContainerShip/ContainerShip/EntityShip.cs @@ -17,7 +17,7 @@ namespace ContainerShip { Random random = new Random(); Speed = speed <= 0 ? random.Next(50, 150) : speed; - Weight = weight <= 0 ? random.Next(50, 150) : weight; + Weight = weight <= 0 ? random.Next(1000, 2000) : weight; BodyColor = bodyColor; } } diff --git a/ContainerShip/ContainerShip/FormMapWithSetShip.Designer.cs b/ContainerShip/ContainerShip/FormMapWithSetShip.Designer.cs index 0d0124d..315a49c 100644 --- a/ContainerShip/ContainerShip/FormMapWithSetShip.Designer.cs +++ b/ContainerShip/ContainerShip/FormMapWithSetShip.Designer.cs @@ -132,8 +132,7 @@ this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 51); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(176, 23); - this.comboBoxSelectorMap.TabIndex = 18; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + this.comboBoxSelectorMap.TabIndex = 18; // // maskedTextBoxPosition // diff --git a/ContainerShip/ContainerShip/FormMapWithSetShip.cs b/ContainerShip/ContainerShip/FormMapWithSetShip.cs index 25e65f9..a5af32e 100644 --- a/ContainerShip/ContainerShip/FormMapWithSetShip.cs +++ b/ContainerShip/ContainerShip/FormMapWithSetShip.cs @@ -11,11 +11,7 @@ using System.Windows.Forms; namespace ContainerShip { public partial class FormMapWithSetShip : Form - { - - private MapWithSetShipGeneric _mapShipCollectionGeneric; - - + { private readonly Dictionary _mapsDict = new() { { "Простая карта", new SimpleMap()}, @@ -75,32 +71,6 @@ namespace ContainerShip ReloadMaps(); } - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - AbstractMap map = null; - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - map = new SimpleMap(); - break; - case "Острова": - map = new IslandsMap(); - break; - case "Скалы": - map = new RocksMap(); - break; - } - if (map != null) - { - _mapShipCollectionGeneric = new - MapWithSetShipGeneric( - pictureBox.Width, pictureBox.Height, map); - } - else - { - _mapShipCollectionGeneric = null; - } - } private void ButtonAddShip_Click(object sender, EventArgs e) { var formShipConfig = new FormShipConfig(); @@ -128,20 +98,23 @@ namespace ContainerShip private void ButtonRemoveShip_Click(object sender, EventArgs e) { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapShipCollectionGeneric - pos != null) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -151,12 +124,12 @@ namespace ContainerShip private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapShipCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); - + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } private void ButtonShowOnMap_Click(object sender, EventArgs e) diff --git a/ContainerShip/ContainerShip/FormShipConfig.cs b/ContainerShip/ContainerShip/FormShipConfig.cs index d32c051..479232b 100644 --- a/ContainerShip/ContainerShip/FormShipConfig.cs +++ b/ContainerShip/ContainerShip/FormShipConfig.cs @@ -14,7 +14,7 @@ namespace ContainerShip { DrawingShip _ship = null; - private event ShipDelegate EventAddShip; + private event Action EventAddShip; public FormShipConfig() { @@ -29,10 +29,7 @@ namespace ContainerShip panelBlue.MouseDown += PanelColor_MouseDown; - buttonCancel.Click += (object sender, EventArgs e) => - { - Close(); - }; + buttonCancel.Click += (object sender, EventArgs e) => Close(); } private void DrawShip() @@ -45,11 +42,11 @@ namespace ContainerShip pictureBoxObject.Image = bmp; } - public void AddEvent(ShipDelegate ev) + public void AddEvent(Action ev) { if (EventAddShip == null) { - EventAddShip = new ShipDelegate(ev); + EventAddShip = new Action(ev); } else { diff --git a/ContainerShip/ContainerShip/ShipDelegate.cs b/ContainerShip/ContainerShip/ShipDelegate.cs deleted file mode 100644 index 2c322fd..0000000 --- a/ContainerShip/ContainerShip/ShipDelegate.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ContainerShip -{ - public delegate void ShipDelegate(DrawingShip ship); -}