159 lines
4.7 KiB
C#
159 lines
4.7 KiB
C#
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;
|
||
case "Пустыня":
|
||
map = new DesertMap();
|
||
break;
|
||
case "Космос":
|
||
map = new SpaceMap();
|
||
break;
|
||
}
|
||
|
||
if (map != null)
|
||
{
|
||
_mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>(
|
||
pictureBox.Width, pictureBox.Height, map);
|
||
}
|
||
else
|
||
{
|
||
_mapPlanesCollectionGeneric = null;
|
||
|
||
}
|
||
}
|
||
|
||
//добавление объекта
|
||
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);
|
||
|
||
if (_mapPlanesCollectionGeneric + plane != -1)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
}
|
||
}
|
||
//удаление объекта
|
||
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);
|
||
|
||
if (_mapPlanesCollectionGeneric - pos != null)
|
||
{
|
||
MessageBox.Show("Объект удалён");
|
||
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
|
||
//вывод набора
|
||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||
{
|
||
if (_mapPlanesCollectionGeneric == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
|
||
}
|
||
|
||
//вывод карты
|
||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||
{
|
||
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);
|
||
}
|
||
|
||
}
|
||
} |