parent
315d6d208a
commit
18c19270af
197
DoubleDeckerBus/DrawingBus.cs
Normal file
197
DoubleDeckerBus/DrawingBus.cs
Normal file
@ -0,0 +1,197 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DoubleDeckerBus
|
||||
{
|
||||
internal class DrawingBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityDoubleDeckerBus? EntityDoubleDeckerBus { 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 _busWidth = 180;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автобуса
|
||||
/// </summary>
|
||||
private readonly int _busHeight = 120;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="secondFloor">Признак наличия второго этажа</param>
|
||||
/// <param name="stairs">Признак наличия лестницы</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена
|
||||
///
|
||||
public bool Init(EntityDoubleDeckerBus bus, int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityDoubleDeckerBus = bus;
|
||||
if (_pictureWidth < _busWidth || _pictureHeight < _busHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
///
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
if (_startPosX + _busWidth > _pictureWidth) {
|
||||
_startPosX = _pictureWidth - _busWidth;
|
||||
}
|
||||
if (_startPosX < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_startPosY + _busHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _busHeight;
|
||||
}
|
||||
if (_startPosY < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (EntityDoubleDeckerBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case Direction.Left:
|
||||
if (_startPosX - EntityDoubleDeckerBus.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityDoubleDeckerBus.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case Direction.Up:
|
||||
if (_startPosY - EntityDoubleDeckerBus.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityDoubleDeckerBus.Step;
|
||||
}
|
||||
break;
|
||||
// вправо
|
||||
case Direction.Right:
|
||||
if (_startPosX + EntityDoubleDeckerBus.Step + _busWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityDoubleDeckerBus.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case Direction.Down:
|
||||
if (_startPosY + EntityDoubleDeckerBus.Step + _busHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityDoubleDeckerBus.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityDoubleDeckerBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyColor = new
|
||||
SolidBrush(EntityDoubleDeckerBus.BodyColor);
|
||||
|
||||
g.FillRectangle(bodyColor, _startPosX + 147, _startPosY + 52, 21, 20); //маленький
|
||||
g.FillRectangle(bodyColor, _startPosX + 147, _startPosY + 71, 30, 27); //2
|
||||
g.FillRectangle(bodyColor, _startPosX + 10, _startPosY + 52, 137, 46); //большой прямоугольник 2
|
||||
|
||||
//окна
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(brBlue, _startPosX + 150, _startPosY + 55, 15, 15);
|
||||
|
||||
g.FillRectangle(brBlue, _startPosX + 42, _startPosY + 55, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 69, _startPosY + 55, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 96, _startPosY + 55, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 123, _startPosY + 55, 15, 15);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 30, _startPosY + 52, _startPosX + 30, _startPosY + 98);
|
||||
g.DrawLine(pen, _startPosX + 35, _startPosY + 52, _startPosX + 35, _startPosY + 98);
|
||||
//ВТОРОЙ ЭТАЖ
|
||||
if (EntityDoubleDeckerBus.SecondFloor)
|
||||
{
|
||||
Brush additionalColor = new
|
||||
SolidBrush(EntityDoubleDeckerBus.AdditionalColor);
|
||||
|
||||
g.FillRectangle(additionalColor, _startPosX + 7, _startPosY + 12, 172, 40); //большой прямоугольник
|
||||
|
||||
g.DrawLine(pen, _startPosX + 7, _startPosY + 36, _startPosX + 178, _startPosY + 36);
|
||||
|
||||
g.FillRectangle(brBlue, _startPosX + 15, _startPosY + 15, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 42, _startPosY + 15, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 69, _startPosY + 15, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 96, _startPosY + 15, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 123, _startPosY + 15, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 150, _startPosY + 15, 15, 15);
|
||||
}
|
||||
//ЛЕСТНИЦА
|
||||
if (EntityDoubleDeckerBus.Stairs)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX + 10, _startPosY + 55, _startPosX + 34, _startPosY + 55);
|
||||
g.DrawLine(pen, _startPosX + 10, _startPosY + 58, _startPosX + 34, _startPosY + 58);
|
||||
g.DrawLine(pen, _startPosX + 10, _startPosY + 64, _startPosX + 34, _startPosY + 64);
|
||||
g.DrawLine(pen, _startPosX + 10, _startPosY + 72, _startPosX + 34, _startPosY + 72);
|
||||
g.DrawLine(pen, _startPosX + 10, _startPosY + 80, _startPosX + 34, _startPosY + 80);
|
||||
g.DrawLine(pen, _startPosX + 10, _startPosY + 88, _startPosX + 34, _startPosY + 88);
|
||||
g.DrawLine(pen, _startPosX + 10, _startPosY + 94, _startPosX + 34, _startPosY + 94);
|
||||
}
|
||||
// колёса
|
||||
Brush gr = new SolidBrush(Color.Gray);
|
||||
g.FillEllipse(bodyColor, _startPosX + 23, _startPosY + 88, 25, 25);
|
||||
g.FillEllipse(bodyColor, _startPosX + 123, _startPosY + 88, 25, 25);
|
||||
|
||||
g.FillEllipse(gr, _startPosX + 25, _startPosY + 90, 21, 21);
|
||||
g.FillEllipse(gr, _startPosX + 125, _startPosY + 90, 21, 21);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user