Лабораторная работа №3
This commit is contained in:
parent
57e2f225a3
commit
7ef8b91458
@ -17,9 +17,6 @@ public class EntityBattleship : EntityWarship
|
|||||||
/// Основной цвет
|
/// Основной цвет
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; private set; }
|
||||||
/// <summary>
|
|
||||||
/// Перемещение военного корабля
|
|
||||||
/// </summary>
|
|
||||||
/// /// <summary>
|
/// /// <summary>
|
||||||
/// Признак (опция) отсека для ракет
|
/// Признак (опция) отсека для ракет
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace Battleship.Entities;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Battleship.Entities;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность Военный корабль
|
/// Класс-сущность Военный корабль
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,40 +1,52 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Battleship.MovementStrategy;
|
namespace Battleship.MovementStrategy;
|
||||||
|
|
||||||
public class MoveToBorder : AbstractStrategy
|
public class MoveToBorder : AbstractStrategy
|
||||||
{
|
{
|
||||||
protected override bool IsTargetDestination()
|
protected override bool IsTargetDestination()
|
||||||
{
|
{
|
||||||
var objParams = GetObjectParameters;
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
if (objParams == null)
|
if (objParams == null)
|
||||||
{
|
{
|
||||||
return false;
|
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()
|
protected override void MoveToTarget()
|
||||||
{
|
{
|
||||||
var objParams = GetObjectParameters;
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
if (objParams == null)
|
if (objParams == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var diffX = objParams.RightBorder - FieldWidth;
|
|
||||||
|
int diffX = objParams.RightBorder - FieldWidth;
|
||||||
if (Math.Abs(diffX) > GetStep())
|
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())
|
if (Math.Abs(diffY) > GetStep())
|
||||||
{
|
{
|
||||||
MoveDown();
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace Battleship.MovementStrategy;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Battleship.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Стратегия перемещения объекта в центр экрана
|
/// Стратегия перемещения объекта в центр экрана
|
||||||
@ -14,20 +8,19 @@ public class MoveToCenter : AbstractStrategy
|
|||||||
protected override bool IsTargetDestination()
|
protected override bool IsTargetDestination()
|
||||||
{
|
{
|
||||||
ObjectParameters? objParams = GetObjectParameters;
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
if (objParams != null )
|
if (objParams == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return objParams.ObjectMiddleHorizontall - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontall + GetStep() >= FieldWidth / 2 &&
|
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()
|
protected override void MoveToTarget()
|
||||||
{
|
{
|
||||||
ObjectParameters? objParams = GetObjectParameters;
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
if (objParams == null )
|
if (objParams == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -45,10 +38,10 @@ public class MoveToCenter : AbstractStrategy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int diffy = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
if (Math.Abs(diffy) > GetStep())
|
if (Math.Abs(diffY) > GetStep())
|
||||||
{
|
{
|
||||||
if (diffy > 0)
|
if (diffY > 0)
|
||||||
{
|
{
|
||||||
MoveUp();
|
MoveUp();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user