From 68ac0088fd2925d2814b799a019db35e708bc3b8 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 23:43:59 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D1=8B,=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3=D0=B8=D0=B8=20MoveToCenter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 9 ++--- AirBomber/AirBomber/DrawningAirPlane.cs | 16 +++++--- AirBomber/AirBomber/FormAirBomber.Designer.cs | 16 ++++++++ AirBomber/AirBomber/FormAirBomber.cs | 37 ++++++++++++++++++- 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index f18461c..acb1c5c 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -42,23 +42,20 @@ namespace AirBomber Brush bombsColor = new SolidBrush(airBomber.BombsColor); base.DrawPlane(g); // обвесы - if (airBomber.Bombs) - { + g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 20, 15, 29); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29); g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 70, 15, 29); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29); g.FillEllipse(bombsColor, _startPosX + 140, _startPosY + 50, 15, 15); g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15); - } + // fueltanks - if (airBomber.FuelTanks) - { g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 34, 20, 15); g.DrawRectangle(pen, _startPosX + 63, _startPosY + 34, 20, 15); g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 70, 20, 15); g.DrawRectangle(pen, _startPosX + 63, _startPosY + 70, 20, 15); - } + } } } diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index c9af062..18f23d8 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -112,11 +112,17 @@ namespace AirBomber break; // вправо case DirectionType.Right: - // TODO: Продумать логику + if (_startPosX + EntityAirPlane.Step + _airPlaneWidth < _pictureWidth) + { + _startPosX += (int)EntityAirPlane.Step; + } break; //вниз case DirectionType.Down: - // TODO: Продумать логику + if (_startPosY + EntityAirPlane.Step + _airPlaneHeight < _pictureHeight) + { + _startPosY += (int)EntityAirPlane.Step; + } break; } } @@ -249,9 +255,9 @@ namespace AirBomber //вверх DirectionType.Up => _startPosY - EntityAirPlane.Step > 0, // вправо - DirectionType.Right => false,// TODO: Продумать логику - //вниз - DirectionType.Down => false,// TODO: Продумать логику + DirectionType.Right => _startPosX + EntityAirPlane.Step < _pictureWidth, + //вниз + DirectionType.Down => _startPosY + EntityAirPlane.Step < _pictureHeight, _ => false, }; } diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index 26b2b51..637d4fb 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -36,6 +36,7 @@ pictureBoxAirBomber = new PictureBox(); comboBoxStrategy = new ComboBox(); buttonCreateAirPlane = new Button(); + buttonStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); SuspendLayout(); // @@ -110,6 +111,7 @@ // // comboBoxStrategy // + comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightEdge" }); @@ -120,6 +122,7 @@ // // buttonCreateAirPlane // + buttonCreateAirPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreateAirPlane.Location = new Point(249, 447); buttonCreateAirPlane.Name = "buttonCreateAirPlane"; buttonCreateAirPlane.Size = new Size(191, 65); @@ -128,11 +131,23 @@ buttonCreateAirPlane.UseVisualStyleBackColor = true; buttonCreateAirPlane.Click += buttonCreateAirPlane_Click; // + // buttonStep + // + buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonStep.Location = new Point(862, 77); + buttonStep.Name = "buttonStep"; + buttonStep.Size = new Size(112, 49); + buttonStep.TabIndex = 8; + buttonStep.Text = "Шаг"; + buttonStep.UseVisualStyleBackColor = true; + buttonStep.Click += buttonStep_Click; + // // FormAirBomber // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(986, 540); + Controls.Add(buttonStep); Controls.Add(buttonCreateAirPlane); Controls.Add(comboBoxStrategy); Controls.Add(buttonUp); @@ -157,5 +172,6 @@ private PictureBox pictureBoxAirBomber; private ComboBox comboBoxStrategy; private Button buttonCreateAirPlane; + private Button buttonStep; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index a365f9c..785941a 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -69,7 +69,42 @@ } Draw(); } + private void buttonStep_Click(object sender, EventArgs e) + { + if (_drawningAirPlane == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _abstractStrategy = comboBoxStrategy.SelectedIndex + switch + { + 0 => new MoveToCenter(), + //1 => new MoveToBorder(), + _ => null, + }; + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.SetData(new + DrawningObjectAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width, + pictureBoxAirBomber.Height); + comboBoxStrategy.Enabled = false; + } + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.MakeStep(); + Draw(); + if (_abstractStrategy.GetStatus() == Status.Finish) + { + comboBoxStrategy.Enabled = true; + _abstractStrategy = null; + } - + } } } \ No newline at end of file