70 lines
2.1 KiB
C#
70 lines
2.1 KiB
C#
namespace ContainerShip
|
|
{
|
|
public partial class FormShips : Form
|
|
{
|
|
private DrawingContainerShip? _drawningShip;
|
|
|
|
public FormShips()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private void Draw()
|
|
{
|
|
if (_drawningShip == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxShips.Width,
|
|
pictureBoxShips.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningShip.DrawTransport(gr);
|
|
pictureBoxShips.Image = bmp;
|
|
}
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningShip == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawningShip.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_drawningShip.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_drawningShip.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_drawningShip.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
_drawningShip = new DrawingContainerShip();
|
|
_drawningShip.Init(random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
|
random.Next(0, 256)),
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
|
random.Next(0, 256)),
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
pictureBoxShips.Width, pictureBoxShips.Height);
|
|
_drawningShip.SetPosition(random.Next(10, 100),
|
|
random.Next(10, 100));
|
|
Draw();
|
|
}
|
|
}
|
|
|
|
}
|