Дополнение формы (логики, элементов)
This commit is contained in:
parent
5c75d533a1
commit
5890fcbba7
@ -6,7 +6,30 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AirBomber
|
namespace AirBomber
|
||||||
{
|
{
|
||||||
internal class DrawningObjectAirPlane
|
public class DrawningObjectAirPlane : IMoveableObject
|
||||||
{
|
{
|
||||||
|
private readonly DrawningAirPlane? _drawningAirPlane = null;
|
||||||
|
public DrawningObjectAirPlane(DrawningAirPlane drawningAirPlane)
|
||||||
|
{
|
||||||
|
_drawningAirPlane = drawningAirPlane;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningAirPlane == null || _drawningAirPlane.EntityAirPlane ==
|
||||||
|
null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawningAirPlane.GetPosX,
|
||||||
|
_drawningAirPlane.GetPosY, _drawningAirPlane.GetWidth, _drawningAirPlane.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningAirPlane?.EntityAirPlane?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(DirectionType direction) =>
|
||||||
|
_drawningAirPlane?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(DirectionType direction) =>
|
||||||
|
_drawningAirPlane?.MoveTransport(direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
50
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
50
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
@ -28,25 +28,27 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
buttonCreate = new Button();
|
buttonCreateAirBomber = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
pictureBoxAirBomber = new PictureBox();
|
pictureBoxAirBomber = new PictureBox();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonCreateAirPlane = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// buttonCreateAirBomber
|
||||||
//
|
//
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreate.Location = new Point(29, 479);
|
buttonCreateAirBomber.Location = new Point(29, 447);
|
||||||
buttonCreate.Name = "buttonCreate";
|
buttonCreateAirBomber.Name = "buttonCreateAirBomber";
|
||||||
buttonCreate.Size = new Size(148, 34);
|
buttonCreateAirBomber.Size = new Size(191, 66);
|
||||||
buttonCreate.TabIndex = 0;
|
buttonCreateAirBomber.TabIndex = 0;
|
||||||
buttonCreate.Text = "Создать";
|
buttonCreateAirBomber.Text = "Создать бомбардировщик";
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
buttonCreateAirBomber.UseVisualStyleBackColor = true;
|
||||||
buttonCreate.Click += buttonCreate_Click;
|
buttonCreateAirBomber.Click += buttonCreateAirBomber_Click;
|
||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
@ -106,16 +108,38 @@
|
|||||||
pictureBoxAirBomber.TabIndex = 5;
|
pictureBoxAirBomber.TabIndex = 5;
|
||||||
pictureBoxAirBomber.TabStop = false;
|
pictureBoxAirBomber.TabStop = false;
|
||||||
//
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightEdge" });
|
||||||
|
comboBoxStrategy.Location = new Point(755, 26);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(219, 33);
|
||||||
|
comboBoxStrategy.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// buttonCreateAirPlane
|
||||||
|
//
|
||||||
|
buttonCreateAirPlane.Location = new Point(249, 447);
|
||||||
|
buttonCreateAirPlane.Name = "buttonCreateAirPlane";
|
||||||
|
buttonCreateAirPlane.Size = new Size(191, 65);
|
||||||
|
buttonCreateAirPlane.TabIndex = 7;
|
||||||
|
buttonCreateAirPlane.Text = "Создать самолёт";
|
||||||
|
buttonCreateAirPlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateAirPlane.Click += buttonCreateAirPlane_Click;
|
||||||
|
//
|
||||||
// FormAirBomber
|
// FormAirBomber
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(986, 540);
|
ClientSize = new Size(986, 540);
|
||||||
|
Controls.Add(buttonCreateAirPlane);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonCreate);
|
Controls.Add(buttonCreateAirBomber);
|
||||||
Controls.Add(pictureBoxAirBomber);
|
Controls.Add(pictureBoxAirBomber);
|
||||||
Name = "FormAirBomber";
|
Name = "FormAirBomber";
|
||||||
Text = "Бомбардировщик";
|
Text = "Бомбардировщик";
|
||||||
@ -125,11 +149,13 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Button buttonCreate;
|
private Button buttonCreateAirBomber;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private PictureBox pictureBoxAirBomber;
|
private PictureBox pictureBoxAirBomber;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonCreateAirPlane;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,37 +2,52 @@
|
|||||||
{
|
{
|
||||||
public partial class FormAirBomber : Form
|
public partial class FormAirBomber : Form
|
||||||
{
|
{
|
||||||
private DrawningAirBomber? _drawningAirBomber;
|
private DrawningAirPlane? _drawningAirPlane;
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения
|
||||||
|
/// </summary>
|
||||||
|
private AbstractStrategy? _abstractStrategy;
|
||||||
public FormAirBomber()
|
public FormAirBomber()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningAirBomber == null)
|
if (_drawningAirPlane == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningAirBomber.DrawBomber(gr);
|
_drawningAirPlane.DrawPlane(gr);
|
||||||
pictureBoxAirBomber.Image = bmp;
|
pictureBoxAirBomber.Image = bmp;
|
||||||
}
|
}
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void buttonCreateAirBomber_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawningAirBomber = new DrawningAirBomber();
|
_drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
_drawningAirBomber.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)),
|
|
||||||
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)), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
Convert.ToBoolean(random.Next(0, 2)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)),
|
||||||
_drawningAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
|
||||||
|
_drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
}
|
||||||
|
private void buttonCreateAirPlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
_drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
|
pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
|
||||||
|
_drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningAirBomber == null)
|
if (_drawningAirPlane == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -40,19 +55,21 @@
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
_drawningAirBomber.MoveTransport(DirectionType.Up);
|
_drawningAirPlane.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
_drawningAirBomber.MoveTransport(DirectionType.Down);
|
_drawningAirPlane.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
_drawningAirBomber.MoveTransport(DirectionType.Left);
|
_drawningAirPlane.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
_drawningAirBomber.MoveTransport(DirectionType.Right);
|
_drawningAirPlane.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user