187 lines
6.3 KiB
C#
187 lines
6.3 KiB
C#
|
using ProjectAntiAircraftGun.DrawingObjects;
|
|||
|
using ProjectAntiAircraftGun.MovementStrategy;
|
|||
|
using ProjectAntiAircraftGun.MovementStrategy;
|
|||
|
|
|||
|
namespace ProjectAntiAircraftGun
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
|||
|
/// </summary>
|
|||
|
public partial class FormAntiAircraftGun : Form
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
private DrawingTank? _drawingTank;
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
private AbstractStrategy? _abstractStrategy;
|
|||
|
|
|||
|
public DrawingTank? SelectedTank { get; private set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public FormAntiAircraftGun()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_abstractStrategy = null;
|
|||
|
SelectedTank = null;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </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>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>"
|
|||
|
/// </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>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
|||
|
/// </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>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </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>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD>"
|
|||
|
/// </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>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void ButtonSelectCar_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
SelectedTank = _drawingTank;
|
|||
|
DialogResult = DialogResult.OK;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|