59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
namespace Artilleries
|
||
{
|
||
public partial class FormArtillery : Form
|
||
{
|
||
private DrawingArtillery _artillery;
|
||
|
||
public FormArtillery()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void Draw()
|
||
{
|
||
Bitmap bmp = new(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
|
||
Graphics gr = Graphics.FromImage(bmp);
|
||
_artillery?.DrawTransport(gr);
|
||
pictureBoxArtilleries.Image = bmp;
|
||
}
|
||
|
||
private void buttonCreate_Click(object sender, EventArgs e)
|
||
{
|
||
Random rnd = new();
|
||
_artillery = new DrawingArtillery();
|
||
_artillery.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||
_artillery.SetPosition(rnd.Next(pictureBoxArtilleries.Width - 161, pictureBoxArtilleries.Width - 81), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
|
||
SpeedStatusLabel.Text = $"Скорость: {_artillery.Artillery.Speed}";
|
||
WeightStatusLabel.Text = $"Вес: {_artillery.Artillery.Weight}";
|
||
ColorStatusLabel.Text = $"Цвет: {_artillery.Artillery.BodyColor.Name}";
|
||
Draw();
|
||
}
|
||
|
||
private void buttonMove_Click(object sender, EventArgs e)
|
||
{
|
||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||
switch (name)
|
||
{
|
||
case "buttonUp":
|
||
_artillery?.MoveTransport(Direction.Up);
|
||
break;
|
||
case "buttonDown":
|
||
_artillery?.MoveTransport(Direction.Down);
|
||
break;
|
||
case "buttonLeft":
|
||
_artillery?.MoveTransport(Direction.Left);
|
||
break;
|
||
case "buttonRight":
|
||
_artillery?.MoveTransport(Direction.Right);
|
||
break;
|
||
}
|
||
Draw();
|
||
}
|
||
|
||
private void pictureBoxArtilleries_Resize(object sender, EventArgs e)
|
||
{
|
||
_artillery?.ChangeBorders(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
|
||
Draw();
|
||
}
|
||
}
|
||
} |