Compare commits
4 Commits
0b3396d17f
...
35ef737015
Author | SHA1 | Date | |
---|---|---|---|
|
35ef737015 | ||
|
7293c69407 | ||
|
083ffec901 | ||
|
a52eb31b45 |
@ -6,27 +6,12 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Tank
|
namespace Tank
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
/// </summary>
|
|
||||||
public enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Вверх
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
Up = 1,
|
Up = 1,
|
||||||
/// <summary>
|
|
||||||
/// Вниз
|
|
||||||
/// </summary>
|
|
||||||
Down = 2,
|
Down = 2,
|
||||||
/// <summary>
|
|
||||||
/// Влево
|
|
||||||
/// </summary>
|
|
||||||
Left = 3,
|
Left = 3,
|
||||||
/// <summary>
|
|
||||||
/// Вправо
|
|
||||||
/// </summary>
|
|
||||||
Right = 4
|
Right = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,6 +220,24 @@ namespace Tank.DrawingObjects
|
|||||||
Brush br = new SolidBrush(EntityArmoredCar.BodyColor);
|
Brush br = new SolidBrush(EntityArmoredCar.BodyColor);
|
||||||
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
|
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
|
||||||
|
|
||||||
|
|
||||||
|
// не мое
|
||||||
|
Brush BrushRandom = new SolidBrush(EntityArmoredCar?.BodyColor ?? Color.Black);
|
||||||
|
|
||||||
|
|
||||||
|
// Корпус
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,11 @@ using Tank.DrawingObjects;
|
|||||||
|
|
||||||
namespace Tank.MovementStrategy
|
namespace Tank.MovementStrategy
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
|
||||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar
|
public class DrawningObjectArmoredCar : IMoveableObject
|
||||||
/// (паттерн Adapter)
|
|
||||||
/// </summary>
|
|
||||||
public class DrawningObjectCar : IMoveableObject
|
|
||||||
{
|
{
|
||||||
private readonly DrawningArmoredCar? _drawningArmoredCar = null;
|
private readonly DrawingArmoredCar? _drawningArmoredCar = null;
|
||||||
public DrawningObjectCar(DrawningArmoredCar drawningArmoredCar)
|
public DrawningObjectArmoredCar(DrawingArmoredCar drawningArmoredCar)
|
||||||
{
|
{
|
||||||
_drawningArmoredCar = drawningArmoredCar;
|
_drawningArmoredCar = drawningArmoredCar;
|
||||||
}
|
}
|
||||||
@ -31,7 +28,7 @@ namespace Tank.MovementStrategy
|
|||||||
_drawningArmoredCar.GetPosY, _drawningArmoredCar.GetWidth, _drawningArmoredCar.GetHeight);
|
_drawningArmoredCar.GetPosY, _drawningArmoredCar.GetWidth, _drawningArmoredCar.GetHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int GetStep => (int)(_drawningArmoredCar?.EntityCar?.Step ?? 0);
|
public int GetStep => (int)(_drawningArmoredCar?.EntityArmoredCar?.Step ?? 0);
|
||||||
public bool CheckCanMove(Direction direction) =>
|
public bool CheckCanMove(Direction direction) =>
|
||||||
_drawningArmoredCar?.CanMove(direction) ?? false;
|
_drawningArmoredCar?.CanMove(direction) ?? false;
|
||||||
public void MoveObject(Direction direction) =>
|
public void MoveObject(Direction direction) =>
|
||||||
|
@ -4,19 +4,14 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Tank.DrawingObjects;
|
|
||||||
using Tank.Entites;
|
using Tank.Entites;
|
||||||
|
|
||||||
namespace Tank.DrawingObjects
|
namespace Tank.DrawingObjects
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
/// </summary>
|
public class DrawingTank : DrawingArmoredCar
|
||||||
public class DrawningTank : DrawingArmoredCar
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес</param>
|
/// <param name="weight">Вес</param>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
@ -26,34 +21,114 @@ namespace Tank.DrawingObjects
|
|||||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||||
/// <param name="width">Ширина картинки</param>
|
/// <param name="width">Ширина картинки</param>
|
||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
public DrawningTank(int speed, double weight, Color bodyColor, Color
|
public DrawingTank(int speed, double weight, Color bodyColor, Color
|
||||||
additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) :
|
additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) :
|
||||||
base(speed, weight, bodyColor, width, height, 110, 60)
|
base(speed, weight, bodyColor, width, height, 110, 60)
|
||||||
{
|
{
|
||||||
if (EntityArmoredCar != null)
|
if (Tank != null)
|
||||||
{
|
{
|
||||||
EntityArmoredCar = new EntityTank(speed, weight, bodyColor,
|
Tank = new EntityTank(speed, weight, bodyColor,
|
||||||
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 (EntityArmoredCar is not EntityTank sportCar)
|
if (Tank is not EntityTank ArmoredCar)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// base.DrawTransport(g);
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush additionalBrush = new
|
Brush additionalBrush = new
|
||||||
SolidBrush(sportCar.AdditionalColor);
|
SolidBrush(ArmoredCar.AdditionalColor);
|
||||||
// обвесы
|
// гусеница
|
||||||
|
Rectangle Caterpillar = new Rectangle(_startPosX + 2, _startPosY + 35, 16, 22);
|
||||||
|
float startAngle_Caterpillar = 90;
|
||||||
|
float sweepAngle_Caterpillar = 180;
|
||||||
|
g.DrawArc(pen, Caterpillar, startAngle_Caterpillar, sweepAngle_Caterpillar);
|
||||||
|
Rectangle Caterpillar2 = new Rectangle(_startPosX + 102, _startPosY + 35, 16, 22);
|
||||||
|
float startAngle_Caterpillar2 = 270;
|
||||||
|
float sweepAngle_Caterpillar2 = 180;
|
||||||
|
g.DrawArc(pen, Caterpillar2, startAngle_Caterpillar2, sweepAngle_Caterpillar2);
|
||||||
|
Point startPoint = new Point(_startPosX + 10, _startPosY + 58);
|
||||||
|
Point endPoint = new Point(_startPosX + 110, _startPosY + 58);
|
||||||
|
g.DrawLine(pen, startPoint, endPoint);
|
||||||
|
// колеса
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 95, _startPosY + 35, 20, 20);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 35, 20, 20);
|
||||||
|
// колеса снизу поменьше
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 47, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 47, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 47, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 47, 10, 10);
|
||||||
|
// колеса сверху
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 32, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 55, _startPosY + 32, 10, 10);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 75, _startPosY + 32, 10, 10);
|
||||||
|
|
||||||
|
//кузов
|
||||||
|
Brush br = new SolidBrush(ArmoredCar.BodyColor);
|
||||||
|
g.FillRectangle(br, _startPosX + 5, _startPosY + 17, 110, 18);
|
||||||
|
g.FillRectangle(br, _startPosX + 30, _startPosY, 50, 15);
|
||||||
|
|
||||||
// багажник
|
// // пулемет
|
||||||
if (EntityArmoredCar.Trunk)
|
// g.FillRectangle(br, _startPosX + 80, _startPosY + 3, 25, 5);
|
||||||
{
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 23, _startPosY + 4, 8, 10);
|
// // зенитный пулемет на башне
|
||||||
g.DrawRectangle(pen, _startPosX + 23, _startPosY + 4, 8, 10);
|
// g.FillRectangle(br, _startPosX + 40, _startPosY - 10, 20, 5);
|
||||||
}
|
|
||||||
|
// g.FillRectangle(brBlack, _startPosX + 50, _startPosY - 5, 5, 5);
|
||||||
|
// g.FillRectangle(brBlack, _startPosX + 55, _startPosY - 10, 5, 10);
|
||||||
|
// g.FillRectangle(brBlack, _startPosX + 52, _startPosY - 7, 3, 2);
|
||||||
|
|
||||||
|
// //выделяем рамкой весь танк
|
||||||
|
// g.DrawRectangle(pen, _startPosX + 5, _startPosY + 17, 110, 18);
|
||||||
|
// g.DrawRectangle(pen, _startPosX + 30, _startPosY, 50, 15);
|
||||||
|
// g.DrawRectangle(pen, _startPosX + 80, _startPosY + 3, 25, 5);
|
||||||
|
// g.DrawRectangle(pen, _startPosX + 40, _startPosY - 10, 20, 5);
|
||||||
|
|
||||||
|
//// обвесы
|
||||||
|
//if (Tank.BodyKit) // entityTank
|
||||||
|
//{
|
||||||
|
// Brush brAdd = new SolidBrush(EntityTank.AdditionalColor);
|
||||||
|
|
||||||
|
// g.FillRectangle(brAdd, _startPosX + 5, _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 + 95, _startPosY + 17, 20, 18);
|
||||||
|
|
||||||
|
// g.FillRectangle(brAdd, _startPosX + 100, _startPosY + 4, 5, 4);
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
//// спортивная линия
|
||||||
|
//if (Tank.SportLine)
|
||||||
|
//{
|
||||||
|
// g.FillRectangle(additionalBrush, _startPosX + 75,
|
||||||
|
// _startPosY + 23, 25, 15);
|
||||||
|
// g.FillRectangle(additionalBrush, _startPosX + 35,
|
||||||
|
// _startPosY + 23, 35, 15);
|
||||||
|
// g.FillRectangle(additionalBrush, _startPosX + 10,
|
||||||
|
// _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>
|
||||||
@ -86,65 +161,8 @@ namespace Tank.DrawingObjects
|
|||||||
// return false;
|
// return false;
|
||||||
//}
|
//}
|
||||||
///// <summary>
|
///// <summary>
|
||||||
///// Установка позиции
|
|
||||||
///// </summary>
|
|
||||||
///// <param name="x">Координата X</param>
|
|
||||||
///// <param name="y">Координата Y</param>
|
|
||||||
//public void SetPosition(int x, int y)
|
|
||||||
//{
|
|
||||||
// // проверки
|
|
||||||
// if (x >= 0 && x + _tankWidth <= _pictureWidth &&
|
|
||||||
// y >= 0 && y + _tankHeight <= _pictureHeight)
|
|
||||||
// {
|
|
||||||
// _startPosX = x;
|
|
||||||
// _startPosY = y;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
///// <summary>
|
|
||||||
///// Изменение направления перемещения
|
|
||||||
///// </summary>
|
|
||||||
///// <param name="direction">Направление</param>
|
|
||||||
//public void MoveTransport(Direction direction)
|
|
||||||
//{
|
|
||||||
// if (EntityTank == null)
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// switch (direction)
|
|
||||||
// {
|
|
||||||
// //влево
|
|
||||||
// case Direction.Left:
|
|
||||||
// if (_startPosX - EntityTank.Step > 0)
|
|
||||||
// {
|
|
||||||
// _startPosX -= (int)EntityTank.Step;
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// //вверх
|
|
||||||
// case Direction.Up:
|
|
||||||
// if (_startPosY - EntityTank.Step > 0)
|
|
||||||
// {
|
|
||||||
// _startPosY -= (int)EntityTank.Step;
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// // вправо
|
|
||||||
// case Direction.Right:
|
|
||||||
// if (_startPosX + EntityTank.Step + _tankWidth < _pictureWidth)
|
|
||||||
// {
|
|
||||||
// _startPosX += (int)EntityTank.Step;
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// //вниз
|
|
||||||
// case Direction.Down:
|
|
||||||
// if (_startPosY + EntityTank.Step + _tankHeight < _pictureHeight)
|
|
||||||
// {
|
|
||||||
// _startPosY += (int)EntityTank.Step;
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
/// <summary>
|
|
||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
//public void DrawTransport(Graphics g)
|
//public void DrawTransport(Graphics g)
|
||||||
//{
|
//{
|
||||||
@ -152,86 +170,8 @@ namespace Tank.DrawingObjects
|
|||||||
// {
|
// {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// Pen pen = new(Color.Black);
|
//
|
||||||
// Brush additionalBrush = new
|
|
||||||
// SolidBrush(EntityTank.AdditionalColor);
|
|
||||||
// // гусеница
|
|
||||||
// Rectangle Caterpillar = new Rectangle(_startPosX + 2, _startPosY + 35, 16, 22);
|
|
||||||
// float startAngle_Caterpillar = 90;
|
|
||||||
// float sweepAngle_Caterpillar = 180;
|
|
||||||
// g.DrawArc(pen, Caterpillar, startAngle_Caterpillar, sweepAngle_Caterpillar);
|
|
||||||
// Rectangle Caterpillar2 = new Rectangle(_startPosX + 102, _startPosY + 35, 16, 22);
|
|
||||||
// float startAngle_Caterpillar2 = 270;
|
|
||||||
// float sweepAngle_Caterpillar2 = 180;
|
|
||||||
// g.DrawArc(pen, Caterpillar2, startAngle_Caterpillar2, sweepAngle_Caterpillar2);
|
|
||||||
// Point startPoint = new Point(_startPosX + 10, _startPosY + 58);
|
|
||||||
// Point endPoint = new Point(_startPosX + 110, _startPosY + 58);
|
|
||||||
// g.DrawLine(pen, startPoint, endPoint);
|
|
||||||
// // колеса
|
|
||||||
// Brush brBlack = new SolidBrush(Color.Black);
|
|
||||||
// g.FillEllipse(brBlack, _startPosX + 95, _startPosY + 35, 20, 20);
|
|
||||||
// g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 35, 20, 20);
|
|
||||||
// // колеса снизу поменьше
|
|
||||||
// g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 47, 10, 10);
|
|
||||||
// g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 47, 10, 10);
|
|
||||||
// g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 47, 10, 10);
|
|
||||||
// g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 47, 10, 10);
|
|
||||||
// // колеса сверху
|
|
||||||
// g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 32, 10, 10);
|
|
||||||
// g.FillEllipse(brBlack, _startPosX + 55, _startPosY + 32, 10, 10);
|
|
||||||
// g.FillEllipse(brBlack, _startPosX + 75, _startPosY + 32, 10, 10);
|
|
||||||
|
|
||||||
// //кузов
|
|
||||||
// Brush br = new SolidBrush(EntityTank.BodyColor);
|
|
||||||
// g.FillRectangle(br, _startPosX + 5, _startPosY + 17, 110, 18);
|
|
||||||
// g.FillRectangle(br, _startPosX + 30, _startPosY, 50, 15);
|
|
||||||
|
|
||||||
// // пулемет
|
|
||||||
// g.FillRectangle(br, _startPosX + 80, _startPosY + 3, 25, 5);
|
|
||||||
|
|
||||||
// // зенитный пулемет на башне
|
|
||||||
// g.FillRectangle(br, _startPosX + 40, _startPosY - 10, 20, 5);
|
|
||||||
|
|
||||||
// g.FillRectangle(brBlack, _startPosX + 50, _startPosY - 5, 5, 5);
|
|
||||||
// g.FillRectangle(brBlack, _startPosX + 55, _startPosY - 10, 5, 10);
|
|
||||||
// g.FillRectangle(brBlack, _startPosX + 52, _startPosY - 7, 3, 2);
|
|
||||||
|
|
||||||
// //выделяем рамкой весь танк
|
|
||||||
// g.DrawRectangle(pen, _startPosX + 5, _startPosY + 17, 110, 18);
|
|
||||||
// g.DrawRectangle(pen, _startPosX + 30, _startPosY, 50, 15);
|
|
||||||
// g.DrawRectangle(pen, _startPosX + 80, _startPosY + 3, 25, 5);
|
|
||||||
// g.DrawRectangle(pen, _startPosX + 40, _startPosY - 10, 20, 5);
|
|
||||||
|
|
||||||
// // обвесы
|
|
||||||
// if (EntityTank.BodyKit)
|
|
||||||
// {
|
|
||||||
// Brush brAdd = new SolidBrush(EntityTank.AdditionalColor);
|
|
||||||
|
|
||||||
// g.FillRectangle(brAdd, _startPosX + 5, _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 + 95, _startPosY + 17, 20, 18);
|
|
||||||
|
|
||||||
// g.FillRectangle(brAdd, _startPosX + 100, _startPosY + 4, 5, 4);
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //// спортивная линия
|
|
||||||
// //if (EntityTank.SportLine)
|
|
||||||
// //{
|
|
||||||
// // g.FillRectangle(additionalBrush, _startPosX + 75,
|
|
||||||
// // _startPosY + 23, 25, 15);
|
|
||||||
// // g.FillRectangle(additionalBrush, _startPosX + 35,
|
|
||||||
// // _startPosY + 23, 35, 15);
|
|
||||||
// // g.FillRectangle(additionalBrush, _startPosX + 10,
|
|
||||||
// // _startPosY + 23, 20, 15);
|
|
||||||
// //}
|
|
||||||
// // багажник
|
|
||||||
// if (EntityTank.Trunk)
|
|
||||||
// {
|
|
||||||
// g.FillRectangle(additionalBrush, _startPosX + 23, _startPosY + 4, 8, 10);
|
|
||||||
// g.DrawRectangle(pen, _startPosX + 23, _startPosY + 4 , 8, 10);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,5 +40,6 @@ namespace Tank.Entites
|
|||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,41 +9,23 @@ namespace Tank.Entites
|
|||||||
{
|
{
|
||||||
public class EntityTank : EntityArmoredCar
|
public class EntityTank : EntityArmoredCar
|
||||||
{
|
{
|
||||||
///// <summary>
|
/// Скорость
|
||||||
///// Скорость
|
public int Speed { get; private set; }
|
||||||
///// </summary>
|
/// Вес
|
||||||
//public int Speed { get; private set; }
|
// public double Weight { get; private set; }
|
||||||
///// <summary>
|
/// Основной цвет
|
||||||
///// Вес
|
// public Color BodyColor { get; private set; }
|
||||||
///// </summary>
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
//public double Weight { get; private set; }
|
|
||||||
///// <summary>
|
|
||||||
///// Основной цвет
|
|
||||||
///// </summary>
|
|
||||||
//public Color BodyColor { get; private set; }
|
|
||||||
///// <summary>
|
|
||||||
///// Дополнительный цвет (для опциональных элементов)
|
|
||||||
///// </summary>
|
|
||||||
public Color AdditionalColor { get; private set; }
|
public Color AdditionalColor { get; private set; }
|
||||||
/// <summary>
|
// Признак (опция) наличия обвеса
|
||||||
/// Признак (опция) наличия обвеса
|
|
||||||
/// </summary>
|
|
||||||
public bool BodyKit { get; private set; }
|
public bool BodyKit { get; private set; }
|
||||||
/// <summary>
|
// Признак (опция) наличия Багажника
|
||||||
/// Признак (опция) наличия Багажника
|
|
||||||
/// </summary>
|
|
||||||
public bool Trunk { get; private set; }
|
public bool Trunk { get; private set; }
|
||||||
/// <summary>
|
// Признак (опция) наличия гоночной полосы
|
||||||
/// Признак (опция) наличия гоночной полосы
|
|
||||||
/// </summary>
|
|
||||||
public bool SportLine { get; private set; }
|
public bool SportLine { get; private set; }
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения танка
|
/// Шаг перемещения танка
|
||||||
/// </summary>
|
|
||||||
// public double Step => (double)Speed * 200 / Weight;
|
// public double Step => (double)Speed * 200 / Weight;
|
||||||
/// <summary>
|
|
||||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес Танка</param>
|
/// <param name="weight">Вес Танка</param>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
@ -52,11 +34,8 @@ namespace Tank.Entites
|
|||||||
/// <param name="trunk">Признак наличия багажника</param>
|
/// <param name="trunk">Признак наличия багажника</param>
|
||||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||||
public EntityTank(int speed, double weight, Color bodyColor, Color
|
public EntityTank(int speed, double weight, Color bodyColor, Color
|
||||||
additionalColor, bool bodyKit, bool trunk, bool sportLine)
|
additionalColor, bool bodyKit, bool trunk, bool sportLine) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
BodyKit = bodyKit;
|
BodyKit = bodyKit;
|
||||||
Trunk = trunk;
|
Trunk = trunk;
|
||||||
|
21
Tank/Tank/FormTank.Designer.cs
generated
21
Tank/Tank/FormTank.Designer.cs
generated
@ -36,6 +36,7 @@
|
|||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonCreateArmoredCar = new System.Windows.Forms.Button();
|
this.buttonCreateArmoredCar = new System.Windows.Forms.Button();
|
||||||
this.buttonStep = new System.Windows.Forms.Button();
|
this.buttonStep = new System.Windows.Forms.Button();
|
||||||
|
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTank)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTank)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -116,18 +117,33 @@
|
|||||||
//
|
//
|
||||||
// buttonStep
|
// buttonStep
|
||||||
//
|
//
|
||||||
this.buttonStep.Location = new System.Drawing.Point(682, 48);
|
this.buttonStep.Location = new System.Drawing.Point(752, 74);
|
||||||
this.buttonStep.Name = "buttonStep";
|
this.buttonStep.Name = "buttonStep";
|
||||||
this.buttonStep.Size = new System.Drawing.Size(75, 23);
|
this.buttonStep.Size = new System.Drawing.Size(75, 23);
|
||||||
this.buttonStep.TabIndex = 9;
|
this.buttonStep.TabIndex = 9;
|
||||||
this.buttonStep.Text = "buttonStep";
|
this.buttonStep.Text = "Шаг";
|
||||||
this.buttonStep.UseVisualStyleBackColor = true;
|
this.buttonStep.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
this.comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4"});
|
||||||
|
this.comboBoxStrategy.Location = new System.Drawing.Point(725, 45);
|
||||||
|
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
|
||||||
|
this.comboBoxStrategy.TabIndex = 10;
|
||||||
//
|
//
|
||||||
// FormTank
|
// FormTank
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||||
|
this.Controls.Add(this.comboBoxStrategy);
|
||||||
this.Controls.Add(this.buttonStep);
|
this.Controls.Add(this.buttonStep);
|
||||||
this.Controls.Add(this.buttonCreateArmoredCar);
|
this.Controls.Add(this.buttonCreateArmoredCar);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
@ -156,5 +172,6 @@
|
|||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonCreateArmoredCar;
|
private Button buttonCreateArmoredCar;
|
||||||
private Button buttonStep;
|
private Button buttonStep;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,36 +8,27 @@ namespace Tank
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class FormTank : Form
|
public partial class FormTank : Form
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||||
/// </summary>
|
// private DrawningArmoredCar? _drawningArmoredCar;
|
||||||
//private DrawningArmoredCar? _drawningArmoredCar;
|
private DrawingArmoredCar? _Tank;
|
||||||
private DrawningTank? _drawningTank;
|
|
||||||
/// <summary>
|
|
||||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||||
/// </summary>
|
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||||
/// </summary>
|
|
||||||
public FormTank()
|
public FormTank()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||||
/// </summary>
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningTank == null) // _drawingArmoredCar
|
if (_Tank == null) // _drawingArmoredCar
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxTank.Width,
|
Bitmap bmp = new(pictureBoxTank.Width,
|
||||||
pictureBoxTank.Height);
|
pictureBoxTank.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningTank.DrawTransport(gr);
|
_Tank.DrawTransport(gr);
|
||||||
pictureBoxTank.Image = bmp;
|
pictureBoxTank.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -59,30 +50,21 @@ namespace Tank
|
|||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawningArmoredCar = new DrawningTank(random.Next(100, 300),
|
_Tank = new DrawingTank(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
random.Next(1000, 3000);
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
_drawningTank.Init(random.Next(100, 300),
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
random.Next(1000, 3000),
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
|
||||||
random.Next(0, 256)),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
|
||||||
random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
Convert.ToBoolean(random.Next(0, 2)),
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
|
||||||
|
|
||||||
pictureBoxTank.Width, pictureBoxTank.Height);
|
pictureBoxTank.Width, pictureBoxTank.Height);
|
||||||
_drawningTank.SetPosition(random.Next(10, 100),
|
_Tank.SetPosition(random.Next(10, 100),
|
||||||
random.Next(10, 100));
|
random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningTank == null)
|
if (_Tank == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -90,16 +72,16 @@ random.Next(1000, 3000);
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
_drawningTank.MoveTransport(Direction.Up);
|
_Tank.MoveTransport(Direction.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
_drawningTank.MoveTransport(Direction.Down);
|
_Tank.MoveTransport(Direction.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
_drawningTank.MoveTransport(Direction.Left);
|
_Tank.MoveTransport(Direction.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
_drawningTank.MoveTransport(Direction.Right);
|
_Tank.MoveTransport(Direction.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
@ -109,18 +91,49 @@ random.Next(1000, 3000);
|
|||||||
private void buttonCreateArmoredCar_Click(object sender, EventArgs e)
|
private void buttonCreateArmoredCar_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawningArmoredCar = new DrawningArmoredCar(random.Next(100, 300),
|
_Tank = new DrawingArmoredCar(random.Next(100,300), random.Next(1000,3000),
|
||||||
random.Next(1000, 3000),
|
Color.FromArgb(random.Next(0,256), random.Next(0,256), random.Next(0,256)),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
pictureBoxTank.Width, pictureBoxTank.Height);
|
||||||
random.Next(0, 256)),
|
|
||||||
pictureBoxTank.Width, pictureBoxTank.Height);
|
_Tank.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
_drawningArmoredCar.SetPosition(random.Next(10, 100), random.Next(10,
|
|
||||||
100));
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button1_Click(object sender, EventArgs e)
|
private void buttonStep_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (_Tank == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||||
|
switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(new
|
||||||
|
DrawningObjectArmoredCar(_Tank), pictureBoxTank.Width,
|
||||||
|
pictureBoxTank.Height);
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
53
Tank/Tank/MoveToBorder.cs
Normal file
53
Tank/Tank/MoveToBorder.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Tank.MovementStrategy
|
||||||
|
{
|
||||||
|
/// Стратегия перемещения объекта в центр экрана
|
||||||
|
public class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.RightBorder - FieldWidth;
|
||||||
|
|
||||||
|
var diffY = objParams.DownBorder - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
else if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
else if (Math.Abs(diffX) > Math.Abs(diffY))
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@ namespace Tank.MovementStrategy
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Стратегия перемещения объекта в центр экрана
|
/// Стратегия перемещения объекта в центр экрана
|
||||||
/// </summary>
|
|
||||||
public class MoveToCenter : AbstractStrategy
|
public class MoveToCenter : AbstractStrategy
|
||||||
{
|
{
|
||||||
protected override bool IsTargetDestinaion()
|
protected override bool IsTargetDestinaion()
|
||||||
|
@ -6,9 +6,6 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Tank.MovementStrategy
|
namespace Tank.MovementStrategy
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Статус выполнения операции перемещения
|
|
||||||
/// </summary>
|
|
||||||
public enum Status
|
public enum Status
|
||||||
{
|
{
|
||||||
NotInit,
|
NotInit,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user