Правки2лаб
This commit is contained in:
parent
35ef737015
commit
6412d03510
@ -3,44 +3,19 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
// using Tank.Drawings;
|
|
||||||
|
|
||||||
namespace Tank.MovementStrategy
|
namespace Tank.MovementStrategy
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Класс-стратегия перемещения объекта
|
|
||||||
/// </summary>
|
|
||||||
public abstract class AbstractStrategy
|
public abstract class AbstractStrategy
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Перемещаемый объект
|
|
||||||
/// </summary>
|
|
||||||
private IMoveableObject? _moveableObject;
|
private IMoveableObject? _moveableObject;
|
||||||
/// <summary>
|
|
||||||
/// Статус перемещения
|
|
||||||
/// </summary>
|
|
||||||
private Status _state = Status.NotInit;
|
private Status _state = Status.NotInit;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина поля
|
|
||||||
/// </summary>
|
|
||||||
protected int FieldWidth { get; private set; }
|
protected int FieldWidth { get; private set; }
|
||||||
/// <summary>
|
|
||||||
/// Высота поля
|
|
||||||
/// </summary>
|
|
||||||
protected int FieldHeight { get; private set; }
|
protected int FieldHeight { get; private set; }
|
||||||
/// <summary>
|
|
||||||
/// Статус перемещения
|
|
||||||
/// </summary>
|
|
||||||
public Status GetStatus() { return _state; }
|
public Status GetStatus() { return _state; }
|
||||||
/// <summary>
|
|
||||||
/// Установка данных
|
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||||
/// </summary>
|
|
||||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
|
||||||
/// <param name="width">Ширина поля</param>
|
|
||||||
/// <param name="height">Высота поля</param>
|
|
||||||
public void SetData(IMoveableObject moveableObject, int width, int
|
|
||||||
height)
|
|
||||||
{
|
{
|
||||||
if (moveableObject == null)
|
if (moveableObject == null)
|
||||||
{
|
{
|
||||||
@ -49,58 +24,28 @@ namespace Tank.MovementStrategy
|
|||||||
}
|
}
|
||||||
_state = Status.InProgress;
|
_state = Status.InProgress;
|
||||||
_moveableObject = moveableObject;
|
_moveableObject = moveableObject;
|
||||||
FieldWidth = width;
|
|
||||||
FieldHeight = height;
|
FieldHeight = height;
|
||||||
|
FieldWidth = width;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения
|
|
||||||
/// </summary>
|
|
||||||
public void MakeStep()
|
public void MakeStep()
|
||||||
{
|
{
|
||||||
if (_state != Status.InProgress)
|
if (_state != Status.InProgress)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
if (IsTargetDestination())
|
||||||
if (IsTargetDestinaion())
|
|
||||||
{
|
{
|
||||||
_state = Status.Finish;
|
_state = Status.Finish;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MoveToTarget();
|
MoveToTarget();
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Перемещение влево
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false -
|
|
||||||
// неудача)</returns>
|
|
||||||
protected bool MoveLeft() => MoveTo(Direction.Left);
|
protected bool MoveLeft() => MoveTo(Direction.Left);
|
||||||
/// <summary>
|
protected bool MoveRight() => MoveTo(Direction.Right);
|
||||||
/// Перемещение вправо
|
protected bool MoveUp() => MoveTo(Direction.Up);
|
||||||
/// </summary>
|
protected bool MoveDown() => MoveTo(Direction.Down);
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться,
|
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectParameters;
|
||||||
// false - неудача)</returns>
|
|
||||||
protected bool MoveRight() => MoveTo(Direction.Right);
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вверх
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться,
|
|
||||||
// false - неудача)</returns>
|
|
||||||
protected bool MoveUp() => MoveTo(Direction.Up);
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вниз
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться,
|
|
||||||
// false - неудача)</returns>
|
|
||||||
protected bool MoveDown() => MoveTo(Direction.Down);
|
|
||||||
/// <summary>
|
|
||||||
/// Параметры объекта
|
|
||||||
/// </summary>
|
|
||||||
protected ObjectParameters? GetObjectParameters =>
|
|
||||||
_moveableObject?.GetObjectPosition;
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected int? GetStep()
|
protected int? GetStep()
|
||||||
{
|
{
|
||||||
if (_state != Status.InProgress)
|
if (_state != Status.InProgress)
|
||||||
@ -109,33 +54,20 @@ protected bool MoveDown() => MoveTo(Direction.Down);
|
|||||||
}
|
}
|
||||||
return _moveableObject?.GetStep;
|
return _moveableObject?.GetStep;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Перемещение к цели
|
|
||||||
/// </summary>
|
|
||||||
protected abstract void MoveToTarget();
|
protected abstract void MoveToTarget();
|
||||||
/// <summary>
|
|
||||||
/// Достигнута ли цель
|
protected abstract bool IsTargetDestination();
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
private bool MoveTo(Direction direction)
|
||||||
protected abstract bool IsTargetDestinaion();
|
|
||||||
/// <summary>
|
|
||||||
/// Попытка перемещения в требуемом направлении
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="directionType">Направление</param>
|
|
||||||
/// <returns>Результат попытки (true - удалось переместиться, false -
|
|
||||||
// неудача)</returns>
|
|
||||||
private bool MoveTo(Direction directionType)
|
|
||||||
{
|
{
|
||||||
if (_state != Status.InProgress)
|
if (_state != Status.InProgress)
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
if (_moveableObject?.CheckCanMove(direction) ?? false)
|
||||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
|
||||||
{
|
{
|
||||||
_moveableObject.MoveObject(directionType);
|
_moveableObject.MoveObject(direction);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ namespace Tank.DrawingObjects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityArmoredCar? EntityArmoredCar { get; protected set; }
|
public EntityArmoredCar? Tank { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Координата X объекта
|
/// Координата X объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -42,53 +42,20 @@ namespace Tank.DrawingObjects
|
|||||||
/// направлению</returns>
|
/// направлению</returns>
|
||||||
public bool CanMove(Direction direction)
|
public bool CanMove(Direction direction)
|
||||||
{
|
{
|
||||||
if (EntityArmoredCar == null)
|
if (Tank == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return direction switch
|
return direction switch
|
||||||
{
|
{
|
||||||
//влево
|
|
||||||
Direction.Left => _startPosX - EntityArmoredCar.Step > 0,
|
Direction.Left => _startPosX - Tank.Step > 0,
|
||||||
//вверх
|
Direction.Up => _startPosY - Tank.Step > 0,
|
||||||
Direction.Up => _startPosY - EntityArmoredCar.Step > 0,
|
Direction.Right => _startPosX + Tank.Step < _pictureWidth - _ArmoredcarWidth, //вниз
|
||||||
// вправо
|
Direction.Down => _startPosY + Tank.Step < _pictureHeight - _ArmoredcarHeight,
|
||||||
Direction.Right => false,// TODO: Продумать логику
|
|
||||||
//вниз
|
|
||||||
Direction.Down => false,// TODO: Продумать логику
|
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Изменение направления перемещения
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction">Направление</param>
|
|
||||||
public void MoveTransport(Direction direction)
|
|
||||||
{
|
|
||||||
if (!CanMove(direction) || EntityArmoredCar == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (direction)
|
|
||||||
{
|
|
||||||
//влево
|
|
||||||
case Direction.Left:
|
|
||||||
_startPosX -= (int)EntityArmoredCar.Step;
|
|
||||||
break;
|
|
||||||
//вверх
|
|
||||||
case Direction.Up:
|
|
||||||
_startPosY -= (int)EntityArmoredCar.Step;
|
|
||||||
break;
|
|
||||||
// вправо
|
|
||||||
case Direction.Right:
|
|
||||||
_startPosX += (int)EntityArmoredCar.Step;
|
|
||||||
break;
|
|
||||||
//вниз
|
|
||||||
case Direction.Down:
|
|
||||||
_startPosY += (int)EntityArmoredCar.Step;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
@ -122,13 +89,16 @@ namespace Tank.DrawingObjects
|
|||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
/// <param name="width">Ширина картинки</param>
|
/// <param name="width">Ширина картинки</param>
|
||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
public DrawningArmoredCar(int speed, double weight, Color bodyColor, int
|
public DrawingArmoredCar(int speed, double weight, Color bodyColor, int
|
||||||
width, int height)
|
width, int height)
|
||||||
{
|
{
|
||||||
// TODO: Продумать проверки
|
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
EntityArmoredCar = new EntityArmoredCar(speed, weight, bodyColor);
|
if (_pictureHeight < _ArmoredcarHeight || _pictureWidth < _ArmoredcarWidth)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Tank = new EntityArmoredCar(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
@ -140,15 +110,17 @@ namespace Tank.DrawingObjects
|
|||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
/// <param name="carWidth">Ширина прорисовки автомобиля</param>
|
/// <param name="carWidth">Ширина прорисовки автомобиля</param>
|
||||||
/// <param name="carHeight">Высота прорисовки автомобиля</param>
|
/// <param name="carHeight">Высота прорисовки автомобиля</param>
|
||||||
protected DrawningArmoredCar(int speed, double weight, Color bodyColor, int
|
protected DrawingArmoredCar(int speed, double weight, Color bodyColor, int
|
||||||
width, int height, int carWidth, int carHeight)
|
width, int height, int carWidth, int carHeight)
|
||||||
{
|
{
|
||||||
// TODO: Продумать проверки
|
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
_ArmoredcarWidth = carWidth;
|
_ArmoredcarWidth = _ArmoredcarWidth;
|
||||||
_ArmoredcarHeight = carHeight;
|
_ArmoredcarHeight = _ArmoredcarHeight;
|
||||||
EntityArmoredCar = new EntityArmoredCar(speed, weight, bodyColor);
|
if (_pictureHeight < _ArmoredcarHeight || _pictureWidth < _ArmoredcarWidth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Tank = new EntityArmoredCar(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции
|
/// Установка позиции
|
||||||
@ -158,8 +130,14 @@ namespace Tank.DrawingObjects
|
|||||||
|
|
||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
// TODO: Изменение x, y, если при установке объект выходит за
|
if (x <0 || x > _pictureHeight - _ArmoredcarHeight)
|
||||||
// границы
|
{
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
if (y < 0 || y > _pictureWidth - _ArmoredcarWidth)
|
||||||
|
{
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
@ -167,77 +145,69 @@ namespace Tank.DrawingObjects
|
|||||||
/// Изменение направления перемещения
|
/// Изменение направления перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="direction">Направление</param>
|
/// <param name="direction">Направление</param>
|
||||||
//public void MoveTransport(Direction direction)
|
public void MoveTransport(Direction direction)
|
||||||
//{
|
{
|
||||||
// if (EntityArmoredCar == null)
|
if (Tank == null)
|
||||||
// {
|
{
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// switch (direction)
|
switch (direction)
|
||||||
// {
|
{
|
||||||
// //влево
|
//влево
|
||||||
// case Direction.Left:
|
case Direction.Left:
|
||||||
// if (_startPosX - EntityArmoredCar.Step > 0)
|
if (_startPosX - Tank.Step > 0)
|
||||||
// {
|
{
|
||||||
// _startPosX -= (int)EntityArmoredCar.Step;
|
_startPosX -= (int)Tank.Step;
|
||||||
// }
|
}
|
||||||
// break;
|
break;
|
||||||
// //вверх
|
//вверх
|
||||||
// case Direction.Up:
|
case Direction.Up:
|
||||||
// if (_startPosY - EntityArmoredCar.Step > 0)
|
if (_startPosY - Tank.Step > 0)
|
||||||
// {
|
{
|
||||||
// _startPosY -= (int)EntityArmoredCar.Step;
|
_startPosY -= (int)Tank.Step;
|
||||||
// }
|
}
|
||||||
// break;
|
break;
|
||||||
// // вправо
|
// вправо
|
||||||
// case Direction.Right:
|
case Direction.Right:
|
||||||
// if (_startPosX + EntityArmoredCar.Step + _ArmoredcarWidth < _pictureWidth)
|
if (_startPosX + Tank.Step + _ArmoredcarWidth < _pictureWidth)
|
||||||
// {
|
{
|
||||||
// _startPosX += (int)EntityArmoredCar.Step;
|
_startPosX += (int)Tank.Step;
|
||||||
// }
|
}
|
||||||
// break;
|
break;
|
||||||
// //вниз
|
//вниз
|
||||||
// case Direction.Down:
|
case Direction.Down:
|
||||||
// if (_startPosY + EntityArmoredCar.Step + _ArmoredcarHeight < _pictureHeight)
|
if (_startPosY + Tank.Step + _ArmoredcarHeight < _pictureHeight)
|
||||||
// {
|
{
|
||||||
// _startPosY += (int)EntityArmoredCar.Step;
|
_startPosY += (int)Tank.Step;
|
||||||
// }
|
}
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
//}
|
//}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public virtual void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityArmoredCar == null)
|
if (Tank == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//кузов
|
Brush BrushRandom = new SolidBrush(Tank?.BodyColor ?? Color.Black);
|
||||||
Brush br = new SolidBrush(EntityArmoredCar.BodyColor);
|
|
||||||
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
|
|
||||||
|
|
||||||
|
|
||||||
// не мое
|
//кузов
|
||||||
Brush BrushRandom = new SolidBrush(EntityArmoredCar?.BodyColor ?? Color.Black);
|
Brush br = new SolidBrush(Tank.BodyColor);
|
||||||
|
g.FillRectangle(br, _startPosX + 5, _startPosY + 17, 110, 18);
|
||||||
|
g.FillRectangle(br, _startPosX + 30, _startPosY, 50, 15);
|
||||||
|
|
||||||
|
// колеса
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 95, _startPosY + 35, 20, 20);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 35, 20, 20);
|
||||||
|
|
||||||
|
|
||||||
// Корпус
|
|
||||||
Point[] pointsbody = { new Point(_startPosX + 5, _startPosY + 30), new Point(_startPosX + 110, _startPosY + 30),
|
|
||||||
new Point(_startPosX + 142, _startPosY + 30), new Point(_startPosX + 120, _startPosY + 45), new Point(_startPosX + 12, _startPosY + 45) };
|
|
||||||
g.FillPolygon(BrushRandom, pointsbody);
|
|
||||||
|
|
||||||
// Колеса, катки
|
|
||||||
Brush ColorBlack = new SolidBrush(Color.Black);
|
|
||||||
g.FillEllipse(ColorBlack, 10 + _startPosX, 42 + _startPosY, 20, 20);
|
|
||||||
g.FillEllipse(ColorBlack, 35 + _startPosX, 42 + _startPosY, 20, 20);
|
|
||||||
g.FillEllipse(ColorBlack, 60 + _startPosX, 42 + _startPosY, 20, 20);
|
|
||||||
g.FillEllipse(ColorBlack, 85 + _startPosX, 42 + _startPosY, 20, 20);
|
|
||||||
g.FillEllipse(ColorBlack, 110 + _startPosX, 42 + _startPosY, 20, 20);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,30 +8,30 @@ using Tank.DrawingObjects;
|
|||||||
namespace Tank.MovementStrategy
|
namespace Tank.MovementStrategy
|
||||||
{
|
{
|
||||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
|
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
|
||||||
public class DrawningObjectArmoredCar : IMoveableObject
|
public class DrawingObjectArmoredCar : IMoveableObject
|
||||||
{
|
{
|
||||||
private readonly DrawingArmoredCar? _drawningArmoredCar = null;
|
private readonly DrawingArmoredCar? _drawingArmoredCar = null;
|
||||||
public DrawningObjectArmoredCar(DrawingArmoredCar drawningArmoredCar)
|
public DrawingObjectArmoredCar(DrawingArmoredCar drawingArmoredCar)
|
||||||
{
|
{
|
||||||
_drawningArmoredCar = drawningArmoredCar;
|
_drawingArmoredCar = drawingArmoredCar;
|
||||||
}
|
}
|
||||||
public ObjectParameters? GetObjectPosition
|
public ObjectParameters? GetObjectParameters
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_drawningArmoredCar == null || _drawningArmoredCar.EntityArmoredCar ==
|
if (_drawingArmoredCar == null || _drawingArmoredCar.Tank ==
|
||||||
null)
|
null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new ObjectParameters(_drawningArmoredCar.GetPosX,
|
return new ObjectParameters(_drawingArmoredCar.GetPosX,
|
||||||
_drawningArmoredCar.GetPosY, _drawningArmoredCar.GetWidth, _drawningArmoredCar.GetHeight);
|
_drawingArmoredCar.GetPosY, _drawingArmoredCar.GetWidth, _drawingArmoredCar.GetHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int GetStep => (int)(_drawningArmoredCar?.EntityArmoredCar?.Step ?? 0);
|
public int GetStep => (int)(_drawingArmoredCar?.Tank?.Step ?? 0);
|
||||||
public bool CheckCanMove(Direction direction) =>
|
public bool CheckCanMove(Direction direction) =>
|
||||||
_drawningArmoredCar?.CanMove(direction) ?? false;
|
_drawingArmoredCar?.CanMove(direction) ?? false;
|
||||||
public void MoveObject(Direction direction) =>
|
public void MoveObject(Direction direction) =>
|
||||||
_drawningArmoredCar?.MoveTransport(direction);
|
_drawingArmoredCar?.MoveTransport(direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,23 +31,13 @@ namespace Tank.DrawingObjects
|
|||||||
additionalColor, bodyKit, wing, sportLine);
|
additionalColor, bodyKit, wing, sportLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
///// Установка позиции
|
|
||||||
//public void SetPosition(int x, int y)
|
|
||||||
//{
|
|
||||||
// if (x >= 0 && x + _tankWidth <= _pictureWidth &&
|
|
||||||
// y >= 0 && y + _tankHeight <= _pictureHeight)
|
|
||||||
// {
|
|
||||||
// _startPosX = x;
|
|
||||||
// _startPosY = y;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
public override void DrawTransport(Graphics g)
|
public override void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (Tank is not EntityTank ArmoredCar)
|
if (Tank is not EntityTank ArmoredCar)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// base.DrawTransport(g);
|
base.DrawTransport(g);
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush additionalBrush = new
|
Brush additionalBrush = new
|
||||||
SolidBrush(ArmoredCar.AdditionalColor);
|
SolidBrush(ArmoredCar.AdditionalColor);
|
||||||
@ -82,96 +72,53 @@ namespace Tank.DrawingObjects
|
|||||||
g.FillRectangle(br, _startPosX + 5, _startPosY + 17, 110, 18);
|
g.FillRectangle(br, _startPosX + 5, _startPosY + 17, 110, 18);
|
||||||
g.FillRectangle(br, _startPosX + 30, _startPosY, 50, 15);
|
g.FillRectangle(br, _startPosX + 30, _startPosY, 50, 15);
|
||||||
|
|
||||||
// // пулемет
|
// пулемет
|
||||||
// g.FillRectangle(br, _startPosX + 80, _startPosY + 3, 25, 5);
|
g.FillRectangle(br, _startPosX + 80, _startPosY + 3, 25, 5);
|
||||||
|
|
||||||
// // зенитный пулемет на башне
|
// зенитный пулемет на башне
|
||||||
// g.FillRectangle(br, _startPosX + 40, _startPosY - 10, 20, 5);
|
g.FillRectangle(br, _startPosX + 40, _startPosY - 10, 20, 5);
|
||||||
|
|
||||||
// g.FillRectangle(brBlack, _startPosX + 50, _startPosY - 5, 5, 5);
|
g.FillRectangle(brBlack, _startPosX + 50, _startPosY - 5, 5, 5);
|
||||||
// g.FillRectangle(brBlack, _startPosX + 55, _startPosY - 10, 5, 10);
|
g.FillRectangle(brBlack, _startPosX + 55, _startPosY - 10, 5, 10);
|
||||||
// g.FillRectangle(brBlack, _startPosX + 52, _startPosY - 7, 3, 2);
|
g.FillRectangle(brBlack, _startPosX + 52, _startPosY - 7, 3, 2);
|
||||||
|
|
||||||
// //выделяем рамкой весь танк
|
//выделяем рамкой весь танк
|
||||||
// g.DrawRectangle(pen, _startPosX + 5, _startPosY + 17, 110, 18);
|
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 17, 110, 18);
|
||||||
// g.DrawRectangle(pen, _startPosX + 30, _startPosY, 50, 15);
|
g.DrawRectangle(pen, _startPosX + 30, _startPosY, 50, 15);
|
||||||
// g.DrawRectangle(pen, _startPosX + 80, _startPosY + 3, 25, 5);
|
g.DrawRectangle(pen, _startPosX + 80, _startPosY + 3, 25, 5);
|
||||||
// g.DrawRectangle(pen, _startPosX + 40, _startPosY - 10, 20, 5);
|
g.DrawRectangle(pen, _startPosX + 40, _startPosY - 10, 20, 5);
|
||||||
|
|
||||||
//// обвесы
|
// обвесы
|
||||||
//if (Tank.BodyKit) // entityTank
|
if (ArmoredCar.BodyKit) // entityTank
|
||||||
//{
|
{
|
||||||
// Brush brAdd = new SolidBrush(EntityTank.AdditionalColor);
|
Brush brAdd = new SolidBrush(ArmoredCar.AdditionalColor);
|
||||||
|
|
||||||
// g.FillRectangle(brAdd, _startPosX + 5, _startPosY + 17, 20, 18);
|
g.FillRectangle(brAdd, _startPosX + 5, _startPosY + 17, 20, 18);
|
||||||
// g.FillRectangle(brAdd, _startPosX + 95, _startPosY + 17, 20, 18);
|
g.FillRectangle(brAdd, _startPosX + 95, _startPosY + 17, 20, 18);
|
||||||
// g.DrawRectangle(pen, _startPosX + 5, _startPosY + 17, 20, 18);
|
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 17, 20, 18);
|
||||||
// g.DrawRectangle(pen, _startPosX + 95, _startPosY + 17, 20, 18);
|
g.DrawRectangle(pen, _startPosX + 95, _startPosY + 17, 20, 18);
|
||||||
|
|
||||||
// g.FillRectangle(brAdd, _startPosX + 100, _startPosY + 4, 5, 4);
|
g.FillRectangle(brAdd, _startPosX + 100, _startPosY + 4, 5, 4);
|
||||||
|
|
||||||
//}
|
}
|
||||||
|
|
||||||
//// спортивная линия
|
// спортивная линия
|
||||||
//if (Tank.SportLine)
|
if (ArmoredCar.SportLine)
|
||||||
//{
|
{
|
||||||
// g.FillRectangle(additionalBrush, _startPosX + 75,
|
g.FillRectangle(additionalBrush, _startPosX + 75,
|
||||||
// _startPosY + 23, 25, 15);
|
_startPosY + 23, 25, 15);
|
||||||
// g.FillRectangle(additionalBrush, _startPosX + 35,
|
g.FillRectangle(additionalBrush, _startPosX + 35,
|
||||||
// _startPosY + 23, 35, 15);
|
_startPosY + 23, 35, 15);
|
||||||
// g.FillRectangle(additionalBrush, _startPosX + 10,
|
g.FillRectangle(additionalBrush, _startPosX + 10,
|
||||||
// _startPosY + 23, 20, 15);
|
_startPosY + 23, 20, 15);
|
||||||
//}
|
}
|
||||||
|
|
||||||
//// багажник
|
|
||||||
//if (EntityTank.Trunk) // Tank
|
|
||||||
//{
|
|
||||||
// g.FillRectangle(additionalBrush, _startPosX + 23, _startPosY + 4, 8, 10);
|
|
||||||
// g.DrawRectangle(pen, _startPosX + 23, _startPosY + 4, 8, 10);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
// /// Инициализация свойств
|
|
||||||
// /// </summary>
|
|
||||||
// /// <param name="speed">Скорость</param>
|
|
||||||
// /// <param name="weight">Вес</param>
|
|
||||||
// /// <param name="bodyColor">Цвет кузова</param>
|
|
||||||
// /// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
// /// <param name="bodyKit">Признак наличия обвеса</param>
|
|
||||||
// /// <param name="trunk">Признак наличия антикрыла</param>
|
|
||||||
// /// <param name="sportLine">Признак наличия гоночной полосы</param>
|
|
||||||
// /// <param name="width">Ширина картинки</param>
|
|
||||||
// /// <param name="height">Высота картинки</param>
|
|
||||||
// /// <returns>true - объект создан, false - проверка не пройдена,
|
|
||||||
// /// нельзя создать объект в этих размерах</returns>
|
|
||||||
// public bool Init(int speed, double weight, Color bodyColor, Color
|
|
||||||
//additionalColor, bool bodyKit, bool trunk, bool sportLine, int width, int height)
|
|
||||||
//{
|
|
||||||
// // TODO: Продумать проверки
|
|
||||||
// if (width > _tankWidth && height > _tankHeight && speed > 0 && weight > 0)
|
|
||||||
// {
|
|
||||||
// _pictureWidth = width;
|
|
||||||
// _pictureHeight = height;
|
|
||||||
// EntityTank = new EntityTank();
|
|
||||||
// EntityTank.Init(speed, weight, bodyColor, additionalColor,
|
|
||||||
// bodyKit, trunk, sportLine);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
//}
|
|
||||||
///// <summary>
|
|
||||||
|
|
||||||
/// Прорисовка объекта
|
|
||||||
/// <param name="g"></param>
|
|
||||||
//public void DrawTransport(Graphics g)
|
|
||||||
//{
|
|
||||||
// if (EntityTank == null)
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
|
// багажник
|
||||||
|
if (ArmoredCar.Trunk) // Tank
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX + 23, _startPosY + 4, 8, 10);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 23, _startPosY + 4, 8, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
6
Tank/Tank/FormTank.Designer.cs
generated
6
Tank/Tank/FormTank.Designer.cs
generated
@ -129,10 +129,8 @@
|
|||||||
//
|
//
|
||||||
this.comboBoxStrategy.FormattingEnabled = true;
|
this.comboBoxStrategy.FormattingEnabled = true;
|
||||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||||
"1",
|
"0",
|
||||||
"2",
|
"1"});
|
||||||
"3",
|
|
||||||
"4"});
|
|
||||||
this.comboBoxStrategy.Location = new System.Drawing.Point(725, 45);
|
this.comboBoxStrategy.Location = new System.Drawing.Point(725, 45);
|
||||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
|
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
|
||||||
|
@ -119,9 +119,9 @@ namespace Tank
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_abstractStrategy.SetData(new
|
_abstractStrategy.SetData(new
|
||||||
DrawningObjectArmoredCar(_Tank), pictureBoxTank.Width,
|
DrawingObjectArmoredCar(_Tank), pictureBoxTank.Width,
|
||||||
pictureBoxTank.Height);
|
pictureBoxTank.Height);
|
||||||
comboBoxStrategy.Enabled = false;
|
// comboBoxStrategy.Enabled = false;
|
||||||
}
|
}
|
||||||
if (_abstractStrategy == null)
|
if (_abstractStrategy == null)
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ namespace Tank.MovementStrategy
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение координаты X объекта
|
/// Получение координаты X объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ObjectParameters? GetObjectPosition { get; }
|
ObjectParameters? GetObjectParameters { get; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг объекта
|
/// Шаг объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -6,19 +6,20 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Tank.MovementStrategy
|
namespace Tank.MovementStrategy
|
||||||
{
|
{
|
||||||
/// Стратегия перемещения объекта в центр экрана
|
|
||||||
public class MoveToBorder : AbstractStrategy
|
public class MoveToBorder : AbstractStrategy
|
||||||
{
|
{
|
||||||
protected override bool IsTargetDestinaion()
|
protected override bool IsTargetDestination()
|
||||||
{
|
{
|
||||||
var objParams = GetObjectParameters;
|
var 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.DownBorder + GetStep() >= FieldHeight &&
|
||||||
|
objParams.RightBorder <= FieldWidth &&
|
||||||
|
objParams.DownBorder <= FieldHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void MoveToTarget()
|
protected override void MoveToTarget()
|
||||||
{
|
{
|
||||||
var objParams = GetObjectParameters;
|
var objParams = GetObjectParameters;
|
||||||
@ -27,27 +28,45 @@ namespace Tank.MovementStrategy
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var diffX = objParams.RightBorder - FieldWidth;
|
var diffX = objParams.RightBorder - FieldWidth;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
var diffY = objParams.DownBorder - FieldHeight;
|
|
||||||
if (Math.Abs(diffY) > GetStep())
|
|
||||||
{
|
{
|
||||||
if (diffX > 0)
|
if (diffX > 0)
|
||||||
{
|
{
|
||||||
MoveDown();
|
MoveLeft();
|
||||||
}
|
}
|
||||||
else if (diffY > 0)
|
else
|
||||||
{
|
{
|
||||||
MoveRight();
|
MoveRight();
|
||||||
}
|
}
|
||||||
else if (Math.Abs(diffX) > Math.Abs(diffY))
|
}
|
||||||
|
var diffY = objParams.DownBorder - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
{
|
{
|
||||||
MoveRight();
|
MoveUp();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MoveDown();
|
MoveDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//if (diffX >= 0)
|
||||||
|
//{
|
||||||
|
// MoveDown();
|
||||||
|
//}
|
||||||
|
//else if (diffY >= 0)
|
||||||
|
//{
|
||||||
|
// MoveRight();
|
||||||
|
//}
|
||||||
|
//else if (Math.Abs(diffX) > Math.Abs(diffY))
|
||||||
|
//{
|
||||||
|
// MoveRight();
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// MoveDown();
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,19 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Tank.MovementStrategy
|
namespace Tank.MovementStrategy
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Стратегия перемещения объекта в центр экрана
|
|
||||||
|
|
||||||
public class MoveToCenter : AbstractStrategy
|
public class MoveToCenter : AbstractStrategy
|
||||||
{
|
{
|
||||||
protected override bool IsTargetDestinaion()
|
protected override bool IsTargetDestination()
|
||||||
{
|
{
|
||||||
var objParams = GetObjectParameters;
|
var objParams = GetObjectParameters;
|
||||||
if (objParams == null)
|
if (objParams == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||||
}
|
}
|
||||||
protected override void MoveToTarget()
|
protected override void MoveToTarget()
|
||||||
{
|
{
|
||||||
@ -30,7 +27,7 @@ namespace Tank.MovementStrategy
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
if (Math.Abs(diffX) > GetStep())
|
if (Math.Abs(diffX) > GetStep())
|
||||||
{
|
{
|
||||||
if (diffX > 0)
|
if (diffX > 0)
|
||||||
@ -56,4 +53,4 @@ namespace Tank.MovementStrategy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user