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 _mapBoatsCollectionGeneric; public FormMapWithSetBoats() { InitializeComponent(); } /// /// Выбор карты /// /// /// 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(pictureBox.Width, pictureBox.Height, map); } else { _mapBoatsCollectionGeneric = null; } } /// /// Добавление объекта /// /// /// /// /// Удаление объекта /// /// /// 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("Не удалось удалить объект"); } } /// /// Вывод набора /// /// /// private void buttonShowStorage_Click(object sender, EventArgs e) { if (_mapBoatsCollectionGeneric == null) { return; } pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet(); } /// /// Вывод карты /// /// /// private void buttonShowOnMap_Click(object sender, EventArgs e) { if (_mapBoatsCollectionGeneric == null) { return; } pictureBox.Image = _mapBoatsCollectionGeneric.ShowOnMap(); } /// /// Перемещение /// /// /// 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("Не удалось добавить объект"); } } } } }