From 5890fcbba7004d6c9a478309033b95d2b9c9014a Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 23:12:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20(=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8,=20=D1=8D=D0=BB=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=BE=D0=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningObjectAirPlane.cs | 25 +++++++++- AirBomber/AirBomber/FormAirBomber.Designer.cs | 50 ++++++++++++++----- AirBomber/AirBomber/FormAirBomber.cs | 47 +++++++++++------ 3 files changed, 94 insertions(+), 28 deletions(-) diff --git a/AirBomber/AirBomber/DrawningObjectAirPlane.cs b/AirBomber/AirBomber/DrawningObjectAirPlane.cs index 18343ab..fe16e4a 100644 --- a/AirBomber/AirBomber/DrawningObjectAirPlane.cs +++ b/AirBomber/AirBomber/DrawningObjectAirPlane.cs @@ -6,7 +6,30 @@ using System.Threading.Tasks; 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); } } diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index 5e931c9..26b2b51 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -28,25 +28,27 @@ /// private void InitializeComponent() { - buttonCreate = new Button(); + buttonCreateAirBomber = new Button(); buttonDown = new Button(); buttonLeft = new Button(); buttonRight = new Button(); buttonUp = new Button(); pictureBoxAirBomber = new PictureBox(); + comboBoxStrategy = new ComboBox(); + buttonCreateAirPlane = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); SuspendLayout(); // - // buttonCreate + // buttonCreateAirBomber // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(29, 479); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(148, 34); - buttonCreate.TabIndex = 0; - buttonCreate.Text = "Создать"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += buttonCreate_Click; + buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateAirBomber.Location = new Point(29, 447); + buttonCreateAirBomber.Name = "buttonCreateAirBomber"; + buttonCreateAirBomber.Size = new Size(191, 66); + buttonCreateAirBomber.TabIndex = 0; + buttonCreateAirBomber.Text = "Создать бомбардировщик"; + buttonCreateAirBomber.UseVisualStyleBackColor = true; + buttonCreateAirBomber.Click += buttonCreateAirBomber_Click; // // buttonDown // @@ -106,16 +108,38 @@ pictureBoxAirBomber.TabIndex = 5; 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 // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(986, 540); + Controls.Add(buttonCreateAirPlane); + Controls.Add(comboBoxStrategy); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonLeft); Controls.Add(buttonDown); - Controls.Add(buttonCreate); + Controls.Add(buttonCreateAirBomber); Controls.Add(pictureBoxAirBomber); Name = "FormAirBomber"; Text = "Бомбардировщик"; @@ -125,11 +149,13 @@ #endregion - private Button buttonCreate; + private Button buttonCreateAirBomber; private Button buttonDown; private Button buttonLeft; private Button buttonRight; private Button buttonUp; private PictureBox pictureBoxAirBomber; + private ComboBox comboBoxStrategy; + private Button buttonCreateAirPlane; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index cf453fb..a365f9c 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -2,37 +2,52 @@ { public partial class FormAirBomber : Form { - private DrawningAirBomber? _drawningAirBomber; + private DrawningAirPlane? _drawningAirPlane; + /// + /// Стратегия перемещения + /// + private AbstractStrategy? _abstractStrategy; public FormAirBomber() { InitializeComponent(); } private void Draw() { - if (_drawningAirBomber == null) + if (_drawningAirPlane == null) { return; } Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningAirBomber.DrawBomber(gr); + _drawningAirPlane.DrawPlane(gr); pictureBoxAirBomber.Image = bmp; } - private void buttonCreate_Click(object sender, EventArgs e) + private void buttonCreateAirBomber_Click(object sender, EventArgs e) { Random random = new(); - _drawningAirBomber = new DrawningAirBomber(); - _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)), + _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)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); - - _drawningAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100)); + 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)), + 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(); } private void buttonMove_Click(object sender, EventArgs e) { - if (_drawningAirBomber == null) + if (_drawningAirPlane == null) { return; } @@ -40,19 +55,21 @@ switch (name) { case "buttonUp": - _drawningAirBomber.MoveTransport(DirectionType.Up); + _drawningAirPlane.MoveTransport(DirectionType.Up); break; case "buttonDown": - _drawningAirBomber.MoveTransport(DirectionType.Down); + _drawningAirPlane.MoveTransport(DirectionType.Down); break; case "buttonLeft": - _drawningAirBomber.MoveTransport(DirectionType.Left); + _drawningAirPlane.MoveTransport(DirectionType.Left); break; case "buttonRight": - _drawningAirBomber.MoveTransport(DirectionType.Right); + _drawningAirPlane.MoveTransport(DirectionType.Right); break; } Draw(); } + + } } \ No newline at end of file