74 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SelfPropelledArtilleryUnit
{
public partial class SelfPropelledArtilleryUnit : Form
{
private DrawningSelfPropelledArtilleryUnit? _drawningSelfPropelledArtilleryUnit;
public SelfPropelledArtilleryUnit()
{
InitializeComponent();
}
private void Draw()
{
if (_drawningSelfPropelledArtilleryUnit == null)
{
return;
}
Bitmap bmp = new(pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningSelfPropelledArtilleryUnit.DrawTransport(gr);
pictureBoxSelfPropelledArtilleryUnit.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningSelfPropelledArtilleryUnit = new DrawningSelfPropelledArtilleryUnit();
_drawningSelfPropelledArtilleryUnit.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)));
_drawningSelfPropelledArtilleryUnit.SetPictureSize(pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
_drawningSelfPropelledArtilleryUnit.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningSelfPropelledArtilleryUnit == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Up); break;
case "buttonDown":
result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Down); break;
case "buttonLeft":
result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Left); break;
case "buttonRight":
result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Right); break;
}
if (result)
{
Draw();
}
}
}
}