PIbd22_Kamcharova_K.A._Doub.../DoubleDeckerBus/FormDoubleDeckerBus.cs

63 lines
2.1 KiB
C#

namespace DoubleDeckerBus
{
public partial class FormDoubleDeckerBus : Form
{
private DrawingBus? _drawingBus;
public FormDoubleDeckerBus()
{
InitializeComponent();
}
private void Draw()
{
if (_drawingBus == null)
{
return;
}
Bitmap bmp = new(pictureBoxBus.Width, pictureBoxBus.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingBus.DrawTransport(gr);
pictureBoxBus.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawingBus = new DrawingBus();
EntityDoubleDeckerBus bus = new EntityDoubleDeckerBus();
bus.Init(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)));
_drawingBus.Init(bus, pictureBoxBus.Width, pictureBoxBus.Height);
_drawingBus.SetPosition(random.Next(10, 100),
random.Next(10, 100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingBus == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingBus.MoveTransport(Direction.Up);
break;
case "buttonDown":
_drawingBus.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_drawingBus.MoveTransport(Direction.Left);
break;
case "buttonRight":
_drawingBus.MoveTransport(Direction.Right);
break;
}
Draw();
}
}
}