186 lines
7.7 KiB
C#
186 lines
7.7 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Tank
|
|||
|
{
|
|||
|
public class DrawningTank
|
|||
|
{
|
|||
|
|
|||
|
public EntityTank? EntityTank { get; private set; }
|
|||
|
/// <summary>
|
|||
|
/// Ширина окна
|
|||
|
/// </summary>
|
|||
|
private int? _pictureWidth;
|
|||
|
/// <summary>
|
|||
|
/// Высота окна
|
|||
|
/// </summary>
|
|||
|
private int? _pictureHeight;
|
|||
|
/// <summary>
|
|||
|
/// Левая координата прорисовки автомобиля
|
|||
|
/// </summary>
|
|||
|
private int? _startPosX;
|
|||
|
/// <summary>
|
|||
|
/// Верхняя кооридната прорисовки автомобиля
|
|||
|
/// </summary>
|
|||
|
private int? _startPosY;
|
|||
|
/// <summary>
|
|||
|
/// Ширина прорисовки автомобиля
|
|||
|
/// </summary>
|
|||
|
private readonly int _drawningCarWidth = 110;
|
|||
|
/// <summary>
|
|||
|
/// Высота прорисовки автомобиля
|
|||
|
/// </summary>
|
|||
|
private readonly int _drawningCarHeight = 60;
|
|||
|
/// <summary>
|
|||
|
/// Инициализация свойств
|
|||
|
/// </summary>
|
|||
|
/// <param name="speed">Скорость</param>
|
|||
|
/// <param name="weight">Вес</param>
|
|||
|
/// <param name="bodyColor">Основной цвет</param>
|
|||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
|||
|
/// <param name="bodyKit">Признак наличия обвеса</param>
|
|||
|
/// <param name="wing">Признак наличия антикрыла</param>
|
|||
|
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
|||
|
public void Init(int speed, double weight, Color bodyColor, Color
|
|||
|
additionalColor)
|
|||
|
{
|
|||
|
EntityTank = new EntityTank();
|
|||
|
EntityTank.Init(speed, weight, bodyColor, additionalColor);
|
|||
|
_pictureWidth = null;
|
|||
|
_pictureHeight = null;
|
|||
|
_startPosX = null;
|
|||
|
_startPosY = null;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Установка границ поля
|
|||
|
/// </summary>
|
|||
|
/// <param name="width">Ширина поля</param>
|
|||
|
/// <param name="height">Высота поля</param>
|
|||
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя
|
|||
|
// разместить объект в этих размерах</returns>
|
|||
|
public bool SetPictureSize(int width, int height)
|
|||
|
{
|
|||
|
// TODO проверка, что объект "влезает" в размеры поля
|
|||
|
// если влезает, сохраняем границы и корректируем позицию объекта,
|
|||
|
//если она была уже установлена
|
|||
|
_pictureWidth = width;
|
|||
|
_pictureHeight = height;
|
|||
|
return true;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Установка позиции
|
|||
|
/// </summary>
|
|||
|
/// <param name="x">Координата X</param>
|
|||
|
/// <param name="y">Координата Y</param>
|
|||
|
public void SetPosition(int x, int y)
|
|||
|
{
|
|||
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
// TODO если при установке объекта в эти координаты, он будет
|
|||
|
// "выходить" за границы формы
|
|||
|
// то надо изменить координаты, чтобы он оставался в этих границах
|
|||
|
_startPosX = x;
|
|||
|
_startPosY = y;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Изменение направления перемещения
|
|||
|
/// </summary>
|
|||
|
/// <param name="direction">Направление</param>
|
|||
|
/// <returns>true - перемещене выполнено, false - перемещение
|
|||
|
//невозможно</returns>
|
|||
|
public bool MoveTransport(DirectionType direction)
|
|||
|
{
|
|||
|
if (EntityTank == null || !_startPosX.HasValue ||
|
|||
|
!_startPosY.HasValue)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
switch (direction)
|
|||
|
{
|
|||
|
//влево
|
|||
|
case DirectionType.Left:
|
|||
|
if (_startPosX.Value - EntityTank.Step > 0)
|
|||
|
{
|
|||
|
_startPosX -= (int)EntityTank.Step;
|
|||
|
}
|
|||
|
return true;
|
|||
|
//вверх
|
|||
|
case DirectionType.Up:
|
|||
|
if (_startPosY.Value - EntityTank.Step > 0)
|
|||
|
{
|
|||
|
_startPosY -= (int)EntityTank.Step;
|
|||
|
}
|
|||
|
return true;
|
|||
|
// вправо
|
|||
|
case DirectionType.Right:
|
|||
|
if (_startPosX.Value + EntityTank.Step < 900)
|
|||
|
{
|
|||
|
_startPosX += (int)EntityTank.Step;
|
|||
|
}
|
|||
|
return true;
|
|||
|
//вниз
|
|||
|
case DirectionType.Down:
|
|||
|
if (_startPosY.Value + EntityTank.Step < 500)
|
|||
|
{
|
|||
|
_startPosY += (int)EntityTank.Step;
|
|||
|
}
|
|||
|
//TODO прописать логику сдвига в вниз
|
|||
|
return true;
|
|||
|
default:
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Прорисовка объекта
|
|||
|
/// </summary>
|
|||
|
/// <param name="g"></param>
|
|||
|
public void DrawTransport(Graphics g)
|
|||
|
{
|
|||
|
if (EntityTank == null || !_startPosX.HasValue ||
|
|||
|
!_startPosY.HasValue)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Pen pen = new(Color.Black);
|
|||
|
Brush additionalBrush = new
|
|||
|
SolidBrush(EntityTank.AdditionalColor);
|
|||
|
Brush brGreen = new SolidBrush(Color.Green);
|
|||
|
|
|||
|
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value, 130, 70);
|
|||
|
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 20, 30, 30);
|
|||
|
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 20, _startPosX.Value + 140, _startPosY.Value + 20);
|
|||
|
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 50, _startPosX.Value + 140, _startPosY.Value + 50);
|
|||
|
|
|||
|
|
|||
|
/*g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value, 40, 40);*/
|
|||
|
g.FillRectangle(brGreen, _startPosX.Value + 11, _startPosY.Value + 1, 129, 19);
|
|||
|
g.FillRectangle(brGreen, _startPosX.Value + 11, _startPosY.Value + 51, 129, 19);
|
|||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 11, _startPosY.Value + 21, 29, 29);
|
|||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 111, _startPosY.Value + 21, 29, 29);
|
|||
|
|
|||
|
|
|||
|
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 20, 70, 30);
|
|||
|
g.FillRectangle(brGreen, _startPosX.Value + 41, _startPosY.Value + 21, 69, 29);
|
|||
|
|
|||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 20, 30, 30);
|
|||
|
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 20, 30, 30);
|
|||
|
|
|||
|
|
|||
|
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 30, 100, 10);
|
|||
|
g.FillRectangle(brGreen, _startPosX.Value + 91, _startPosY.Value + 31, 99, 9);
|
|||
|
|
|||
|
|
|||
|
/*g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value, 40, 40);
|
|||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 45, 15, 15);*/
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|