Лаба 2 без допов.
This commit is contained in:
parent
a8c7158463
commit
378bceea9b
@ -126,7 +126,7 @@
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К левому нижнему краю", "К правому нижнему краю" });
|
||||
comboBoxStrategy.Location = new Point(620, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(242, 40);
|
||||
|
@ -148,7 +148,8 @@ public partial class FormBulldozer : Form
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
1 => new MoveToBorderLB(),
|
||||
2 => new MoveToBorderRB(),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
@ -161,11 +162,11 @@ public partial class FormBulldozer : Form
|
||||
pictureBoxBulldozer.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
@ -177,3 +178,5 @@ public partial class FormBulldozer : Form
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//2
|
||||
|
@ -53,7 +53,9 @@ public abstract class AbstractStrategy
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
|
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBulldozer.MovementStrategy;
|
||||
|
||||
public class MoveToBorderLB : AbstractStrategy
|
||||
{
|
||||
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objParams.LeftBorder - GetStep() <= 0 && objParams.BottomBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int diffX = objParams.LeftBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
|
||||
int diffY = objParams.BottomBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBulldozer.MovementStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
public class MoveToBorderRB : AbstractStrategy
|
||||
{
|
||||
|
||||
protected override bool IsTargetDestinaion()
|
@ -22,8 +22,8 @@ public class MoveToCenter : AbstractStrategy
|
||||
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical >= FieldHeight / 2;
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
|
@ -44,7 +44,7 @@ public class MoveableDozer : IMoveableObject
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_dozer != null || _dozer.EntityDozer == null)
|
||||
if (_dozer == null || _dozer.EntityDozer == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user