79 lines
2.9 KiB
C#

namespace Locomotive
{
public partial class FormLocomotive : Form
{
private DrawningLocomotive _locomotive;
public FormLocomotive()
{
InitializeComponent();
}
/// Ìåòîä ïðîðèñîâêè ìàøèíû
private void Draw()
{
Bitmap bmp = new(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
Graphics gr = Graphics.FromImage(bmp);
_locomotive?.DrawTransport(gr);
pictureBoxLocomotive.Image = bmp;
}
private void SetData()
{
toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}";
toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}";
toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}";
}
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);
SetData();
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();
}
private void buttonCreateModified_Click(object sender, EventArgs e)
{
Random rnd = new();
_locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)),
Convert.ToBoolean(rnd.Next(0, 2)));
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
SetData();
Draw();
}
}
}