95 lines
3.0 KiB
C#
95 lines
3.0 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)));
|
|
SetSize();
|
|
_drawningElectroTrans.SetPosition(50, 50);
|
|
Resize += Form1_Resize;
|
|
Draw();
|
|
}
|
|
|
|
private void Form1_Resize(object? sender, EventArgs e)
|
|
{
|
|
SetSize();
|
|
}
|
|
private void SetSize()
|
|
{
|
|
if (!_drawningElectroTrans.SetPictureSize(ClientSize.Width, ClientSize.Height))
|
|
{
|
|
Size = Config.screenSize;
|
|
}
|
|
pictureBoxSportCar.Size = ClientSize;
|
|
buttonCreateSportCar.Text = ClientSize.ToString();
|
|
}
|
|
|
|
/// <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();
|
|
}
|
|
}
|
|
}
|
|
}
|