using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectAntiAircraftGun.Entities;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ProjectAntiAircraftGun.DrawingObjects
{
public class DrawingTank
{
///
/// Класс-сущность
///
public EntityTank? EntityTank { get; protected set; }
///
/// Ширина окна
///
private int _pictureWidth;
///
/// Высота окна
///
private int _pictureHeight;
///
/// Левая координата прорисовки танка
///
protected int _startPosX;
///
/// Верхняя кооридната прорисовки танка
///
protected int _startPosY;
///
/// Ширина прорисовки танка
///
protected readonly int _tankWidth = 130;
///
/// Высота прорисовки танка
///
protected readonly int _tankHeight = 102;
///
/// Координата X объекта
///
public int GetPosX => _startPosX;
///
/// Координата Y объекта
///
public int GetPosY => _startPosY;
///
/// Ширина объекта
///
public int GetWidth => _tankWidth;
///
/// Высота объекта
///
public int GetHeight => _tankHeight;
///
/// Конструктор
///
/// Скорость
/// Вес
/// Основной цвет
/// Дополнительный цвет
/// Ширина картинки
/// Высота картинки
public DrawingTank(int speed, double weight, Color bodyColor, Color additionalColor, int
width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
EntityTank = new EntityTank(speed, weight, bodyColor, additionalColor);
if (_pictureWidth > _tankWidth && _pictureHeight > _tankHeight)
{
EntityTank = new EntityTank(speed, weight, bodyColor, additionalColor);
}
else
{
EntityTank = null;
}
}
///
/// Конструктор
///
/// Скорость
/// Вес
/// Основной цвет
/// Ширина картинки
/// Высота картинки
/// Ширина прорисовки танка
/// Высота прорисовки танка
protected DrawingTank(int speed, double weight, Color bodyColor, Color additionalColor, int
width, int height, int tankWidth, int tankHeight)
{
_pictureWidth = width;
_pictureHeight = height;
EntityTank = new EntityTank(speed, weight, bodyColor, additionalColor);
if (_pictureWidth > _tankWidth && _pictureHeight > _tankHeight)
{
EntityTank = new EntityTank(speed, weight, bodyColor, additionalColor);
}
else
{
EntityTank = null;
}
}
///
/// Проверка, что объект может переместится по указанному направлению
///
/// Направление
/// true - можно переместится по указанному направлению
public bool CanMove(DirectionType direction)
{
if (EntityTank == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityTank.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityTank.Step > 0,
// вправо
DirectionType.Right => _startPosX + _tankWidth + EntityTank.Step < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + _tankHeight + EntityTank.Step < _pictureHeight,
_ => false,
};
}
///
/// Изменение направления перемещения
///
/// Направление
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityTank == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
_startPosX -= (int)EntityTank.Step;
break;
//вверх
case DirectionType.Up:
_startPosY -= (int)EntityTank.Step;
break;
// вправо
case DirectionType.Right:
_startPosX += (int)EntityTank.Step;
break;
//вниз
case DirectionType.Down:
_startPosY += (int)EntityTank.Step;
break;
}
}
///
/// Установка позиции
///
/// Координата X
/// Координата Y
public void SetPosition(int x, int y)
{
if (EntityTank == null) return;
while (x + _tankWidth > _pictureWidth)
{
x -= (int)EntityTank.Step;
}
while (x < 0)
{
x += (int)EntityTank.Step;
}
while (y + _tankHeight > _pictureHeight)
{
y -= (int)EntityTank.Step;
}
while (y < 0)
{
y += (int)EntityTank.Step;
}
_startPosX = x;
_startPosY = y;
}
///
/// Прорисовка объекта
///
///
public virtual void DrawTransport(Graphics g)
{
if (EntityTank == null) { return; }
Pen pen = new(Color.Black);
pen.Width = 2;
Brush brush = new SolidBrush(EntityTank.BodyColor);
Random random = new Random();
Brush additionalBrush = new SolidBrush(EntityTank.AdditionalColor);
// границы зенитной установки
g.DrawRectangle(pen, _startPosX + 3, _startPosY + 60, 121, 23);
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 43, 54, 16);
g.DrawRectangle(pen, _startPosX + 42, _startPosY + 33, 16, 9);
// корпус
g.FillRectangle(brush, _startPosX + 3, _startPosY + 60, 121, 23);
g.FillRectangle(brush, _startPosX + 20, _startPosY + 43, 54, 16);
g.FillRectangle(brush, _startPosX + 42, _startPosY + 33, 16, 9);
// контур гусеницы
g.DrawLine(pen, _startPosX + 13, _startPosY + 100, _startPosX + 114, _startPosY + 100);
g.DrawLine(pen, _startPosX + 6, _startPosY + 99, _startPosX + 16, _startPosY + 99);
g.DrawLine(pen, _startPosX + 4, _startPosY + 98, _startPosX + 6, _startPosY + 98);
g.DrawLine(pen, _startPosX + 4, _startPosY + 97, _startPosX + 4, _startPosY + 86);
g.DrawLine(pen, _startPosX + 4, _startPosY + 86, _startPosX + 5, _startPosY + 86);
g.DrawLine(pen, _startPosX + 5, _startPosY + 85, _startPosX + 10, _startPosY + 85);
g.DrawLine(pen, _startPosX + 10, _startPosY + 84, _startPosX + 116, _startPosY + 84);
g.DrawLine(pen, _startPosX + 116, _startPosY + 85, _startPosX + 123, _startPosY + 85);
g.DrawLine(pen, _startPosX + 124, _startPosY + 86, _startPosX + 125, _startPosY + 86);
g.DrawLine(pen, _startPosX + 125, _startPosY + 87, _startPosX + 125, _startPosY + 97);
g.DrawLine(pen, _startPosX + 123, _startPosY + 98, _startPosX + 125, _startPosY + 98);
g.DrawLine(pen, _startPosX + 115, _startPosY + 99, _startPosX + 123, _startPosY + 99);
//гусеница
g.FillRectangle(additionalBrush, _startPosX + 4, _startPosY + 87, 120, 10);
g.FillRectangle(additionalBrush, _startPosX + 19, _startPosY + 85, 92, 2);
g.FillRectangle(additionalBrush, _startPosX + 14, _startPosY + 93, 100, 7);
// контур колес
g.DrawEllipse(pen, _startPosX + 5, _startPosY + 83, 18, 17);
g.DrawEllipse(pen, _startPosX + 30, _startPosY + 88, 15, 12);
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 88, 15, 12);
g.DrawEllipse(pen, _startPosX + 70, _startPosY + 88, 15, 12);
g.DrawEllipse(pen, _startPosX + 87, _startPosY + 88, 15, 12);
g.DrawEllipse(pen, _startPosX + 107, _startPosY + 83, 18, 17);
// контур верхних катков
g.DrawEllipse(pen, _startPosX + 43, _startPosY + 83, 7, 5);
g.DrawEllipse(pen, _startPosX + 64, _startPosY + 83, 7, 5);
g.DrawEllipse(pen, _startPosX + 82, _startPosY + 83, 7, 5);
// колеса
g.FillEllipse(brush, _startPosX + 5, _startPosY + 83, 18, 17);
g.FillEllipse(brush, _startPosX + 30, _startPosY + 88, 15, 12);
g.FillEllipse(brush, _startPosX + 50, _startPosY + 88, 15, 12);
g.FillEllipse(brush, _startPosX + 70, _startPosY + 88, 15, 12);
g.FillEllipse(brush, _startPosX + 87, _startPosY + 88, 15, 12);
g.FillEllipse(brush, _startPosX + 107, _startPosY + 83, 18, 17);
// верхние катки
g.FillEllipse(brush, _startPosX + 43, _startPosY + 83, 7, 5);
g.FillEllipse(brush, _startPosX + 64, _startPosY + 83, 7, 5);
g.FillEllipse(brush, _startPosX + 82, _startPosY + 83, 7, 5);
}
}
}