2022-12-23 10:26:53 +04:00

166 lines
5.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
using static System.Windows.Forms.DataFormats;
namespace AntiAircraftGun
{
public partial class FormMapWithSetAntiAircraftGuns : Form
{
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap> _mapAntiAircraftGunsCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetAntiAircraftGuns()
{
InitializeComponent();
}
/// <summary>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Простая карта 2":
map = new SimpleMap2();
break;
}
if (map != null)
{
_mapAntiAircraftGunsCollectionGeneric = new MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapAntiAircraftGunsCollectionGeneric = null;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
///
private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e)
{
if (_mapAntiAircraftGunsCollectionGeneric == null)
{
return;
}
FormAntiAircraftGun form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectAntiAircraftGun antiAircraftGun = new(form.SelectedAntiAircraftGun);
if (_mapAntiAircraftGunsCollectionGeneric + antiAircraftGun >= 0)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveAntiAircraftGun_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 (_mapAntiAircraftGunsCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapAntiAircraftGunsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapAntiAircraftGunsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapAntiAircraftGunsCollectionGeneric == null)
{
return;
}
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.MoveObject(dir);
}
}
}