2024-03-01 19:55:24 +04:00
|
|
|
|
using ProjectAirplaneWithRadar.Drawnings;
|
|
|
|
|
|
|
|
|
|
namespace ProjectAirplaneWithRadar
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
2024-02-18 17:22:50 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с объектом "Самолет с радаром"
|
|
|
|
|
/// </summary>
|
2024-02-10 18:11:15 +04:00
|
|
|
|
public partial class FormAirplaneWithRadar : Form
|
|
|
|
|
{
|
2024-02-18 17:22:50 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Поле-объект для происовки объект
|
|
|
|
|
/// </summary>
|
2024-03-01 19:55:24 +04:00
|
|
|
|
private DrawningAirplane? _drawingAirplane;
|
2024-02-21 16:34:26 +04:00
|
|
|
|
|
2024-02-18 17:22:50 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор формы
|
|
|
|
|
/// </summary>
|
2024-02-10 18:11:15 +04:00
|
|
|
|
public FormAirplaneWithRadar()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-18 17:22:50 +04:00
|
|
|
|
/// <summary>
|
2024-03-01 19:55:24 +04:00
|
|
|
|
/// Создание объекта класса-перемещения
|
2024-02-18 17:22:50 +04:00
|
|
|
|
/// </summary>
|
2024-03-01 19:55:24 +04:00
|
|
|
|
/// <param name="type">Тип создаваемого объекта</param>
|
|
|
|
|
private void CreateObject(string type)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
|
|
|
|
Random random = new();
|
2024-03-01 19:55:24 +04:00
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case nameof(DrawningAirplane):
|
|
|
|
|
_drawingAirplane = new DrawningAirplane(random.Next(100, 300), random.Next(1000, 3000),
|
|
|
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
|
|
|
|
break;
|
|
|
|
|
case nameof(DrawingAirplaneWithRadar):
|
|
|
|
|
_drawingAirplane = new DrawingAirplaneWithRadar(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)));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_drawingAirplane.SetPictureSize(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
|
|
|
|
_drawingAirplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
UpdatePlane();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-01 19:55:24 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия кнопки "Создать Самолет с радаром"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingAirplaneWithRadar));
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия кнопки "Создать Самолет"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCreateAirplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirplane));
|
|
|
|
|
|
2024-02-18 17:22:50 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Метод прорисовки самолета
|
|
|
|
|
/// </summary>
|
2024-02-10 18:11:15 +04:00
|
|
|
|
private void UpdatePlane()
|
|
|
|
|
{
|
2024-03-01 19:55:24 +04:00
|
|
|
|
if (_drawingAirplane == null)
|
2024-02-18 17:22:50 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-02-10 18:11:15 +04:00
|
|
|
|
Bitmap bmp = new(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
2024-03-01 19:55:24 +04:00
|
|
|
|
_drawingAirplane?.DrawTransport(gr);
|
2024-02-10 18:11:15 +04:00
|
|
|
|
pictureBoxAirplaneWithRadar.Image = bmp;
|
2024-03-01 19:55:24 +04:00
|
|
|
|
}
|
2024-02-18 17:22:50 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-02-10 18:11:15 +04:00
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-03-01 19:55:24 +04:00
|
|
|
|
if (_drawingAirplane == null)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
}
|
2024-03-01 19:55:24 +04:00
|
|
|
|
_drawingAirplane.MoveTransport(result);
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
UpdatePlane();
|
|
|
|
|
}
|
2024-03-01 19:55:24 +04:00
|
|
|
|
}
|
2024-02-10 18:11:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|