2023-11-28 00:26:29 +04:00
|
|
|
|
using AirBomber.DrawningObjects;
|
|
|
|
|
using AirBomber.Generics;
|
|
|
|
|
using AirBomber.MovementStrategy;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace AirBomber
|
|
|
|
|
{
|
|
|
|
|
public partial class FormBomberCollection : Form
|
|
|
|
|
{
|
2023-11-28 01:00:19 +04:00
|
|
|
|
private readonly BomberGenericStorage _bomber;
|
2023-11-28 00:26:29 +04:00
|
|
|
|
|
|
|
|
|
public FormBomberCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-11-28 01:00:19 +04:00
|
|
|
|
_bomber = new BomberGenericStorage(PicBoxBomberCollection.Width, PicBoxBomberCollection.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ReloadObjects()
|
|
|
|
|
{
|
|
|
|
|
int index = listBoxStorages.SelectedIndex;
|
|
|
|
|
listBoxStorages.Items.Clear();
|
|
|
|
|
for (int i = 0; i < _bomber.Keys.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.Items.Add(_bomber.Keys[i]);
|
|
|
|
|
}
|
|
|
|
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
|
|
|
|
>= listBoxStorages.Items.Count))
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
|
|
|
|
index < listBoxStorages.Items.Count)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.SelectedIndex = index;
|
|
|
|
|
}
|
2023-11-28 00:26:29 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-11-28 01:00:19 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _bomber[listBoxStorages.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PicBoxBomberCollection.Image = obj.ShowBomber();
|
2023-11-28 00:26:29 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonAddBomber_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-11-28 01:00:19 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _bomber[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FormAirBomber form = new();
|
2023-11-28 00:26:29 +04:00
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2023-11-28 01:00:19 +04:00
|
|
|
|
if (obj + form.SelectedBomber != 1)
|
2023-11-28 00:26:29 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
2023-11-28 01:00:19 +04:00
|
|
|
|
PicBoxBomberCollection.Image = obj.ShowBomber();
|
2023-11-28 00:26:29 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonRemoveBomber_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-11-28 01:00:19 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _bomber[listBoxStorages.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
2023-11-28 00:26:29 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int pos = Convert.ToInt32(MessageBoxBomber.Text);
|
2023-11-28 01:00:19 +04:00
|
|
|
|
if (obj - pos != null)
|
2023-11-28 00:26:29 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
2023-11-28 01:00:19 +04:00
|
|
|
|
PicBoxBomberCollection.Image = obj.ShowBomber();
|
2023-11-28 00:26:29 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-28 01:00:19 +04:00
|
|
|
|
|
|
|
|
|
private void AddKit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(KitTextbox.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_bomber.AddSet(KitTextbox.Text);
|
|
|
|
|
ReloadObjects();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveKit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
_bomber.DelSet(listBoxStorages.SelectedItem.ToString()
|
|
|
|
|
?? string.Empty);
|
|
|
|
|
ReloadObjects();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-28 00:26:29 +04:00
|
|
|
|
}
|
|
|
|
|
}
|