166 lines
5.2 KiB
C#
166 lines
5.2 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 Catamaran
|
||
{
|
||
public partial class FormMapWithSetBoats : Form
|
||
{
|
||
private MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap> _mapBoatsCollectionGeneric;
|
||
|
||
|
||
public FormMapWithSetBoats()
|
||
{
|
||
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 "SimpleMap":
|
||
map = new SimpleMap();
|
||
break;
|
||
case "SecondMap":
|
||
map = new SecondMap();
|
||
break;
|
||
}
|
||
if (map != null)
|
||
{
|
||
_mapBoatsCollectionGeneric = new MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
||
}
|
||
else
|
||
{
|
||
_mapBoatsCollectionGeneric = null;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Добавление объекта
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
/// <summary>
|
||
/// Удаление объекта
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void buttonRemoveBoat_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 (_mapBoatsCollectionGeneric - pos != null)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Вывод набора
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void buttonShowStorage_Click(object sender, EventArgs e)
|
||
{
|
||
if (_mapBoatsCollectionGeneric == null)
|
||
{
|
||
return;
|
||
}
|
||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
|
||
}
|
||
/// <summary>
|
||
/// Вывод карты
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void buttonShowOnMap_Click(object sender, EventArgs e)
|
||
{
|
||
if (_mapBoatsCollectionGeneric == null)
|
||
{
|
||
return;
|
||
}
|
||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowOnMap();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Перемещение
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void buttonMove_Click(object sender, EventArgs e)
|
||
{
|
||
if (_mapBoatsCollectionGeneric == 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 = _mapBoatsCollectionGeneric.MoveObject(dir);
|
||
}
|
||
|
||
private void buttonAddBoat_Click_1(object sender, EventArgs e)
|
||
{
|
||
if (_mapBoatsCollectionGeneric == null)
|
||
{
|
||
return;
|
||
}
|
||
FormBoat form = new FormBoat();
|
||
if (form.ShowDialog() == DialogResult.OK)
|
||
{
|
||
DrawingObjectBoat boat = new DrawingObjectBoat(form.SelectedBoat);
|
||
if (_mapBoatsCollectionGeneric + boat != null)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|