2022-10-02 16:55:05 +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;
|
|
|
|
|
using static System.Windows.Forms.DataFormats;
|
|
|
|
|
|
|
|
|
|
namespace Artilleries
|
|
|
|
|
{
|
|
|
|
|
public partial class FormMapWithSetArtilleries : Form
|
|
|
|
|
{
|
2022-10-02 22:17:57 +04:00
|
|
|
|
private MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap> _mapArtilleriesCollectionGeneric;
|
2022-10-02 16:55:05 +04:00
|
|
|
|
|
|
|
|
|
public FormMapWithSetArtilleries()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void comboBoxSelectorMap_SelectedIndexChanged(object sender,
|
|
|
|
|
EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AbstractMap map = null;
|
|
|
|
|
switch (comboBoxSelectorMap.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Простая карта":
|
|
|
|
|
map = new SimpleMap();
|
|
|
|
|
break;
|
|
|
|
|
case "Лесная карта":
|
|
|
|
|
map = new ForestMap();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (map != null)
|
|
|
|
|
{
|
|
|
|
|
_mapArtilleriesCollectionGeneric = new
|
|
|
|
|
MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap>(
|
|
|
|
|
pictureBoxArtilleries.Width, pictureBoxArtilleries.Height, map);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_mapArtilleriesCollectionGeneric = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonAddArtillery_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_mapArtilleriesCollectionGeneric == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FormArtillery form = new();
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
DrawingObjectArtillery car = new(form.SelectedArtillery);
|
|
|
|
|
if (_mapArtilleriesCollectionGeneric + car)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonRemoveArtillery_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 (_mapArtilleriesCollectionGeneric - pos)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
|
|
|
|
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonShowStorage_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_mapArtilleriesCollectionGeneric == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonShowOnMap_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_mapArtilleriesCollectionGeneric == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowOnMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_mapArtilleriesCollectionGeneric == 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;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.MoveObject(dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|