2023-11-30 02:23:07 +04:00
|
|
|
|
using ProjectBulldozer.Entities;
|
2023-11-30 02:09:48 +04:00
|
|
|
|
using ProjectBulldozer.MovementStrategy;
|
|
|
|
|
namespace ProjectBulldozer.Drawning
|
2023-11-23 01:37:55 +04:00
|
|
|
|
{
|
|
|
|
|
public class DrawingTractor
|
|
|
|
|
{
|
|
|
|
|
public EntityTractor? EntityTractor { get; protected set; }
|
2023-12-13 17:38:05 +04:00
|
|
|
|
public int _pictureWidth;
|
|
|
|
|
public int _pictureHeight;
|
2023-11-23 01:37:55 +04:00
|
|
|
|
protected int _startPosX;
|
|
|
|
|
protected int _startPosY;
|
2023-11-30 02:09:48 +04:00
|
|
|
|
protected readonly int _tractWidth = 120;
|
|
|
|
|
protected readonly int _tractHeight = 110;
|
2023-11-23 01:37:55 +04:00
|
|
|
|
public int GetPosX => _startPosX;
|
|
|
|
|
public int GetPosY => _startPosY;
|
|
|
|
|
public int GetWidth => _tractWidth;
|
|
|
|
|
public int GetHeight => _tractHeight;
|
2023-11-30 02:09:48 +04:00
|
|
|
|
public IMoveableObject GetMoveableObject => new DrawingObjectTractor(this);
|
2023-11-23 01:37:55 +04:00
|
|
|
|
public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth)
|
|
|
|
|
{
|
|
|
|
|
if (width < _tractWidth || heigth < _tractHeight)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = heigth;
|
|
|
|
|
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
|
|
|
|
}
|
|
|
|
|
protected DrawingTractor(int speed, double weight, Color bodyColor, int width,
|
|
|
|
|
int height, int tractWidth, int tractHeight)
|
|
|
|
|
{
|
|
|
|
|
if (width < _tractWidth || height < _tractHeight)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
_tractWidth = tractWidth;
|
|
|
|
|
_tractHeight = tractHeight;
|
|
|
|
|
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
|
|
|
|
}
|
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
if (x < 0 || x + _tractWidth > _pictureWidth)
|
|
|
|
|
{
|
2023-11-30 02:09:48 +04:00
|
|
|
|
x = _pictureWidth - _tractWidth;
|
2023-11-23 01:37:55 +04:00
|
|
|
|
}
|
|
|
|
|
if (y < 0 || y + _tractHeight > _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
y = _pictureHeight - _tractHeight;
|
|
|
|
|
}
|
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
|
|
|
|
}
|
|
|
|
|
public void MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityTractor == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case DirectionType.Left:
|
|
|
|
|
if (_startPosX - EntityTractor.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosX -= (int)EntityTractor.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DirectionType.Up:
|
|
|
|
|
if (_startPosY - EntityTractor.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosY -= (int)EntityTractor.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DirectionType.Right:
|
|
|
|
|
if (_startPosX + EntityTractor.Step + _tractWidth < _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX += (int)EntityTractor.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DirectionType.Down:
|
|
|
|
|
if (_startPosY + EntityTractor.Step + _tractHeight < _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY += (int)EntityTractor.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
if (EntityTractor == null) return;
|
|
|
|
|
}
|
|
|
|
|
Pen pen = new(Color.Black);
|
|
|
|
|
Brush brownBrush = new SolidBrush(Color.Brown);
|
|
|
|
|
Brush windows = new SolidBrush(Color.LightYellow);
|
|
|
|
|
Brush bodyColor = new SolidBrush(EntityTractor.BodyColor);
|
|
|
|
|
Brush grayBrush = new SolidBrush(Color.Gray);
|
|
|
|
|
//основное тело
|
2023-11-30 02:09:48 +04:00
|
|
|
|
g.FillRectangle(bodyColor, _startPosX + 18, _startPosY + 42, 99, 56);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX + 18, _startPosY + 42, 99, 56);
|
2023-11-23 01:37:55 +04:00
|
|
|
|
//кабина водителя
|
2023-11-30 02:09:48 +04:00
|
|
|
|
g.FillRectangle(windows, _startPosX + 18, _startPosY + 4 , 37, 37);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX + 18, _startPosY +4 , 37, 37);
|
2023-11-23 01:37:55 +04:00
|
|
|
|
//колеса
|
2023-11-30 02:09:48 +04:00
|
|
|
|
g.FillEllipse(grayBrush, _startPosX + 19, _startPosY + 76, 45, 45);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX + 19, _startPosY + 76, 45, 45);
|
|
|
|
|
g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 87, 33, 33);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 87, 33, 33);
|
2023-11-23 01:37:55 +04:00
|
|
|
|
//выхлопная труба
|
2023-11-30 02:09:48 +04:00
|
|
|
|
g.FillRectangle(brownBrush, _startPosX + 88, _startPosY+ 6, 14, 35);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX + 88, _startPosY + 6, 14, 35);
|
2023-11-23 01:37:55 +04:00
|
|
|
|
}
|
|
|
|
|
public bool CanMove(DirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityTractor == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return direction switch
|
|
|
|
|
{
|
|
|
|
|
DirectionType.Left => _startPosX - EntityTractor.Step > 0,
|
|
|
|
|
DirectionType.Up => _startPosY - EntityTractor.Step > 0,
|
|
|
|
|
DirectionType.Right => _startPosX + EntityTractor.Step < _pictureWidth,
|
|
|
|
|
DirectionType.Down => _startPosY + EntityTractor.Step < _pictureHeight,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|