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 FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
///
/// Обработка нажатия кнопки "Создать"
///
///
///
private void btn_create_Click(object sender, EventArgs e)
{
Random rnd = new();
var boat = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetData(boat);
}
///
/// Обработка нажатия кнопки "Создать парусник"
///
///
///
private void btn_create_sailboat_Click(object sender, EventArgs e)
{
Random rnd = new();
var boat = new DrawingSailboat(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(boat);
}
///
/// Обработка нажатия стрелок
///
///
///
private void btn_move_Click(object sender, EventArgs e)
{
//получаем имя кнопки
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;
}
pictureBoxBoat.Image = _abstractMap?.MoveObject(dir);
}
///
/// Метод прорисовки машины
///
private void SetData(DrawingBoat boat)
{
Random rnd = new();
toolStripLabel_color.Text = $"Скорость: {boat?.Boat.Speed}";
toolStripLabel_weight.Text = $"Вес: {boat?.Boat.Weight}";
toolStripLabel_color.Text = $"Цвет: { boat?.Boat.BodyColor.Name}";
pictureBoxBoat.Image = _abstractMap.CreateMap(pictureBoxBoat.Width, pictureBoxBoat.Height,
new DrawingObjectBoat(boat));
}
private void comboBoxMapSelector_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxMapSelector.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Водная карта":
_abstractMap = new WaterMap();
break;
}
}
}
}