210 lines
7.8 KiB
C#
210 lines
7.8 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Cruiser
|
|||
|
{
|
|||
|
public class DrawingCruiser
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Класс-сущность
|
|||
|
/// </summary>
|
|||
|
public EntityCruiser? EntityCruiser { get; private set; }
|
|||
|
/// <summary>
|
|||
|
/// Ширина окна
|
|||
|
/// </summary>
|
|||
|
private int _pictureWidth;
|
|||
|
/// <summary>
|
|||
|
/// Высота окна
|
|||
|
/// </summary>
|
|||
|
private int _pictureHeight;
|
|||
|
/// <summary>
|
|||
|
/// Левая координата прорисовки Крейсера
|
|||
|
/// </summary>
|
|||
|
private static int _startPosX;
|
|||
|
/// <summary>
|
|||
|
/// Верхняя кооридната прорисовки Крейсера
|
|||
|
/// </summary>
|
|||
|
private static int _startPosY;
|
|||
|
/// <summary>
|
|||
|
/// Ширина прорисовки Крейсера
|
|||
|
/// </summary>
|
|||
|
private readonly int _cruiserWidth = 150;
|
|||
|
/// <summary>
|
|||
|
/// Высота прорисовки Крейсера
|
|||
|
/// </summary>
|
|||
|
private readonly int _cruiserHeight = 60;
|
|||
|
/// <summary>
|
|||
|
/// Цвет для палубы
|
|||
|
/// </summary>
|
|||
|
public Color PalubaColor { get; private set; }
|
|||
|
/// <summary>
|
|||
|
/// Цвет для элементов
|
|||
|
/// </summary>
|
|||
|
public Color ElementsColor { get; private set; }
|
|||
|
/// <summary>
|
|||
|
/// Цвет для дополнений
|
|||
|
/// </summary>
|
|||
|
public Color DopColor { get; private set; }
|
|||
|
/// <summary>
|
|||
|
/// Шахты
|
|||
|
/// </summary>
|
|||
|
public bool Mines { get; private set; }
|
|||
|
/// <summary>
|
|||
|
/// Верт. площадка
|
|||
|
/// </summary>
|
|||
|
public bool HelicopPad { get; private set; }
|
|||
|
/// <summary>
|
|||
|
/// Инициализация свойств
|
|||
|
/// </summary>
|
|||
|
/// <param name="speed">Скорость</param>
|
|||
|
/// <param name="weight">Вес автомобиля</param>
|
|||
|
/// <param name="bodyColor">Основной цвет</param>
|
|||
|
/// <param name="secColor">Элементов цвет</param>
|
|||
|
/// <param name="dopColor">Дополнений цвет</param>
|
|||
|
/// <param name="rocketMines">Признак наличия ракетных шахт</param>
|
|||
|
/// <param name="helipad">Признак наличия вертолётной площадки</param>
|
|||
|
/// <param name="width">Ширина картинки</param>
|
|||
|
/// <param name="height">Высота картинки</param>
|
|||
|
/// <returns>true - объект создан, false - проверка не пройдена,
|
|||
|
///нельзя создать объект в этих размерах</returns>
|
|||
|
public bool Init(int speed, double weight, Color bodyColor, Color secColor, Color dopColor, bool rocketMines, bool helipad, int width, int height)
|
|||
|
{
|
|||
|
if (width < _cruiserWidth || height < _cruiserHeight)
|
|||
|
{
|
|||
|
_pictureHeight = _cruiserHeight + 100;
|
|||
|
_pictureWidth = _cruiserWidth + 100;
|
|||
|
}
|
|||
|
_pictureWidth = width;
|
|||
|
_pictureHeight = height;
|
|||
|
PalubaColor = bodyColor;
|
|||
|
ElementsColor = secColor;
|
|||
|
DopColor = dopColor;
|
|||
|
Mines = rocketMines;
|
|||
|
HelicopPad = helipad;
|
|||
|
EntityCruiser = new EntityCruiser();
|
|||
|
EntityCruiser.Init(speed, weight, bodyColor, secColor, rocketMines, helipad);
|
|||
|
return true;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Установка позиции
|
|||
|
/// </summary>
|
|||
|
/// <param name="x">Координата X</param>
|
|||
|
/// <param name="y">Координата Y</param>
|
|||
|
public void SetPosition(int x, int y)
|
|||
|
{
|
|||
|
if (x < 0 || y < 0)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
if (x > _pictureWidth || y > _pictureHeight)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
_startPosX = x;
|
|||
|
_startPosY = y;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Изменение направления перемещения
|
|||
|
/// </summary>
|
|||
|
/// <param name="direction">Направление</param>
|
|||
|
public void MoveTransport(Direction direction)
|
|||
|
{
|
|||
|
if (EntityCruiser == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
switch (direction)
|
|||
|
{
|
|||
|
//влево
|
|||
|
case Direction.Left:
|
|||
|
if (_startPosX - EntityCruiser.Step > 0)
|
|||
|
{
|
|||
|
_startPosX -= (int)EntityCruiser.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
//вверх
|
|||
|
case Direction.Up:
|
|||
|
if (_startPosY - EntityCruiser.Step > 0)
|
|||
|
{
|
|||
|
_startPosY -= (int)EntityCruiser.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
// вправо
|
|||
|
case Direction.Right:
|
|||
|
if (_startPosX + EntityCruiser.Step < _pictureWidth - _cruiserWidth)
|
|||
|
{
|
|||
|
_startPosX += (int)EntityCruiser.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
//вниз
|
|||
|
case Direction.Down:
|
|||
|
if (_startPosY + EntityCruiser.Step < _pictureHeight - _cruiserHeight)
|
|||
|
{
|
|||
|
_startPosY += (int)EntityCruiser.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Прорисовка объекта
|
|||
|
/// </summary>
|
|||
|
/// <param name="g"></param>
|
|||
|
public void DrawTransport(Graphics g)
|
|||
|
{
|
|||
|
if (EntityCruiser == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
// палуба
|
|||
|
Point[] Paluba = new Point[5]
|
|||
|
{
|
|||
|
new Point(_startPosX + 10,_startPosY),
|
|||
|
new Point(_startPosX + 110,_startPosY),
|
|||
|
new Point(_startPosX + 160,_startPosY + 30),
|
|||
|
new Point(_startPosX + 110,_startPosY + 60),
|
|||
|
new Point(_startPosX + 10,_startPosY + 60)
|
|||
|
};
|
|||
|
Brush brush = new SolidBrush(PalubaColor);
|
|||
|
g.FillPolygon(brush, Paluba);
|
|||
|
// элементы
|
|||
|
Point[] Elements = new Point[8]
|
|||
|
{
|
|||
|
new Point(_startPosX + 50,_startPosY + 20),
|
|||
|
new Point(_startPosX + 70,_startPosY + 20),
|
|||
|
new Point(_startPosX + 70,_startPosY + 10),
|
|||
|
new Point(_startPosX + 90,_startPosY + 10),
|
|||
|
new Point(_startPosX + 90,_startPosY + 50),
|
|||
|
new Point(_startPosX + 70,_startPosY + 50),
|
|||
|
new Point(_startPosX + 70,_startPosY + 40),
|
|||
|
new Point(_startPosX + 50,_startPosY + 40),
|
|||
|
};
|
|||
|
Brush brushElem = new SolidBrush(ElementsColor);
|
|||
|
g.FillPolygon(brushElem, Elements);
|
|||
|
g.FillEllipse(brushElem, _startPosX + 100, _startPosY + 20, 20, 20);
|
|||
|
// турбины
|
|||
|
Brush Turbins = new SolidBrush(Color.Black);
|
|||
|
g.FillRectangle(Turbins, _startPosX, _startPosY + 10, 10, 20);
|
|||
|
g.FillRectangle(Turbins, _startPosX, _startPosY + 35, 10, 20);
|
|||
|
// шахты
|
|||
|
if (Mines)
|
|||
|
{
|
|||
|
Brush DopBrush = new SolidBrush(DopColor);
|
|||
|
g.FillRectangle(DopBrush, _startPosX + 15, _startPosY + 10, 10, 15);
|
|||
|
g.FillRectangle(DopBrush, _startPosX + 30, _startPosY + 10, 10, 15);
|
|||
|
}
|
|||
|
// верт площадка
|
|||
|
if (HelicopPad)
|
|||
|
{
|
|||
|
Brush DopBrush = new SolidBrush(DopColor);
|
|||
|
g.FillEllipse(DopBrush, _startPosX + 15, _startPosY + 25, 25, 25);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|