105 lines
3.7 KiB
C#
105 lines
3.7 KiB
C#
namespace Locomotive
|
|
{
|
|
public partial class FormLocomotive : Form
|
|
{
|
|
private DrawningLocomotive _locomotive;
|
|
public DrawningLocomotive SelectedLocomotive { get; private set; }
|
|
|
|
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();
|
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),rnd.Next(0, 256));
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
color = dialog.Color;
|
|
}
|
|
_locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
|
_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();
|
|
|
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
color = dialog.Color;
|
|
}
|
|
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
|
ColorDialog dialogDop = new();
|
|
if (dialogDop.ShowDialog() == DialogResult.OK)
|
|
{
|
|
dopColor = dialogDop.Color;
|
|
}
|
|
|
|
_locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
|
color,
|
|
dopColor,
|
|
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();
|
|
}
|
|
|
|
private void buttonSelectLocomotive_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedLocomotive = _locomotive;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
} |