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 Sailboat { public partial class FormMapWithSetBoats : Form { private MapWithSetBoatsGeneric _mapBoatsCollectionGeneric; public FormMapWithSetBoats() { InitializeComponent(); AbstractMap map = new SimpleMap(); _mapBoatsCollectionGeneric = new MapWithSetBoatsGeneric( pictureBox.Width, pictureBox.Height, map); } private void comboBoxMapSelector_SelectedIndexChanged(object sender, EventArgs e) { AbstractMap map = null; switch (comboBoxMapSelector.Text) { case "Простая карта": map = new SimpleMap(); break; case "Водная карта": map = new WaterMap(); break; } if (map != null) { _mapBoatsCollectionGeneric = new MapWithSetBoatsGeneric( pictureBox.Width, pictureBox.Height, map); } else { _mapBoatsCollectionGeneric = null; } } private void btn_add_boat_Click(object sender, EventArgs e) { if (_mapBoatsCollectionGeneric == null) { return; } BoatForm form = new(); if (form.ShowDialog() == DialogResult.OK) { if (form.SelectedBoat == null) { MessageBox.Show("Вы не создали объект"); return; } DrawingObjectBoat bus = new(form.SelectedBoat); if (_mapBoatsCollectionGeneric + bus != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet(); } else { MessageBox.Show("Не удалось добавить объект"); } } } private void btn_remove_boat_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 btn_show_storage_Click(object sender, EventArgs e) { if (_mapBoatsCollectionGeneric == null) { return; } pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet(); } private void btn_show_map_Click(object sender, EventArgs e) { if (_mapBoatsCollectionGeneric == null) { return; } pictureBox.Image = _mapBoatsCollectionGeneric.ShowOnMap(); } private void btn_move_Click(object sender, EventArgs e) { if (_mapBoatsCollectionGeneric == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; Direction dir = Direction.None; switch (name) { case "btn_up": dir = Direction.Up; break; case "btn_down": dir = Direction.Down; break; case "btn_left": dir = Direction.Left; break; case "btn_right": dir = Direction.Right; break; } pictureBox.Image = _mapBoatsCollectionGeneric.MoveObject(dir); } } }