107 lines
3.8 KiB
C#
107 lines
3.8 KiB
C#
using ProjectMonorail.Scripts.Monorail.Drawnings;
|
|
|
|
namespace ProjectMonorail
|
|
{
|
|
public partial class FormMonorail : Form
|
|
{
|
|
private DrawingMonorail? _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 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(DirectionType.Up);
|
|
break;
|
|
case "buttonMove_Down":
|
|
result = _drawningMonorail.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonMove_Right":
|
|
result = _drawningMonorail.MoveTransport(DirectionType.Right);
|
|
break;
|
|
case "buttonMove_Left":
|
|
result = _drawningMonorail.MoveTransport(DirectionType.Left);
|
|
break;
|
|
}
|
|
|
|
if (result) Draw();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Создание объекта класса-перемещения
|
|
/// </summary>
|
|
/// <param name="type">Тип создоваемого объекта</param>
|
|
private void CreateObject(string type)
|
|
{
|
|
Random random = new();
|
|
|
|
switch (type)
|
|
{
|
|
case nameof(DrawingMonorail):
|
|
_drawningMonorail = new DrawingMonorail(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(DrawingModernMonorail):
|
|
bool randomTrack = Convert.ToBoolean(random.Next(0, 2));
|
|
_drawningMonorail = new DrawingModernMonorail(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)),
|
|
randomTrack,
|
|
(randomTrack? Convert.ToBoolean(random.Next(0, 2)) : true));
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
|
|
_drawningMonorail.SetPictureSize(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
|
_drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
|
|
Draw();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Обработка нажатия кнопки "Создать современный монорельс"
|
|
/// </summary>
|
|
private void ButtonCreateModernMonorail_Click(object sender, EventArgs e)
|
|
{
|
|
CreateObject(nameof(DrawingModernMonorail));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Обработка нажатия кнопки "Создать монорельс"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void buttonCreateMonorail_Click(object sender, EventArgs e)
|
|
{
|
|
CreateObject(nameof(DrawingMonorail));
|
|
}
|
|
|
|
}
|
|
}
|