Удаление класса Delegate, создание вместо него Action. Исправление ошибок. Сдана Lab5

This commit is contained in:
malimova 2023-11-13 12:40:58 +04:00
parent ede63a0ae5
commit 32ff4df6d8
4 changed files with 26 additions and 51 deletions

View File

@ -1,10 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
public delegate void AirPlaneDelegate(DrawningAirPlane plane);
}

View File

@ -63,6 +63,28 @@ namespace AirBomber
formPlaneConfig.AddEvent(AddPlane); formPlaneConfig.AddEvent(AddPlane);
formPlaneConfig.Show(); formPlaneConfig.Show();
} }
private void AddPlane(DrawningAirPlane plane)
{
plane._pictureWidth = pictureBoxCollection.Width;
plane._pictureHeight = pictureBoxCollection.Height;
if (listBoxStorages.SelectedIndex == -1) return;
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
if (obj + plane > -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary> /// <summary>
/// Удаление объекта из набора /// Удаление объекта из набора
/// </summary> /// </summary>
@ -140,27 +162,6 @@ namespace AirBomber
ReloadObjects(); ReloadObjects();
} }
} }
private void AddPlane(DrawningAirPlane plane)
{
plane._pictureWidth = pictureBoxCollection.Width;
plane._pictureHeight = pictureBoxCollection.Height;
if (listBoxStorages.SelectedIndex == -1) return;
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
if (obj + plane > -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
} }
} }

View File

@ -126,8 +126,6 @@
panelPurple.Name = "panelPurple"; panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(54, 54); panelPurple.Size = new Size(54, 54);
panelPurple.TabIndex = 1; panelPurple.TabIndex = 1;
panelPurple.DragDrop += PanelObject_DragDrop;
panelPurple.DragEnter += PanelObject_DragEnter;
panelPurple.MouseDown += panelColor_MouseDown; panelPurple.MouseDown += panelColor_MouseDown;
// //
// panelBlack // panelBlack
@ -137,8 +135,6 @@
panelBlack.Name = "panelBlack"; panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(54, 54); panelBlack.Size = new Size(54, 54);
panelBlack.TabIndex = 1; panelBlack.TabIndex = 1;
panelBlack.DragDrop += PanelObject_DragDrop;
panelBlack.DragEnter += PanelObject_DragEnter;
panelBlack.MouseDown += panelColor_MouseDown; panelBlack.MouseDown += panelColor_MouseDown;
// //
// panelGray // panelGray
@ -148,8 +144,6 @@
panelGray.Name = "panelGray"; panelGray.Name = "panelGray";
panelGray.Size = new Size(54, 54); panelGray.Size = new Size(54, 54);
panelGray.TabIndex = 1; panelGray.TabIndex = 1;
panelGray.DragDrop += PanelObject_DragDrop;
panelGray.DragEnter += PanelObject_DragEnter;
panelGray.MouseDown += panelColor_MouseDown; panelGray.MouseDown += panelColor_MouseDown;
// //
// panelWhite // panelWhite
@ -159,8 +153,6 @@
panelWhite.Name = "panelWhite"; panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(54, 54); panelWhite.Size = new Size(54, 54);
panelWhite.TabIndex = 1; panelWhite.TabIndex = 1;
panelWhite.DragDrop += PanelObject_DragDrop;
panelWhite.DragEnter += PanelObject_DragEnter;
panelWhite.MouseDown += panelColor_MouseDown; panelWhite.MouseDown += panelColor_MouseDown;
// //
// panelYellow // panelYellow
@ -170,8 +162,6 @@
panelYellow.Name = "panelYellow"; panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(54, 54); panelYellow.Size = new Size(54, 54);
panelYellow.TabIndex = 1; panelYellow.TabIndex = 1;
panelYellow.DragDrop += PanelObject_DragDrop;
panelYellow.DragEnter += PanelObject_DragEnter;
panelYellow.MouseDown += panelColor_MouseDown; panelYellow.MouseDown += panelColor_MouseDown;
// //
// panelBlue // panelBlue
@ -181,8 +171,6 @@
panelBlue.Name = "panelBlue"; panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(54, 54); panelBlue.Size = new Size(54, 54);
panelBlue.TabIndex = 1; panelBlue.TabIndex = 1;
panelBlue.DragDrop += PanelObject_DragDrop;
panelBlue.DragEnter += PanelObject_DragEnter;
panelBlue.MouseDown += panelColor_MouseDown; panelBlue.MouseDown += panelColor_MouseDown;
// //
// panelGreen // panelGreen
@ -192,8 +180,6 @@
panelGreen.Name = "panelGreen"; panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(54, 54); panelGreen.Size = new Size(54, 54);
panelGreen.TabIndex = 1; panelGreen.TabIndex = 1;
panelGreen.DragDrop += PanelObject_DragDrop;
panelGreen.DragEnter += PanelObject_DragEnter;
panelGreen.MouseDown += panelColor_MouseDown; panelGreen.MouseDown += panelColor_MouseDown;
// //
// panelRed // panelRed
@ -203,8 +189,6 @@
panelRed.Name = "panelRed"; panelRed.Name = "panelRed";
panelRed.Size = new Size(54, 54); panelRed.Size = new Size(54, 54);
panelRed.TabIndex = 0; panelRed.TabIndex = 0;
panelRed.DragDrop += PanelObject_DragDrop;
panelRed.DragEnter += PanelObject_DragEnter;
panelRed.MouseDown += panelColor_MouseDown; panelRed.MouseDown += panelColor_MouseDown;
// //
// checkBoxFuelTanks // checkBoxFuelTanks

View File

@ -19,8 +19,8 @@ namespace AirBomber
/// <summary> /// <summary>
/// Делегат для передачи объекта-автомобиля /// Делегат для передачи объекта-автомобиля
/// </summary> /// </summary>
/// <param name="car"></param> /// <param name="plane"></param>
private event AirPlaneDelegate? EventAddPlane; private event Action<DrawningAirPlane>? EventAddPlane;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -53,7 +53,7 @@ namespace AirBomber
/// Добавление события /// Добавление события
/// </summary> /// </summary>
/// <param name="ev">Привязанный метод</param> /// <param name="ev">Привязанный метод</param>
public void AddEvent(AirPlaneDelegate ev) public void AddEvent(Action<DrawningAirPlane> ev)
{ {
if (EventAddPlane == null) if (EventAddPlane == null)
{ {