187 lines
6.3 KiB
C#
187 lines
6.3 KiB
C#
using ProjectAntiAircraftGun.DrawingObjects;
|
|
using ProjectAntiAircraftGun.MovementStrategy;
|
|
using ProjectAntiAircraftGun.MovementStrategy;
|
|
|
|
namespace ProjectAntiAircraftGun
|
|
{
|
|
/// <summary>
|
|
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Çåíèòíàÿ óñòàíîâêà"
|
|
/// </summary>
|
|
public partial class FormAntiAircraftGun : Form
|
|
{
|
|
/// <summary>
|
|
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
|
/// </summary>
|
|
private DrawingTank? _drawingTank;
|
|
/// <summary>
|
|
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
|
/// </summary>
|
|
private AbstractStrategy? _abstractStrategy;
|
|
|
|
public DrawingTank? SelectedTank { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Èíèöèàëèçàöèÿ ôîðìû
|
|
/// </summary>
|
|
public FormAntiAircraftGun()
|
|
{
|
|
InitializeComponent();
|
|
_abstractStrategy = null;
|
|
SelectedTank = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ìåòîä ïðîðèñîâêè çåíèòíîé óñòàíîâêè
|
|
/// </summary>
|
|
private void Draw()
|
|
{
|
|
if (_drawingTank == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width,
|
|
pictureBoxAntiAircraftGun.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawingTank.DrawTransport(gr);
|
|
pictureBoxAntiAircraftGun.Image = bmp;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü òàíê"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonCreateTank_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
Color color = Color.FromArgb(random.Next(0, 256),
|
|
random.Next(0, 256), random.Next(0, 256));
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
color = dialog.Color;
|
|
}
|
|
|
|
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
|
random.Next(0, 256), random.Next(0, 256));
|
|
_drawingTank = new DrawingTank(random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
color, dopColor,
|
|
pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
|
_drawingTank.SetPosition(random.Next(10, 100), random.Next(10,
|
|
100));
|
|
Draw();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü çåíèòíóþ óñòàíîâêó"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonCreateAntiAircraftGun(object sender, EventArgs e)
|
|
{
|
|
ColorDialog dialogCoreColor = new ColorDialog();
|
|
|
|
Random random = new();
|
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
if (dialogCoreColor.ShowDialog() == DialogResult.OK) { color = dialogCoreColor.Color; }
|
|
|
|
ColorDialog dialogSatelliteColor = new ColorDialog();
|
|
|
|
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
|
random.Next(0, 256), random.Next(0, 256));
|
|
if (dialogSatelliteColor.ShowDialog() == DialogResult.OK) { dopColor = dialogSatelliteColor.Color; }
|
|
|
|
|
|
_drawingTank = new DrawingAntiAircraftGun(random.Next(100, 300),
|
|
random.Next(1000, 3000),color,dopColor,
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
|
pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
|
_drawingTank.SetPosition(random.Next(10, 100), random.Next(10,
|
|
100));
|
|
Draw();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèé êíîïîê óïðàâëåíèÿ çåíèòíîé óñòàíîâêîé
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingTank == null) return;
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawingTank.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_drawingTank.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_drawingTank.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_drawingTank.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingTank == null)
|
|
{
|
|
return;
|
|
}
|
|
if (comboBoxStrategy.Enabled)
|
|
{
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToBorder(),
|
|
_ => null,
|
|
};
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.SetData(new
|
|
DrawingObjectTank(_drawingTank), pictureBoxAntiAircraftGun.Width,
|
|
pictureBoxAntiAircraftGun.Height);
|
|
comboBoxStrategy.Enabled = false;
|
|
}
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.MakeStep();
|
|
Draw();
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_abstractStrategy = null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Âûáîð òàíêà
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonSelectCar_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedTank = _drawingTank;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
} |