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 FormBoat : Form
{
private DrawingBoat _catamaran;
public DrawingBoat SelectedBoat { get; private set; }
public FormBoat()
{
InitializeComponent();
}
private void Draw()
{
Bitmap bmp = new Bitmap(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
Graphics gr = Graphics.FromImage(bmp);
_catamaran?.DrawTransport(gr);
pictureBoxCatamaran.Image = bmp;
}
private void SetData()
{
Random rnd = new Random();
_catamaran.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_catamaran.Catamaran.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_catamaran.Catamaran.Weight}";
toolStripStatusLabelColor.Text = $"Цвет: { _catamaran.Catamaran.BodyColor.Name}";
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_catamaran = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_catamaran?.MoveTransport(Direction.Up);
break;
case "buttonDown":
_catamaran?.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_catamaran?.MoveTransport(Direction.Left);
break;
case "buttonRight":
_catamaran?.MoveTransport(Direction.Right);
break;
}
Draw();
}
private void PictureBoxCatamaran_Resize(object sender, EventArgs e)
{
_catamaran?.ChangeBorders(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
Draw();
}
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
rnd.Next(0, 256));
ColorDialog dialogDop = new ColorDialog();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_catamaran = new DrawingCatamaran(rnd.Next(100, 300), rnd.Next(1000, 2000),
color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
///
/// Обработка нажатия кнопки "Выбрать"
///
///
///
private void buttonSelectBoat_Click(object sender, EventArgs e)
{
SelectedBoat = _catamaran;
DialogResult = DialogResult.OK;
}
}
}