74 lines
2.1 KiB
C#
74 lines
2.1 KiB
C#
|
namespace AirBomber
|
||
|
{
|
||
|
public partial class BomberForm : Form
|
||
|
{
|
||
|
private BomberRenderer? _bomberRenderer;
|
||
|
|
||
|
public BomberForm()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
}
|
||
|
|
||
|
private void Draw()
|
||
|
{
|
||
|
if (_bomberRenderer == null)
|
||
|
return;
|
||
|
|
||
|
Bitmap bmp = new Bitmap(BomberPictureBox.Width, BomberPictureBox.Height);
|
||
|
Graphics g = Graphics.FromImage(bmp);
|
||
|
_bomberRenderer.DrawEntity(g);
|
||
|
|
||
|
BomberPictureBox.Image = bmp;
|
||
|
}
|
||
|
|
||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
Random random = new Random();
|
||
|
_bomberRenderer = new BomberRenderer();
|
||
|
|
||
|
_bomberRenderer.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)),
|
||
|
true,
|
||
|
true,
|
||
|
BomberPictureBox.Width,
|
||
|
BomberPictureBox.Height
|
||
|
);
|
||
|
_bomberRenderer.SetPosition(random.Next(20, 100), random.Next(20, 100));
|
||
|
|
||
|
Draw();
|
||
|
}
|
||
|
|
||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
if (_bomberRenderer == null)
|
||
|
return;
|
||
|
|
||
|
string ButtonName = ((Button)sender)?.Name ?? string.Empty;
|
||
|
|
||
|
switch (ButtonName)
|
||
|
{
|
||
|
case "ButtonUp":
|
||
|
_bomberRenderer.MoveEntity(DirectionType.Up);
|
||
|
break;
|
||
|
|
||
|
case "ButtonDown":
|
||
|
_bomberRenderer.MoveEntity(DirectionType.Down);
|
||
|
break;
|
||
|
|
||
|
case "ButtonLeft":
|
||
|
_bomberRenderer.MoveEntity(DirectionType.Left);
|
||
|
break;
|
||
|
|
||
|
case "ButtonRight":
|
||
|
_bomberRenderer.MoveEntity(DirectionType.Right);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
Draw();
|
||
|
}
|
||
|
}
|
||
|
}
|