80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
namespace Lab1
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
/// <summary>
|
|
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
|
/// </summary>
|
|
private DrawingElectroTrans _drawningElectroTrans;
|
|
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
_drawningElectroTrans = new DrawingElectroTrans();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
|
/// </summary>
|
|
private void Draw()
|
|
{
|
|
if (_drawningElectroTrans == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Bitmap bmp = new(pictureBoxSportCar.Width, pictureBoxSportCar.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningElectroTrans.DrawTransport(gr);
|
|
pictureBoxSportCar.Image = bmp;
|
|
}
|
|
private void ButtonCreateElectroTrans_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
_drawningElectroTrans.Init(random.Next(500, 1500), 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)), random.Next(3, 8), Convert.ToBoolean(random.Next(0, 2)));
|
|
_drawningElectroTrans.SetPictureSize(pictureBoxSportCar.Size.Width, pictureBoxSportCar.Size.Height);
|
|
_drawningElectroTrans.SetPosition(random.Next(0, 5), random.Next(0, 5));
|
|
Draw();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ïåðåìåùåíèå îáúåêòà ïî ôîðìå (íàæàòèå êíîïîê íàâèãàöèè)
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningElectroTrans == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
bool result = false;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
result = _drawningElectroTrans.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
result = _drawningElectroTrans.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
result = _drawningElectroTrans.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
result = _drawningElectroTrans.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
|
|
if (result)
|
|
{
|
|
Draw();
|
|
}
|
|
}
|
|
}
|
|
}
|