PIbd-21_Kargin_D.E._AirFigh.../AirFighter/AirFighter/FormAirFighter.cs
2022-10-29 18:17:32 +04:00

120 lines
4.4 KiB
C#

namespace AirFighter
{
public partial class FormAirFighter : Form
{
private DrawningAirFighter _airFighter;
/// <summary>
/// Âûáðàííûé îáúåêò
/// </summary>
public DrawningAirFighter SelectedAirFighter { get ; private set; }
public FormAirFighter()
{
InitializeComponent();
}
/// <summary>
/// Ìåòîä ïðîðèñîâêè ñàìîëåòà
/// </summary>
private void Draw()
{
Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
Graphics g = Graphics.FromImage(bmp);
_airFighter?.DrawAirFighter(g);
pictureBoxAirFighter.Image = bmp;
}
/// <summary>
/// Ìåòîä óñòàíîâêè äàííûõ
/// </summary>
private void SetData()
{
Random rnd = new Random();
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter?.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter?.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airFighter.AirFighter?.BodyColor}";
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
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;
}
_airFighter = new DrawningAirFighter(rnd.Next(200, 500), rnd.Next(2000, 5000), color);
SetData();
Draw();
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïîê äâèæåíèÿ
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_airFighter?.MoveTransport(Direction.Up);
break;
case "buttonDown":
_airFighter?.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_airFighter?.MoveTransport(Direction.Left);
break;
case "buttonRight":
_airFighter?.MoveTransport(Direction.Right);
break;
}
Draw();
}
/// <summary>
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBoxAirFighter_Resize(object sender, EventArgs e)
{
_airFighter?.ChangeBorders(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
Draw();
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonUpgrade_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;
}
_airFighter = new DrawningUpgradeAirFighter(rnd.Next(300, 600), rnd.Next(2000, 5000), color,
dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
private void ButtonSelectAirFighter_Click(object sender, EventArgs e)
{
SelectedAirFighter = _airFighter;
DialogResult = DialogResult.OK;
}
}
}