116 lines
3.7 KiB
C#
116 lines
3.7 KiB
C#
namespace AirFighter
|
|
{
|
|
public partial class AirFighterForm : Form
|
|
{
|
|
private DrawingAircraft _aircraft;
|
|
|
|
public DrawingAircraft SelectedAircraft { get; private set; }
|
|
|
|
public AirFighterForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Draw()
|
|
{
|
|
Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_aircraft?.DrawTransport(gr);
|
|
pictureBoxAirFighter.Image = bmp;
|
|
}
|
|
|
|
private void SetData()
|
|
{
|
|
Random rnd = new Random();
|
|
|
|
_aircraft.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
|
toolStripStatusSpeed.Text = $"Speed: {_aircraft.Plane.Speed}";
|
|
toolStripStatusWeight.Text = $"Weight: {_aircraft.Plane.Weight}";
|
|
toolStripStatusBodyColor.Text = $"BodyColor: {_aircraft.Plane.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;
|
|
}
|
|
_aircraft = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
|
color);
|
|
SetData();
|
|
Draw();
|
|
|
|
}
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
{
|
|
_aircraft?.MoveTransport(Direction.Up);
|
|
}
|
|
break;
|
|
case "buttonDown":
|
|
{
|
|
_aircraft?.MoveTransport(Direction.Down);
|
|
}
|
|
break;
|
|
case "buttonLeft":
|
|
{
|
|
_aircraft?.MoveTransport(Direction.Left);
|
|
}
|
|
break;
|
|
case "buttonRight":
|
|
{
|
|
_aircraft?.MoveTransport(Direction.Right);
|
|
}
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
private void pictureBoxAirFighter_Resize(object sender, EventArgs e)
|
|
{
|
|
_aircraft?.ChangeBorders(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
|
Draw();
|
|
}
|
|
|
|
private void buttonCreateModification_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;
|
|
}
|
|
_aircraft = new DrawingMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
|
color, dopColor,
|
|
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,
|
|
2)));
|
|
SetData();
|
|
Draw();
|
|
|
|
}
|
|
|
|
private void SelectButton_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedAircraft = _aircraft;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
} |