готовая лаб работа 2
This commit is contained in:
parent
40448cbf4f
commit
626b613b39
26
ProjectCar/ProjectCar/FormGasMachine.Designer.cs
generated
26
ProjectCar/ProjectCar/FormGasMachine.Designer.cs
generated
@ -35,6 +35,8 @@
|
|||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
pictureBoxGasMachine = new PictureBox();
|
pictureBoxGasMachine = new PictureBox();
|
||||||
buttonCreateMachine = new Button();
|
buttonCreateMachine = new Button();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonStrategyStep = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxGasMachine).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxGasMachine).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -117,11 +119,33 @@
|
|||||||
buttonCreateMachine.UseVisualStyleBackColor = true;
|
buttonCreateMachine.UseVisualStyleBackColor = true;
|
||||||
buttonCreateMachine.Click += ButtonCreateMachine_Click;
|
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
|
// FormGasMachine
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(988, 528);
|
ClientSize = new Size(988, 528);
|
||||||
|
Controls.Add(buttonStrategyStep);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonCreateMachine);
|
Controls.Add(buttonCreateMachine);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
@ -143,5 +167,7 @@
|
|||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private PictureBox pictureBoxGasMachine;
|
private PictureBox pictureBoxGasMachine;
|
||||||
private Button buttonCreateMachine;
|
private Button buttonCreateMachine;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,17 +1,27 @@
|
|||||||
using ProjectGasMachine.Drawnings;
|
using ProjectGasMachine.Drawnings;
|
||||||
|
using ProjectGasMachine.MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
namespace ProjectGasMachine;
|
namespace ProjectGasMachine;
|
||||||
public partial class FormGasMachine : Form
|
public partial class FormGasMachine : Form
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// поле-объект для прорисовки объекта
|
||||||
|
/// </summary>
|
||||||
private DrawningMachine? _drawningMachine;
|
private DrawningMachine? _drawningMachine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// стратегия перемещения
|
||||||
|
/// </summary>
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// конструктор формы
|
/// конструктор формы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormGasMachine()
|
public FormGasMachine()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -57,7 +67,8 @@ public partial class FormGasMachine : Form
|
|||||||
|
|
||||||
_drawningMachine.SetPictureSize(pictureBoxGasMachine.Width, pictureBoxGasMachine.Height);
|
_drawningMachine.SetPictureSize(pictureBoxGasMachine.Width, pictureBoxGasMachine.Height);
|
||||||
_drawningMachine.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningMachine.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
_strategy = null;
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +127,50 @@ public partial class FormGasMachine : Form
|
|||||||
{
|
{
|
||||||
Draw();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user