125 lines
4.4 KiB
C#
125 lines
4.4 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;
|
||
|
||
namespace Sailboat
|
||
{
|
||
public partial class BoatForm : Form
|
||
{
|
||
private DrawingBoat _boat;
|
||
/// <summary>
|
||
/// Выбранный объект
|
||
/// </summary>
|
||
public DrawingBoat SelectedBoat { get; private set; }
|
||
public BoatForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
/// <summary>
|
||
/// Обработка нажатия кнопки "Создать"
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btn_create_Click(object sender, EventArgs e)
|
||
{
|
||
Random rnd = new();
|
||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||
ColorDialog dialog = new();
|
||
if (dialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
color = dialog.Color;
|
||
}
|
||
_boat = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||
_boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
|
||
pictureBoxBoat.Width, pictureBoxBoat.Height);
|
||
SetData();
|
||
Draw();
|
||
}
|
||
/// <summary>
|
||
/// Обработка нажатия кнопки "Создать парусник"
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btn_create_sailboat_Click(object sender, EventArgs e)
|
||
{
|
||
Random rnd = new();
|
||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||
ColorDialog dialog = new();
|
||
if (dialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
color = dialog.Color;
|
||
}
|
||
Color edgeColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||
ColorDialog dialogDop = new();
|
||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||
{
|
||
edgeColor = dialogDop.Color;
|
||
}
|
||
_boat = new DrawingSailboat(rnd.Next(100, 300), rnd.Next(1000, 2000), color, edgeColor,
|
||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||
_boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
|
||
pictureBoxBoat.Width, pictureBoxBoat.Height);
|
||
SetData();
|
||
Draw();
|
||
}
|
||
/// <summary>
|
||
/// Обработка нажатия стрелок
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btn_move_Click(object sender, EventArgs e)
|
||
{
|
||
//получаем имя кнопки
|
||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||
switch (name)
|
||
{
|
||
case "btn_up":
|
||
_boat?.MoveTransport(Direction.Up);
|
||
break;
|
||
case "btn_down":
|
||
_boat?.MoveTransport(Direction.Down);
|
||
break;
|
||
case "btn_left":
|
||
_boat?.MoveTransport(Direction.Left);
|
||
break;
|
||
case "btn_right":
|
||
_boat?.MoveTransport(Direction.Right);
|
||
break;
|
||
}
|
||
Draw();
|
||
}
|
||
/// <summary>
|
||
/// Метод прорисовки машины
|
||
/// </summary>
|
||
private void Draw()
|
||
{
|
||
Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height);
|
||
Graphics gr = Graphics.FromImage(bmp);
|
||
_boat?.DrawTransport(gr);
|
||
pictureBoxBoat.Image = bmp;
|
||
}
|
||
/// <summary>
|
||
/// Метод прорисовки машины
|
||
/// </summary>
|
||
private void SetData()
|
||
{
|
||
Random rnd = new();
|
||
toolStripLabel_color.Text = $"Скорость: {_boat.Boat.Speed}";
|
||
toolStripLabel_weight.Text = $"Вес: {_boat.Boat.Weight}";
|
||
toolStripLabel_color.Text = $"Цвет: { _boat.Boat.BodyColor.Name}";
|
||
}
|
||
|
||
private void btn_select_Click(object sender, EventArgs e)
|
||
{
|
||
SelectedBoat = _boat;
|
||
DialogResult = DialogResult.OK;
|
||
}
|
||
}
|
||
}
|