2023-11-14 13:52:50 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2023-11-14 14:11:54 +04:00
|
|
|
|
using DoubleDeckerbus.Entities;
|
2023-11-25 14:55:27 +04:00
|
|
|
|
using DoubleDeckerbus.Move_Strategy;
|
2023-11-14 14:11:54 +04:00
|
|
|
|
|
2023-11-25 14:55:27 +04:00
|
|
|
|
namespace DoubleDeckerbus.Drawing
|
2023-11-14 13:52:50 +04:00
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
public class DrawingBus
|
2023-11-14 13:52:50 +04:00
|
|
|
|
{
|
2023-11-25 14:13:49 +04:00
|
|
|
|
public IMoveableObject GetMoveableObject => new DrawingObjectBus(this);
|
2023-11-14 14:11:54 +04:00
|
|
|
|
public EntityBus? EntityBus { get; protected set; }
|
|
|
|
|
public int _pictureWidth;
|
|
|
|
|
public int _pictureHeight;
|
|
|
|
|
protected int _startPosX;
|
|
|
|
|
protected int _startPosY;
|
2023-11-25 14:55:27 +04:00
|
|
|
|
protected readonly int _busWidth = 175;
|
|
|
|
|
protected readonly int _busHeight = 115;
|
2023-11-14 14:11:54 +04:00
|
|
|
|
public int GetPosX => _startPosX;
|
|
|
|
|
public int GetPosY => _startPosY;
|
|
|
|
|
public int GetWidth => _busWidth;
|
|
|
|
|
public int GetHeight => _busHeight;
|
|
|
|
|
public DrawingBus(int speed, double weight, Color bodyColor, int width, int height)
|
2023-11-14 13:52:50 +04:00
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
if (width < _busWidth || height < _busHeight)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-14 13:52:50 +04:00
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
2023-11-14 14:11:54 +04:00
|
|
|
|
EntityBus = new EntityBus(speed, weight, bodyColor);
|
|
|
|
|
}
|
|
|
|
|
protected DrawingBus(int speed, double weight, Color bodyColor, int width, int height, int busWidth, int busHeight)
|
|
|
|
|
{
|
|
|
|
|
if (width < _busWidth || height < _busHeight)
|
2023-11-14 13:52:50 +04:00
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
return;
|
2023-11-14 13:52:50 +04:00
|
|
|
|
}
|
2023-11-14 14:11:54 +04:00
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
_busWidth = busWidth;
|
|
|
|
|
_busHeight = busHeight;
|
|
|
|
|
EntityBus = new EntityBus(speed, weight, bodyColor);
|
2023-11-14 13:52:50 +04:00
|
|
|
|
}
|
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
if (x > _pictureWidth || y > _pictureHeight)
|
2023-11-14 13:52:50 +04:00
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
return;
|
2023-11-14 13:52:50 +04:00
|
|
|
|
}
|
2023-11-14 14:11:54 +04:00
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
2023-11-14 13:52:50 +04:00
|
|
|
|
}
|
2023-11-14 14:11:54 +04:00
|
|
|
|
public void MoveTransport(DirectionType direction)
|
2023-11-25 14:55:27 +04:00
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
if (!CanMove(direction) || EntityBus == null)
|
|
|
|
|
{
|
2023-11-14 13:52:50 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
case DirectionType.Left:
|
|
|
|
|
if (_startPosX - EntityBus.Step > 0)
|
2023-11-14 13:52:50 +04:00
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
_startPosX -= (int)EntityBus.Step;
|
2023-11-14 13:52:50 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
2023-11-14 14:11:54 +04:00
|
|
|
|
case DirectionType.Up:
|
|
|
|
|
if (_startPosY - EntityBus.Step > 0)
|
2023-11-14 13:52:50 +04:00
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
_startPosY -= (int)EntityBus.Step;
|
2023-11-14 13:52:50 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
2023-11-14 14:11:54 +04:00
|
|
|
|
case DirectionType.Right:
|
|
|
|
|
if (_startPosX + _busWidth + EntityBus.Step < _pictureWidth)
|
2023-11-14 13:52:50 +04:00
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
_startPosX += (int)EntityBus.Step;
|
2023-11-14 13:52:50 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
2023-11-14 14:11:54 +04:00
|
|
|
|
case DirectionType.Down:
|
|
|
|
|
if (_startPosY + _busHeight + EntityBus.Step < _pictureHeight)
|
2023-11-14 13:52:50 +04:00
|
|
|
|
{
|
2023-11-14 14:11:54 +04:00
|
|
|
|
_startPosY += (int)EntityBus.Step;
|
2023-11-14 13:52:50 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-14 14:11:54 +04:00
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
2023-11-14 13:52:50 +04:00
|
|
|
|
{
|
|
|
|
|
Pen pen = new(Color.Black);
|
2023-11-14 14:11:54 +04:00
|
|
|
|
Brush additionalBrush = new
|
|
|
|
|
SolidBrush(EntityBus.BodyColor);
|
2023-11-25 14:13:49 +04:00
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 52, 21, 20);
|
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 71, 30, 27);
|
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 52, 137, 46);
|
2023-11-14 13:52:50 +04:00
|
|
|
|
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);
|
|
|
|
|
Brush gr = new SolidBrush(Color.Gray);
|
2023-11-14 14:11:54 +04:00
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX + 23, _startPosY + 88, 25, 25);
|
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX + 123, _startPosY + 88, 25, 25);
|
2023-11-14 13:52:50 +04:00
|
|
|
|
g.FillEllipse(gr, _startPosX + 25, _startPosY + 90, 21, 21);
|
|
|
|
|
g.FillEllipse(gr, _startPosX + 125, _startPosY + 90, 21, 21);
|
|
|
|
|
}
|
2023-11-14 14:11:54 +04:00
|
|
|
|
public bool CanMove(DirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityBus == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return direction switch
|
|
|
|
|
{
|
|
|
|
|
DirectionType.Left => _startPosX - EntityBus.Step > 0,
|
|
|
|
|
DirectionType.Up => _startPosY - EntityBus.Step > 0,
|
|
|
|
|
DirectionType.Right => _startPosX + _busWidth + EntityBus.Step < _pictureWidth,
|
|
|
|
|
DirectionType.Down => _startPosY + _busHeight + EntityBus.Step < _pictureHeight,
|
|
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-11-14 13:52:50 +04:00
|
|
|
|
}
|
|
|
|
|
}
|