Лабораторная работа №3
This commit is contained in:
parent
57e2f225a3
commit
7ef8b91458
@ -17,9 +17,6 @@ public class EntityBattleship : EntityWarship
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Перемещение военного корабля
|
||||
/// </summary>
|
||||
/// /// <summary>
|
||||
/// Признак (опция) отсека для ракет
|
||||
/// </summary>
|
||||
|
@ -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>
|
||||
|
@ -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())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
}
|
||||
|
||||
int diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user