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();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-02 22:19:25 +04:00
|
|
|
|
private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
2022-10-02 16:55:05 +04:00
|
|
|
|
{
|
|
|
|
|
AbstractMap map = null;
|
|
|
|
|
switch (comboBoxSelectorMap.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Простая карта":
|
|
|
|
|
map = new SimpleMap();
|
|
|
|
|
break;
|
|
|
|
|
case "Лесная карта":
|
|
|
|
|
map = new ForestMap();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (map != null)
|
|
|
|
|
{
|
2022-10-02 22:19:25 +04:00
|
|
|
|
_mapArtilleriesCollectionGeneric = new MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap>(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height, map);
|
2022-10-02 16:55:05 +04:00
|
|
|
|
}
|
|
|
|
|
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);
|
2022-10-03 16:01:05 +04:00
|
|
|
|
if (_mapArtilleriesCollectionGeneric + car != -1)
|
2022-10-02 16:55:05 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonRemoveArtillery_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-10-02 22:19:25 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
2022-10-02 16:55:05 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
2022-10-03 16:01:05 +04:00
|
|
|
|
if (_mapArtilleriesCollectionGeneric - pos != null)
|
2022-10-02 16:55:05 +04:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|