74 lines
2.6 KiB
C#
74 lines
2.6 KiB
C#
namespace ProjectMachine
|
|
{
|
|
public partial class FormMachine : Form
|
|
{
|
|
private DrawningMachine _machine;
|
|
|
|
public FormMachine()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
/// <summary>
|
|
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
|
/// </summary>
|
|
private void Draw()
|
|
{
|
|
Bitmap bmp = new(pictureBoxMachine.Width, pictureBoxMachine.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_machine?.DrawTransport(gr);
|
|
pictureBoxMachine.Image = bmp;
|
|
}
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random rnd = new();
|
|
_machine = new DrawningMachine();
|
|
_machine.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
_machine.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxMachine.Width, pictureBoxMachine.Height);
|
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_machine.Machine.Speed}";
|
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_machine.Machine.Weight}";
|
|
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_machine.Machine.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":
|
|
_machine?.MoveTransport(Direction.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_machine?.MoveTransport(Direction.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_machine?.MoveTransport(Direction.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_machine?.MoveTransport(Direction.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
/// <summary>
|
|
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void pictureBoxMachine_Resize(object sender, EventArgs e)
|
|
{
|
|
_machine?.ChangeBorders(pictureBoxMachine.Width, pictureBoxMachine.Height);
|
|
Draw();
|
|
}
|
|
}
|
|
} |