2022-11-08 10:13:46 +04:00
|
|
|
|
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 Airbus
|
|
|
|
|
{
|
|
|
|
|
public partial class FormMapWithSetPlanes : Form
|
|
|
|
|
{
|
|
|
|
|
//объект от класса карты с набором объектов
|
|
|
|
|
private MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> _mapPlanesCollectionGeneric;
|
|
|
|
|
|
|
|
|
|
public FormMapWithSetPlanes()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//выбор карты
|
|
|
|
|
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AbstractMap map = null;
|
|
|
|
|
|
|
|
|
|
switch (comboBoxSelectorMap.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Простая карта":
|
|
|
|
|
map = new SimpleMap();
|
|
|
|
|
break;
|
2022-11-21 22:22:00 +04:00
|
|
|
|
case "Пустыня":
|
|
|
|
|
map = new DesertMap();
|
|
|
|
|
break;
|
|
|
|
|
case "Космос":
|
|
|
|
|
map = new SpaceMap();
|
|
|
|
|
break;
|
2022-11-08 10:13:46 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (map != null)
|
|
|
|
|
{
|
|
|
|
|
_mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>(
|
|
|
|
|
pictureBox.Width, pictureBox.Height, map);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_mapPlanesCollectionGeneric = null;
|
2022-11-21 22:22:00 +04:00
|
|
|
|
|
2022-11-08 10:13:46 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//добавление объекта
|
|
|
|
|
private void ButtonAddPlane_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_mapPlanesCollectionGeneric == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormAirbus form = new();
|
|
|
|
|
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
DrawningObjectPlane plane = new(form.SelectedPlane);
|
|
|
|
|
|
2022-11-21 22:22:00 +04:00
|
|
|
|
if (_mapPlanesCollectionGeneric + plane != -1)
|
2022-11-08 10:13:46 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-21 22:22:00 +04:00
|
|
|
|
//удаление объекта
|
2022-11-08 10:13:46 +04:00
|
|
|
|
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo,
|
|
|
|
|
MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
|
|
|
|
|
2022-11-21 22:22:00 +04:00
|
|
|
|
if (_mapPlanesCollectionGeneric - pos != null)
|
2022-11-08 10:13:46 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удалён");
|
|
|
|
|
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//вывод набора
|
2022-11-21 22:22:00 +04:00
|
|
|
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
2022-11-08 10:13:46 +04:00
|
|
|
|
{
|
|
|
|
|
if (_mapPlanesCollectionGeneric == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//вывод карты
|
2022-11-21 22:22:00 +04:00
|
|
|
|
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
2022-11-08 10:13:46 +04:00
|
|
|
|
{
|
|
|
|
|
if (_mapPlanesCollectionGeneric == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//перемещение
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_mapPlanesCollectionGeneric == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//получаем имя кнопки
|
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
|
Direction dir = Direction.None;
|
|
|
|
|
|
|
|
|
|
switch (name)
|
|
|
|
|
{
|
|
|
|
|
case "buttonUp":
|
|
|
|
|
dir = Direction.Up;
|
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
|
|
|
|
dir = Direction.Left;
|
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
|
|
|
|
dir = Direction.Down;
|
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
|
|
|
|
dir = Direction.Right;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pictureBox.Image = _mapPlanesCollectionGeneric.MoveObject(dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|