PIbd-13_Ladyagin_P.D._Simple/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs

97 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace ProjectAirplaneWithRadar
{
/// <summary>
/// Форма работы с объектом "Самолет с радаром"
/// </summary>
public partial class FormAirplaneWithRadar : Form
{
/// <summary>
/// Поле-объект для происовки объект
/// </summary>
private DrawingAirplaneWithRadar? _drawingAirplaneWithRadar;
/// <summary>
/// Конструктор формы
/// </summary>
public FormAirplaneWithRadar()
{
InitializeComponent();
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawingAirplaneWithRadar = new DrawingAirplaneWithRadar();
_drawingAirplaneWithRadar.Init(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
_drawingAirplaneWithRadar.SetPictureSize(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
_drawingAirplaneWithRadar.SetPosition(random.Next(10, 100), random.Next(10, 100));
UpdatePlane();
}
/// <summary>
/// Метод прорисовки самолета
/// </summary>
private void UpdatePlane()
{
if (_drawingAirplaneWithRadar == null)
{
return;
}
Bitmap bmp = new(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingAirplaneWithRadar?.DrawTransport(gr);
pictureBoxAirplaneWithRadar.Image = bmp;
}
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingAirplaneWithRadar == null)
{
return;
}
if (sender is Button button)
{
string name = button.Name;
DirectionType result;
switch (name)
{
case "buttonUp":
result = DirectionType.Up;
break;
case "buttonDown":
result = DirectionType.Down;
break;
case "buttonLeft":
result = DirectionType.Left;
break;
case "buttonRight":
result = DirectionType.Right;
break;
default:
return;
}
_drawingAirplaneWithRadar.MoveTransport(result);
UpdatePlane();
}
}
}
}