165 lines
5.7 KiB
C#
165 lines
5.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;
|
||
using static System.Windows.Forms.DataFormats;
|
||
|
||
namespace WarmlyLocomotive
|
||
{
|
||
public partial class FormMapWithSetLocomotives : Form
|
||
{
|
||
/// <summary>
|
||
/// Объект от класса карты с набором объектов
|
||
/// </summary>
|
||
private MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> _mapLocomotivesCollectionGeneric;
|
||
public FormMapWithSetLocomotives()
|
||
{
|
||
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 "Карта с большими барьерами":
|
||
map = new BigBarriersMap();
|
||
break;
|
||
case "Карта с круглыми барьерами":
|
||
map = new CirclesMap();
|
||
break;
|
||
}
|
||
if (map != null)
|
||
{
|
||
_mapLocomotivesCollectionGeneric = new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(
|
||
pictureBox.Width, pictureBox.Height, map);
|
||
}
|
||
else
|
||
{
|
||
_mapLocomotivesCollectionGeneric = null;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Добавление объекта
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||
{
|
||
if (_mapLocomotivesCollectionGeneric == null)
|
||
{
|
||
return;
|
||
}
|
||
FormLocomotive form = new();
|
||
if (form.ShowDialog() == DialogResult.OK)
|
||
{
|
||
DrawningObjectLocomotive car = new(form.SelectedLocomotive);
|
||
if (_mapLocomotivesCollectionGeneric + car != -1)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Удаление объекта
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonRemoveLocomotive_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 (_mapLocomotivesCollectionGeneric - pos != null)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Вывод набора
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||
{
|
||
if (_mapLocomotivesCollectionGeneric == null)
|
||
{
|
||
return;
|
||
}
|
||
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||
}
|
||
/// <summary>
|
||
/// Вывод карты
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||
{
|
||
if (_mapLocomotivesCollectionGeneric == null)
|
||
{
|
||
return;
|
||
}
|
||
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowOnMap();
|
||
}
|
||
/// <summary>
|
||
/// Перемещение
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonMove_Click(object sender, EventArgs e)
|
||
{
|
||
if (_mapLocomotivesCollectionGeneric == 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 = _mapLocomotivesCollectionGeneric.MoveObject(dir);
|
||
}
|
||
}
|
||
}
|