Compare commits
4 Commits
0b3396d17f
...
35ef737015
Author | SHA1 | Date | |
---|---|---|---|
|
35ef737015 | ||
|
7293c69407 | ||
|
083ffec901 | ||
|
a52eb31b45 |
@ -6,27 +6,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Tank
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum Direction
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
///
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
}
|
||||
|
@ -220,6 +220,24 @@ namespace Tank.DrawingObjects
|
||||
Brush br = new SolidBrush(EntityArmoredCar.BodyColor);
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar
|
||||
/// (паттерн Adapter)
|
||||
/// </summary>
|
||||
public class DrawningObjectCar : IMoveableObject
|
||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
|
||||
public class DrawningObjectArmoredCar : IMoveableObject
|
||||
{
|
||||
private readonly DrawningArmoredCar? _drawningArmoredCar = null;
|
||||
public DrawningObjectCar(DrawningArmoredCar drawningArmoredCar)
|
||||
private readonly DrawingArmoredCar? _drawningArmoredCar = null;
|
||||
public DrawningObjectArmoredCar(DrawingArmoredCar drawningArmoredCar)
|
||||
{
|
||||
_drawningArmoredCar = drawningArmoredCar;
|
||||
}
|
||||
@ -31,7 +28,7 @@ namespace Tank.MovementStrategy
|
||||
_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) =>
|
||||
_drawningArmoredCar?.CanMove(direction) ?? false;
|
||||
public void MoveObject(Direction direction) =>
|
||||
|
@ -4,19 +4,14 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tank.DrawingObjects;
|
||||
using Tank.Entites;
|
||||
|
||||
namespace Tank.DrawingObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningTank : DrawingArmoredCar
|
||||
public class DrawingTank : DrawingArmoredCar
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
@ -26,34 +21,114 @@ namespace Tank.DrawingObjects
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
/// <param name="width">Ширина картинки</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) :
|
||||
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);
|
||||
}
|
||||
}
|
||||
///// Установка позиции
|
||||
//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)
|
||||
{
|
||||
if (EntityArmoredCar is not EntityTank sportCar)
|
||||
if (Tank is not EntityTank ArmoredCar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// base.DrawTransport(g);
|
||||
Pen pen = new(Color.Black);
|
||||
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(additionalBrush, _startPosX + 23, _startPosY + 4, 8, 10);
|
||||
g.DrawRectangle(pen, _startPosX + 23, _startPosY + 4, 8, 10);
|
||||
}
|
||||
// // пулемет
|
||||
// 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 (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>
|
||||
@ -86,65 +161,8 @@ namespace Tank.DrawingObjects
|
||||
// return false;
|
||||
//}
|
||||
///// <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>
|
||||
//public void DrawTransport(Graphics g)
|
||||
//{
|
||||
@ -152,86 +170,8 @@ namespace Tank.DrawingObjects
|
||||
// {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -9,41 +9,23 @@ namespace Tank.Entites
|
||||
{
|
||||
public class EntityTank : EntityArmoredCar
|
||||
{
|
||||
///// <summary>
|
||||
///// Скорость
|
||||
///// </summary>
|
||||
//public int Speed { get; private set; }
|
||||
///// <summary>
|
||||
///// Вес
|
||||
///// </summary>
|
||||
//public double Weight { get; private set; }
|
||||
///// <summary>
|
||||
///// Основной цвет
|
||||
///// </summary>
|
||||
//public Color BodyColor { get; private set; }
|
||||
///// <summary>
|
||||
///// Дополнительный цвет (для опциональных элементов)
|
||||
///// </summary>
|
||||
/// Скорость
|
||||
public int Speed { get; private set; }
|
||||
/// Вес
|
||||
// public double Weight { get; private set; }
|
||||
/// Основной цвет
|
||||
// public Color BodyColor { get; private set; }
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
// Признак (опция) наличия обвеса
|
||||
public bool BodyKit { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия Багажника
|
||||
/// </summary>
|
||||
// Признак (опция) наличия Багажника
|
||||
public bool Trunk { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
// Признак (опция) наличия гоночной полосы
|
||||
public bool SportLine { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения танка
|
||||
/// </summary>
|
||||
// public double Step => (double)Speed * 200 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес Танка</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
@ -52,11 +34,8 @@ namespace Tank.Entites
|
||||
/// <param name="trunk">Признак наличия багажника</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
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;
|
||||
BodyKit = bodyKit;
|
||||
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.buttonCreateArmoredCar = 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();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -116,18 +117,33 @@
|
||||
//
|
||||
// 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.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonStep.TabIndex = 9;
|
||||
this.buttonStep.Text = "buttonStep";
|
||||
this.buttonStep.Text = "Шаг";
|
||||
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
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.buttonCreateArmoredCar);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
@ -156,5 +172,6 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateArmoredCar;
|
||||
private Button buttonStep;
|
||||
private ComboBox comboBoxStrategy;
|
||||
}
|
||||
}
|
@ -8,36 +8,27 @@ namespace Tank
|
||||
/// </summary>
|
||||
public partial class FormTank : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
//private DrawningArmoredCar? _drawningArmoredCar;
|
||||
private DrawningTank? _drawningTank;
|
||||
/// <summary>
|
||||
// private DrawningArmoredCar? _drawningArmoredCar;
|
||||
private DrawingArmoredCar? _Tank;
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
/// </summary>
|
||||
public FormTank()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningTank == null) // _drawingArmoredCar
|
||||
if (_Tank == null) // _drawingArmoredCar
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxTank.Width,
|
||||
pictureBoxTank.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningTank.DrawTransport(gr);
|
||||
_Tank.DrawTransport(gr);
|
||||
pictureBoxTank.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
@ -59,30 +50,21 @@ namespace Tank
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningArmoredCar = new DrawningTank(random.Next(100, 300),
|
||||
random.Next(1000, 3000);
|
||||
_drawningTank.Init(random.Next(100, 300),
|
||||
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),
|
||||
random.Next(0, 256)),
|
||||
_Tank = new DrawingTank(random.Next(100, 300), 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), 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)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
|
||||
pictureBoxTank.Width, pictureBoxTank.Height);
|
||||
_drawningTank.SetPosition(random.Next(10, 100),
|
||||
_Tank.SetPosition(random.Next(10, 100),
|
||||
random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningTank == null)
|
||||
if (_Tank == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -90,16 +72,16 @@ random.Next(1000, 3000);
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningTank.MoveTransport(Direction.Up);
|
||||
_Tank.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningTank.MoveTransport(Direction.Down);
|
||||
_Tank.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningTank.MoveTransport(Direction.Left);
|
||||
_Tank.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningTank.MoveTransport(Direction.Right);
|
||||
_Tank.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
@ -109,18 +91,49 @@ random.Next(1000, 3000);
|
||||
private void buttonCreateArmoredCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningArmoredCar = new DrawningArmoredCar(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
pictureBoxTank.Width, pictureBoxTank.Height);
|
||||
_drawningArmoredCar.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
_Tank = new DrawingArmoredCar(random.Next(100,300), random.Next(1000,3000),
|
||||
Color.FromArgb(random.Next(0,256), random.Next(0,256), random.Next(0,256)),
|
||||
pictureBoxTank.Width, pictureBoxTank.Height);
|
||||
|
||||
_Tank.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
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>
|
||||
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
|
@ -6,9 +6,6 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Tank.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
|
Loading…
Reference in New Issue
Block a user