79 lines
2.7 KiB
C#
79 lines
2.7 KiB
C#
namespace HoistingCrane
|
|
{
|
|
public partial class FormHoistingCrane : Form
|
|
{
|
|
private DrawingHoistingCrane _hoistingCrane;
|
|
public FormHoistingCrane()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Draw()
|
|
{
|
|
Bitmap bmp = new(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_hoistingCrane?.DrawTransport(gr);
|
|
pictureBoxHoistingCrane.Image = bmp;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random rnd = new();
|
|
_hoistingCrane = new DrawingHoistingCrane();
|
|
_hoistingCrane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
_hoistingCrane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
|
|
pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_hoistingCrane.HoistingCrane.Speed}";
|
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_hoistingCrane.HoistingCrane.Weight}";
|
|
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_hoistingCrane.HoistingCrane.BodyColor.Name} ";
|
|
Draw();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_hoistingCrane?.MoveTransport(Direction.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_hoistingCrane?.MoveTransport(Direction.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_hoistingCrane?.MoveTransport(Direction.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_hoistingCrane?.MoveTransport(Direction.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
|
|
private void PictureBoxBulldozer_Resize(object sender, EventArgs e)
|
|
{
|
|
_hoistingCrane?.ChangeBorders(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
|
Draw();
|
|
}
|
|
}
|
|
}
|