From 262f64521cd525939749e620be3617bf7027f870 Mon Sep 17 00:00:00 2001 From: Daniya_Youdakova Date: Sat, 24 Dec 2022 21:57:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B1-5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetAircraftCarriers.cs | 31 ++++++++++--------- .../AircraftCarrier/MapsCollection.cs | 16 ++++++++++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs b/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs index f0c5486..2ef0bc5 100644 --- a/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs +++ b/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs @@ -116,26 +116,27 @@ pictureBox.Height); } } private void ButtonAddAircraftCarrier_Click(object sender, EventArgs e) + { + var formAircraftCarrierConfig = new FormAircraftCarrierConfig(); + // TODO Call method AddEvent from formCarConfig + formAircraftCarrierConfig.AddEvent(AddAircraftCarrier); + formAircraftCarrierConfig.Show(); + } + private void AddAircraftCarrier(DrawningAircraftCarrier drawningAircraftCarrier) { if (listBoxMaps.SelectedIndex == -1) { return; } - FormAircraftCarrier form = new(); - if (form.ShowDialog() == DialogResult.OK) + DrawningObjectAircraftCarrier aircraftcarrier = new(drawningAircraftCarrier); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + aircraftcarrier != -1) { - DrawningObjectAircraftCarrier aircraftcarrier = new(form.SelectedAircraftCarrier); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? -string.Empty] + aircraftcarrier != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = - _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } private void buttonRemoveAircraftCarrier_Click(object sender, EventArgs e) @@ -164,6 +165,7 @@ string.Empty] - pos != null) { MessageBox.Show("Не удалось удалить объект"); } + } private void buttonShowStorage_Click(object sender, EventArgs e) { @@ -179,6 +181,7 @@ string.Empty] - pos != null) { return; } + pictureBox.Image = _mapAircraftCarriersCollectionGeneric.ShowOnMap(); } private void ButtonMove_Click(object sender, EventArgs e) diff --git a/AircraftCarrier/AircraftCarrier/MapsCollection.cs b/AircraftCarrier/AircraftCarrier/MapsCollection.cs index 3050853..c400950 100644 --- a/AircraftCarrier/AircraftCarrier/MapsCollection.cs +++ b/AircraftCarrier/AircraftCarrier/MapsCollection.cs @@ -72,5 +72,21 @@ namespace AircraftCarrier return mapWithSetAircraftCarriersGeneric; } } + public MapWithSetAircraftCarriersGeneric this[int index] + { + get + { + if ((index < 0) || (index >= Keys.Count)) + { + return null; + } + + else + { + string StringKey = Keys[index]; + return _mapStorages[StringKey]; + } + } + } } } \ No newline at end of file