151 lines
4.7 KiB
C#
151 lines
4.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 WinFormsApp1;
|
|||
|
|
|||
|
namespace WinFormsApp1
|
|||
|
{
|
|||
|
public partial class FormMapWithSetTraktor : Form
|
|||
|
{
|
|||
|
private MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> _mapTraktorCollectionGeneric;
|
|||
|
|
|||
|
//DrawingBus SelectedBus { get; private set; }
|
|||
|
|
|||
|
public FormMapWithSetTraktor()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
AbstractMap map = new SimpleMap();
|
|||
|
_mapTraktorCollectionGeneric = new MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>(
|
|||
|
pictureBox.Width, pictureBox.Height, map);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
AbstractMap map = null;
|
|||
|
switch (comboBoxSelectorMap.Text)
|
|||
|
{
|
|||
|
case "Простая карта":
|
|||
|
map = new SimpleMap();
|
|||
|
break;
|
|||
|
case "Поле":
|
|||
|
map = new FieldMap();
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if (map != null)
|
|||
|
{
|
|||
|
_mapTraktorCollectionGeneric = new MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
|||
|
}
|
|||
|
|
|||
|
else
|
|||
|
{
|
|||
|
_mapTraktorCollectionGeneric = null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonAddTraktor_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_mapTraktorCollectionGeneric == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
FormTractor form = new();
|
|||
|
if (form.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
if (form.SelectedTractor == null)
|
|||
|
{
|
|||
|
MessageBox.Show("Сначала создайте объект");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
DrawningObjectTractor bus = new(form.SelectedTractor);
|
|||
|
|
|||
|
if (_mapTraktorCollectionGeneric + bus != -1)
|
|||
|
{
|
|||
|
MessageBox.Show("Объект добавлен");
|
|||
|
pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
MessageBox.Show("Не удалось добавить объект");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonRemoveTraktor_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 (_mapTraktorCollectionGeneric - pos != null)
|
|||
|
{
|
|||
|
MessageBox.Show("Объект удален");
|
|||
|
pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
MessageBox.Show("Не удалось удалить объект");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_mapTraktorCollectionGeneric == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
pictureBox.Image = _mapTraktorCollectionGeneric.ShowSet();
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_mapTraktorCollectionGeneric == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
pictureBox.Image = _mapTraktorCollectionGeneric.ShowOnMap();
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_mapTraktorCollectionGeneric == 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 = _mapTraktorCollectionGeneric.MoveObject(dir);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|