From 18e8449fdf0782733927b2398473d5b73708bb82 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 25 Sep 2023 23:53:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingStormTrooper.cs | 2 +- .../FormStormtrooper.Designer.cs | 64 ++++++++++++--- .../ProjectStormtrooper/FormStormtrooper.cs | 81 ++++++++++++++++--- 3 files changed, 121 insertions(+), 26 deletions(-) diff --git a/ProjectStormtrooper/ProjectStormtrooper/DrawingStormTrooper.cs b/ProjectStormtrooper/ProjectStormtrooper/DrawingStormTrooper.cs index 9778ff8..47dde2b 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/DrawingStormTrooper.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/DrawingStormTrooper.cs @@ -24,7 +24,7 @@ namespace ProjectStormtrooper /// Высота картинки public DrawingStormtrooper(int speed, double weight, Color bodyColor, Color additionalColor, bool rockets, bool bombs, - int width, int height) : base(speed, weight, bodyColor, width, height, 110, 110) + int width, int height) : base(speed, weight, bodyColor, width, height, 140, 90) { if (EntityPlane != null) { diff --git a/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.Designer.cs b/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.Designer.cs index 9b11491..735e23f 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.Designer.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.Designer.cs @@ -29,11 +29,14 @@ private void InitializeComponent() { pictureBoxStormtrooper = new PictureBox(); - buttonCreate = new Button(); + buttonCreateStormtrooper = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonLeft = new Button(); buttonRight = new Button(); + buttonCreatePlane = new Button(); + comboBoxStrategy = new ComboBox(); + buttonStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit(); SuspendLayout(); // @@ -47,16 +50,16 @@ pictureBoxStormtrooper.TabIndex = 0; pictureBoxStormtrooper.TabStop = false; // - // buttonCreate + // buttonCreateStormtrooper // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 412); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(94, 29); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += buttonCreate_Click; + buttonCreateStormtrooper.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateStormtrooper.Location = new Point(12, 412); + buttonCreateStormtrooper.Name = "buttonCreateStormtrooper"; + buttonCreateStormtrooper.Size = new Size(201, 29); + buttonCreateStormtrooper.TabIndex = 1; + buttonCreateStormtrooper.Text = "Создать штурмовик"; + buttonCreateStormtrooper.UseVisualStyleBackColor = true; + buttonCreateStormtrooper.Click += buttonCreateStormtrooper_Click; // // buttonUp // @@ -106,16 +109,50 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += buttonMove_Click; // + // buttonCreatePlane + // + buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreatePlane.Location = new Point(219, 412); + buttonCreatePlane.Name = "buttonCreatePlane"; + buttonCreatePlane.Size = new Size(201, 29); + buttonCreatePlane.TabIndex = 6; + buttonCreatePlane.Text = "Создать самолет"; + buttonCreatePlane.UseVisualStyleBackColor = true; + buttonCreatePlane.Click += buttonCreatePlane_Click; + // + // comboBoxStrategy + // + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter" }); + comboBoxStrategy.Location = new Point(719, 12); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(151, 28); + comboBoxStrategy.TabIndex = 7; + // + // buttonStep + // + buttonStep.Location = new Point(776, 46); + buttonStep.Name = "buttonStep"; + buttonStep.Size = new Size(94, 29); + buttonStep.TabIndex = 8; + buttonStep.Text = "Шаг"; + buttonStep.UseVisualStyleBackColor = true; + buttonStep.Click += buttonStep_Click; + // // FormStormtrooper // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(882, 453); + Controls.Add(buttonStep); + Controls.Add(comboBoxStrategy); + Controls.Add(buttonCreatePlane); Controls.Add(buttonRight); Controls.Add(buttonLeft); Controls.Add(buttonDown); Controls.Add(buttonUp); - Controls.Add(buttonCreate); + Controls.Add(buttonCreateStormtrooper); Controls.Add(pictureBoxStormtrooper); Name = "FormStormtrooper"; StartPosition = FormStartPosition.CenterScreen; @@ -128,10 +165,13 @@ #endregion private PictureBox pictureBoxStormtrooper; - private Button buttonCreate; + private Button buttonCreateStormtrooper; private Button buttonUp; private Button buttonDown; private Button buttonLeft; private Button buttonRight; + private Button buttonCreatePlane; + private ComboBox comboBoxStrategy; + private Button buttonStep; } } \ No newline at end of file diff --git a/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs b/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs index d8b7972..dc08c5c 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs @@ -8,7 +8,8 @@ namespace ProjectStormtrooper /// /// - /// - private DrawingStormtrooper? _drawingStormtrooper; + private DrawingPlane? _drawingPlane; + private AbstractStrategy? _abstractStrategy; /// /// /// @@ -21,25 +22,24 @@ namespace ProjectStormtrooper /// private void Draw() { - if (_drawingStormtrooper == null) + if (_drawingPlane == null) { return; } Bitmap bmp = new(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); Graphics g = Graphics.FromImage(bmp); - _drawingStormtrooper.DrawTransport(g); + _drawingPlane.DrawTransport(g); pictureBoxStormtrooper.Image = bmp; } /// - /// "" + /// " " /// /// /// - private void buttonCreate_Click(object sender, EventArgs e) + private void buttonCreateStormtrooper_Click(object sender, EventArgs e) { Random random = new(); - _drawingStormtrooper = new DrawingStormtrooper(); - _drawingStormtrooper.Init( + _drawingPlane = new DrawingStormtrooper( random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), @@ -49,7 +49,25 @@ namespace ProjectStormtrooper pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height ); - _drawingStormtrooper.SetPosition(random.Next(10, 100), random.Next(10, 100)); + _drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + /// + /// " " + /// + /// + /// + private void buttonCreatePlane_Click(object sender, EventArgs e) + { + Random random = new(); + _drawingPlane = new DrawingPlane( + random.Next(100, 300), + random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + pictureBoxStormtrooper.Width, + pictureBoxStormtrooper.Height + ); + _drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } /// @@ -59,7 +77,7 @@ namespace ProjectStormtrooper /// private void buttonMove_Click(object sender, EventArgs e) { - if (_drawingStormtrooper == null) + if (_drawingPlane == null) { return; } @@ -67,19 +85,56 @@ namespace ProjectStormtrooper switch (buttonName) { case "buttonUp": - _drawingStormtrooper.MoveTransport(DirectionType.Up); + _drawingPlane.MoveTransport(DirectionType.Up); break; case "buttonDown": - _drawingStormtrooper.MoveTransport(DirectionType.Down); + _drawingPlane.MoveTransport(DirectionType.Down); break; case "buttonLeft": - _drawingStormtrooper.MoveTransport(DirectionType.Left); + _drawingPlane.MoveTransport(DirectionType.Left); break; case "buttonRight": - _drawingStormtrooper.MoveTransport(DirectionType.Right); + _drawingPlane.MoveTransport(DirectionType.Right); break; } Draw(); } + /// + /// "" + /// + /// + /// + private void buttonStep_Click(object sender, EventArgs e) + { + if (_drawingPlane == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _abstractStrategy = comboBoxStrategy.SelectedIndex switch + { + 0 => new MoveToCenter(), + _ => null, + }; + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.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