76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
using ProjectMonorail.Scripts.Locomative;
|
|
|
|
namespace ProjectMonorail
|
|
{
|
|
public partial class FormMonorail : Form
|
|
{
|
|
private DrawMonorail? _drawningMonorail;
|
|
|
|
public FormMonorail()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Метод для прорисовки автомобиля
|
|
/// </summary>
|
|
private void Draw ()
|
|
{
|
|
if (_drawningMonorail == null) return;
|
|
|
|
Bitmap bmp = new(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningMonorail.DrawTransport(gr);
|
|
pictureBoxMonorail.Image = bmp;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Обработка нажатия кнопки "Создать"
|
|
/// </summary>
|
|
private void ButtonCreateMonorail_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
_drawningMonorail = new DrawMonorail();
|
|
|
|
_drawningMonorail.Initialization(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)));
|
|
|
|
_drawningMonorail.SetPictureSize(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
|
_drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
|
|
Draw();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Обработка кнопок перемешения
|
|
/// </summary>
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningMonorail == null) return;
|
|
|
|
string name = ((Button)sender).Name ?? string.Empty;
|
|
bool result = false;
|
|
switch(name)
|
|
{
|
|
case "buttonMove_Up":
|
|
result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Up);
|
|
break;
|
|
case "buttonMove_Down":
|
|
result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Down);
|
|
break;
|
|
case "buttonMove_Right":
|
|
result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Right);
|
|
break;
|
|
case "buttonMove_Left":
|
|
result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Left);
|
|
break;
|
|
}
|
|
|
|
if (result) Draw();
|
|
}
|
|
}
|
|
}
|