88 lines
3.0 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 ProjectCleaningCar;
/// <summary>
/// Форма работы с классом Подметально-уборочная машина
/// </summary>
public partial class FormCleaningCar : Form
{
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawningCleaningCar? _drawningCleaningCar;
/// <summary>
/// Конструктор формы
/// </summary>
public FormCleaningCar()
{
InitializeComponent();
}
/// <summary>
/// Метод прорисовки машины
/// </summary>
private void Draw()
{
if (_drawningCleaningCar == null)
{
return;
}
Bitmap bmp = new(pictureBoxCleaningCar.Width,
pictureBoxCleaningCar.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningCleaningCar.DrawTransport(gr);
pictureBoxCleaningCar.Image = bmp;
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateCleaningCar_Click(object sender, EventArgs e)
{
Random random = new();
_drawningCleaningCar = new DrawningCleaningCar();
_drawningCleaningCar.Init(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)));
_drawningCleaningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
_drawningCleaningCar.SetPosition(random.Next(0, 200), random.Next(0, 200));
Draw();
}
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningCleaningCar == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result = _drawningCleaningCar.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawningCleaningCar.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _drawningCleaningCar.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _drawningCleaningCar.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();
}
}
}