PIbd-11_Gulina_V.S._LabWork02_Simple #2

Closed
victinass wants to merge 4 commits from LabWork02 into LabWork01
4 changed files with 34 additions and 38 deletions
Showing only changes of commit 7ef8b91458 - Show all commits

View File

@ -17,9 +17,6 @@ public class EntityBattleship : EntityWarship
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Перемещение военного корабля
/// </summary>
/// /// <summary>
/// Признак (опция) отсека для ракет
/// </summary>

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Battleship.Entities;
namespace Battleship.Entities;
/// <summary>
/// Класс-сущность Военный корабль
/// </summary>

View File

@ -1,40 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Battleship.MovementStrategy;
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestination()
{
var objParams = GetObjectParameters;
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder + GetStep() >= FieldHeight;
return objParams.RightBorder - GetStep() <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder - GetStep() <= FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
int diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
MoveRight();
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.DownBorder - FieldHeight;
int diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
MoveDown();
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Battleship.MovementStrategy;
namespace Battleship.MovementStrategy;
/// <summary>
/// Стратегия перемещения объекта в центр экрана
@ -14,20 +8,19 @@ public class MoveToCenter : AbstractStrategy
protected override bool IsTargetDestination()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams != null )
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontall - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontall + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null )
if (objParams == null)
{
return;
}
@ -45,10 +38,10 @@ public class MoveToCenter : AbstractStrategy
}
}
int diffy = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffy) > GetStep())
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffy > 0)
if (diffY > 0)
{
MoveUp();
}
@ -58,4 +51,4 @@ public class MoveToCenter : AbstractStrategy
}
}
}
}
}