126 lines
4.3 KiB
C#
126 lines
4.3 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 Airbus
|
||
{
|
||
public partial class FormPlane : Form
|
||
{
|
||
private DrawningPlane _plane;
|
||
|
||
public DrawningPlane SelectedPlane { get; private set; }
|
||
|
||
public FormPlane()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
/// <summary>
|
||
/// Метод прорисовки самолета
|
||
/// </summary>
|
||
private void Draw()
|
||
{
|
||
Bitmap bmp = new(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||
Graphics gr = Graphics.FromImage(bmp);
|
||
_plane?.DrawTransport(gr);
|
||
pictureBoxAirbus.Image = bmp;
|
||
}
|
||
|
||
private void SetData()
|
||
{
|
||
Random rnd = new();
|
||
_plane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||
toolStripStatusLabelSpeed.Text = $"Скорость: {_plane.Plane.Speed}";
|
||
toolStripStatusLabelWeight.Text = $"Вес: {_plane.Plane.Weight}";
|
||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_plane.Plane.BodyColor.Name}";
|
||
}
|
||
/// <summary>
|
||
/// Обработка нажатия кнопки "Создать"
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonCreate_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;
|
||
}
|
||
_plane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 2000),color);
|
||
SetData();
|
||
Draw();
|
||
}
|
||
/// <summary>
|
||
/// Изменение размеров формы
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonMove_Click(object sender, EventArgs e)
|
||
{
|
||
//получаем имя кнопки
|
||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||
switch (name)
|
||
{
|
||
case "buttonUp":
|
||
_plane?.MoveTransport(Direction.Up);
|
||
break;
|
||
case "buttonDown":
|
||
_plane?.MoveTransport(Direction.Down);
|
||
break;
|
||
case "buttonLeft":
|
||
_plane?.MoveTransport(Direction.Left);
|
||
break;
|
||
case "buttonRight":
|
||
_plane?.MoveTransport(Direction.Right);
|
||
break;
|
||
}
|
||
Draw();
|
||
}
|
||
/// <summary>
|
||
/// Изменение размеров формы
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void PictureBoxAirbus_Resize(object sender, EventArgs e)
|
||
{
|
||
_plane?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||
Draw();
|
||
}
|
||
|
||
private void buttonCreateModif_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 dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||
ColorDialog dialogDop = new();
|
||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||
{
|
||
dopColor = dialogDop.Color;
|
||
}
|
||
_plane = new DrawningAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||
SetData();
|
||
Draw();
|
||
}
|
||
|
||
private void buttonSelectPlane_Click(object sender, EventArgs e)
|
||
{
|
||
SelectedPlane = _plane;
|
||
DialogResult = DialogResult.OK;
|
||
}
|
||
}
|
||
|
||
}
|