2023-11-27 13:18:25 +04:00
|
|
|
|
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;
|
2023-11-30 14:13:38 +04:00
|
|
|
|
using Airbus_Base.DrawningObjects;
|
|
|
|
|
using Airbus_Base.MovementStrategy;
|
2023-11-27 13:18:25 +04:00
|
|
|
|
|
|
|
|
|
namespace Airbus_Base
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с объектом "Аэробус"
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormAirbus : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Поле-объект для прорисовки объекта
|
|
|
|
|
/// </summary>
|
2023-11-30 14:13:38 +04:00
|
|
|
|
private DrawningAirplane? _drawningAirplane;
|
2023-11-27 13:18:25 +04:00
|
|
|
|
/// <summary>
|
2023-11-30 14:13:38 +04:00
|
|
|
|
/// Стратегия перемещения
|
2023-11-27 13:18:25 +04:00
|
|
|
|
/// </summary>
|
2023-11-30 14:13:38 +04:00
|
|
|
|
private AbstractStrategy? _abstractStrategy;
|
2023-11-27 13:18:25 +04:00
|
|
|
|
public FormAirbus()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Метод прорисовки аэробуса
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Draw()
|
|
|
|
|
{
|
2023-11-30 14:13:38 +04:00
|
|
|
|
if (_drawningAirplane == null)
|
2023-11-27 13:18:25 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Bitmap bmp = new(pictureBoxAirbus.Width,
|
|
|
|
|
pictureBoxAirbus.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
2023-11-30 14:13:38 +04:00
|
|
|
|
_drawningAirplane.DrawTransport(gr);
|
2023-11-27 13:18:25 +04:00
|
|
|
|
pictureBoxAirbus.Image = bmp;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2023-11-30 14:13:38 +04:00
|
|
|
|
/// Обработка нажатия кнопки "Создать самолёт"
|
2023-11-27 13:18:25 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2023-11-30 14:13:38 +04:00
|
|
|
|
private void buttonCreateAirplane_Click(object sender, EventArgs e)
|
2023-11-27 13:18:25 +04:00
|
|
|
|
{
|
|
|
|
|
Random random = new();
|
2023-11-30 14:13:38 +04:00
|
|
|
|
_drawningAirplane = new DrawningAirplane(random.Next(100, 300), random.Next(1000, 3000),
|
|
|
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
|
|
|
pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
|
|
|
|
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия кнопки "Создать aэробус"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonCreateAirbus_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Random random = new();
|
|
|
|
|
_drawningAirplane = new DrawningAirbus(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)),
|
2023-11-27 13:18:25 +04:00
|
|
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
|
|
|
pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
2023-11-30 14:13:38 +04:00
|
|
|
|
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
2023-11-27 13:18:25 +04:00
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение размеров формы
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-11-30 14:13:38 +04:00
|
|
|
|
if (_drawningAirplane == null)
|
2023-11-27 13:18:25 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
|
switch (name)
|
|
|
|
|
{
|
|
|
|
|
case "buttonUp":
|
2023-11-30 14:13:38 +04:00
|
|
|
|
_drawningAirplane.MoveTransport(DirectionType.Up);
|
2023-11-27 13:18:25 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
2023-11-30 14:13:38 +04:00
|
|
|
|
_drawningAirplane.MoveTransport(DirectionType.Down);
|
2023-11-27 13:18:25 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
2023-11-30 14:13:38 +04:00
|
|
|
|
_drawningAirplane.MoveTransport(DirectionType.Left);
|
2023-11-27 13:18:25 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
2023-11-30 14:13:38 +04:00
|
|
|
|
_drawningAirplane.MoveTransport(DirectionType.Right);
|
2023-11-27 13:18:25 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
2023-11-30 14:13:38 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия кнопки "Шаг"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonStep_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningAirplane == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
|
{
|
|
|
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
|
|
|
switch
|
|
|
|
|
{
|
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_abstractStrategy.SetData(new
|
|
|
|
|
DrawningObjectAirplane(_drawningAirplane), pictureBoxAirbus.Width,
|
|
|
|
|
pictureBoxAirbus.Height);
|
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_abstractStrategy.MakeStep();
|
|
|
|
|
Draw();
|
|
|
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
|
|
|
{
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_abstractStrategy = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-27 13:18:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|