diff --git a/ProjectCar/ProjectCar/FormGasMachine.Designer.cs b/ProjectCar/ProjectCar/FormGasMachine.Designer.cs
index bc29c66..09d6b1b 100644
--- a/ProjectCar/ProjectCar/FormGasMachine.Designer.cs
+++ b/ProjectCar/ProjectCar/FormGasMachine.Designer.cs
@@ -35,6 +35,8 @@
buttonDown = new Button();
pictureBoxGasMachine = new PictureBox();
buttonCreateMachine = new Button();
+ comboBoxStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxGasMachine).BeginInit();
SuspendLayout();
//
@@ -117,11 +119,33 @@
buttonCreateMachine.UseVisualStyleBackColor = true;
buttonCreateMachine.Click += ButtonCreateMachine_Click;
//
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
+ comboBoxStrategy.Location = new Point(858, 12);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(121, 23);
+ comboBoxStrategy.TabIndex = 7;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(901, 41);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(75, 23);
+ buttonStrategyStep.TabIndex = 8;
+ buttonStrategyStep.Text = "Шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += ButtonStrategyStep_Click;
+ //
// FormGasMachine
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(988, 528);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateMachine);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
@@ -143,5 +167,7 @@
private Button buttonDown;
private PictureBox pictureBoxGasMachine;
private Button buttonCreateMachine;
+ private ComboBox comboBoxStrategy;
+ private Button buttonStrategyStep;
}
}
\ No newline at end of file
diff --git a/ProjectCar/ProjectCar/FormGasMachine.cs b/ProjectCar/ProjectCar/FormGasMachine.cs
index e18514f..8aa8104 100644
--- a/ProjectCar/ProjectCar/FormGasMachine.cs
+++ b/ProjectCar/ProjectCar/FormGasMachine.cs
@@ -1,17 +1,27 @@
using ProjectGasMachine.Drawnings;
+using ProjectGasMachine.MovementStrategy;
namespace ProjectGasMachine;
public partial class FormGasMachine : Form
{
+ ///
+ /// поле-объект для прорисовки объекта
+ ///
private DrawningMachine? _drawningMachine;
+ ///
+ /// стратегия перемещения
+ ///
+ private AbstractStrategy? _strategy;
+
///
/// конструктор формы
///
public FormGasMachine()
{
InitializeComponent();
+ _strategy = null;
}
@@ -57,7 +67,8 @@ public partial class FormGasMachine : Form
_drawningMachine.SetPictureSize(pictureBoxGasMachine.Width, pictureBoxGasMachine.Height);
_drawningMachine.SetPosition(random.Next(10, 100), random.Next(10, 100));
-
+ _strategy = null;
+ comboBoxStrategy.Enabled = true;
Draw();
}
@@ -116,6 +127,50 @@ public partial class FormGasMachine : Form
{
Draw();
}
+ }
+
+ private void ButtonStrategyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawningMachine == null)
+ {
+ return;
+ }
+
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+
+ if (_strategy == null)
+ {
+ return;
+ }
+
+ _strategy.SetData(new MoveableMachine(_drawningMachine), pictureBoxGasMachine.Width, pictureBoxGasMachine.Height);
+ }
+
+ if (_strategy == null)
+ {
+ return;
+ }
+
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+
+
+
+
}
}