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