Лаба 2 без допов.

This commit is contained in:
MariaBelkina 2024-03-26 09:38:42 +04:00
parent a8c7158463
commit 378bceea9b
7 changed files with 58 additions and 10 deletions

View File

@ -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);

View File

@ -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

View File

@ -53,7 +53,9 @@ public abstract class AbstractStrategy
FieldHeight = height;
}
/// <summary>
/// Шаг перемещения
/// </summary>
public void MakeStep()
{
if (_state != StrategyStatus.InProgress)

View File

@ -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();
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ProjectBulldozer.MovementStrategy;
public class MoveToBorder : AbstractStrategy
public class MoveToBorderRB : AbstractStrategy
{
protected override bool IsTargetDestinaion()

View File

@ -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()

View File

@ -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;
}