146 lines
5.2 KiB
C#
146 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Bus
|
|
{
|
|
public class DrawingBus
|
|
{
|
|
public EntityBus Bus { get; protected set; }
|
|
protected float _startPosX;
|
|
protected float _startPosY;
|
|
private int? _pictureWidth = null;
|
|
private int? _pictureHeight = null;
|
|
protected readonly int _busWidth = 157;
|
|
protected readonly int _busHeight = 65;
|
|
|
|
public DrawingBus(int speed, float weight, Color bodyColor)
|
|
{
|
|
Bus = new EntityBus(speed, weight, bodyColor);
|
|
}
|
|
|
|
|
|
protected DrawingBus(int speed, float weight, Color bodyColor, int busWidth, int busHeight) :
|
|
this(speed, weight, bodyColor)
|
|
{
|
|
_busWidth = busWidth;
|
|
_busHeight = busHeight;
|
|
}
|
|
|
|
public void SetPosition(int x, int y, int width, int height)
|
|
{
|
|
if (x < 0 || y < 0 || width < x+_busWidth || height < y + _busHeight)
|
|
{
|
|
_pictureHeight = null;
|
|
_pictureWidth = null;
|
|
return;
|
|
}
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
}
|
|
|
|
public void MoveTransport(Direction direction)
|
|
{
|
|
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
switch (direction)
|
|
{
|
|
case Direction.Right:
|
|
if (_startPosX + _busWidth + Bus.Step < _pictureWidth)
|
|
{
|
|
_startPosX += Bus.Step;
|
|
}
|
|
break;
|
|
case Direction.Left:
|
|
if (_startPosX - Bus.Step >= 0)
|
|
{
|
|
_startPosX -= Bus.Step;
|
|
}
|
|
break;
|
|
case Direction.Up:
|
|
if (_startPosY - Bus.Step >= 0)
|
|
{
|
|
_startPosY -= Bus.Step;
|
|
}
|
|
break;
|
|
case Direction.Down:
|
|
if (_startPosY + _busHeight + Bus.Step < _pictureHeight)
|
|
{
|
|
_startPosY += Bus.Step;
|
|
}
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
|
{
|
|
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
//границы автобуса
|
|
Pen pen = new(Color.Black);
|
|
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 10, 150, 50);
|
|
|
|
//кузов
|
|
Brush br = new SolidBrush(Bus?.BodyColor ?? Color.Black);
|
|
g.FillRectangle(br, _startPosX+ 11, _startPosY + 11, 149, 49);
|
|
|
|
//колеса
|
|
Brush brBlack = new SolidBrush(Color.Black);
|
|
g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 50, 20, 20);
|
|
g.FillEllipse(brBlack, _startPosX + 130, _startPosY + 50, 20, 20);
|
|
Brush brGray = new SolidBrush(Color.Gray);
|
|
g.FillEllipse(brGray, _startPosX + 25, _startPosY + 55, 10, 10);
|
|
g.FillEllipse(brGray, _startPosX + 135, _startPosY + 55, 10, 10);
|
|
|
|
//стекла
|
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
|
g.FillRectangle(brBlue, _startPosX + 10, _startPosY + 20, 10, 20);
|
|
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 20, 10, 20);
|
|
g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 20, 30, 20);
|
|
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 30, 20);
|
|
g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 20, 15, 40);
|
|
g.DrawRectangle(pen, _startPosX + 70, _startPosY + 20, 15, 40);
|
|
g.FillRectangle(brBlue, _startPosX + 85, _startPosY + 20, 15, 40);
|
|
g.DrawRectangle(pen, _startPosX + 85, _startPosY + 20, 15, 40);
|
|
g.FillRectangle(brBlue, _startPosX + 110, _startPosY + 20, 30, 20);
|
|
g.DrawRectangle(pen, _startPosX + 110, _startPosY + 20, 30, 20);
|
|
g.FillRectangle(brBlue, _startPosX + 150, _startPosY + 20, 10, 20);
|
|
g.DrawRectangle(pen, _startPosX + 150, _startPosY + 20, 10, 20);
|
|
}
|
|
|
|
public void ChangeBorbers(int width, int height)
|
|
{
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
if (_pictureWidth <= _busWidth || _pictureHeight <= _busHeight)
|
|
{
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
return;
|
|
}
|
|
if (_startPosX + _busWidth > _pictureWidth)
|
|
{
|
|
_startPosX = _pictureWidth.Value - _busWidth;
|
|
}
|
|
if (_startPosY + _busHeight > _pictureHeight)
|
|
{
|
|
_startPosY = _pictureHeight.Value - _busHeight;
|
|
}
|
|
}
|
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
|
{
|
|
return (_startPosX, _startPosY, _startPosX + _busWidth, _startPosY + _busHeight);
|
|
}
|
|
|
|
}
|
|
}
|