2023-09-19 19:04:33 +04:00
|
|
|
|
using ElectricLocomotive;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ElectricLocomotive
|
|
|
|
|
{
|
|
|
|
|
public class DrawingLocomotiv
|
|
|
|
|
{
|
2023-10-03 11:53:51 +04:00
|
|
|
|
public EntityLocomotiv? EntityLocomotiv { get; protected set; }
|
|
|
|
|
protected int _pictureWidth;
|
|
|
|
|
protected int _pictureHeight;
|
|
|
|
|
public int GetPosX => _startPosX;
|
|
|
|
|
public int GetPosY => _startPosY;
|
|
|
|
|
public int GetWidth => _vehicleWidth;
|
|
|
|
|
public int GetHeight => _vehicleHeight;
|
|
|
|
|
protected int _startPosX;
|
|
|
|
|
protected int _startPosY;
|
|
|
|
|
protected readonly int _vehicleWidth = 170;
|
|
|
|
|
protected readonly int _vehicleHeight = 110;
|
|
|
|
|
|
|
|
|
|
public DrawingLocomotiv(int speed, double weight,int width,int height)
|
2023-09-19 19:04:33 +04:00
|
|
|
|
{
|
|
|
|
|
if (width <= _vehicleWidth || height <= _vehicleHeight) {
|
2023-10-03 11:53:51 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
EntityLocomotiv = new EntityLocomotiv(speed, weight);
|
|
|
|
|
}
|
|
|
|
|
protected DrawingLocomotiv(int speed, double weight,int width,int height, int vehicleHeight, int vehicleWidth)
|
|
|
|
|
{
|
|
|
|
|
if (width <= _vehicleWidth || height <= _vehicleHeight) {
|
|
|
|
|
return;
|
2023-09-19 19:04:33 +04:00
|
|
|
|
}
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
2023-10-03 11:53:51 +04:00
|
|
|
|
EntityLocomotiv = new EntityLocomotiv(speed, weight);
|
|
|
|
|
}
|
|
|
|
|
public bool CanMove(DirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityLocomotiv == null)
|
|
|
|
|
return false;
|
|
|
|
|
return direction switch
|
|
|
|
|
{
|
|
|
|
|
DirectionType.Left => _startPosX - EntityLocomotiv.Step > 0,
|
|
|
|
|
DirectionType.Up => _startPosY - EntityLocomotiv.Step > 0,
|
|
|
|
|
DirectionType.Right => _startPosX + EntityLocomotiv.Step < _pictureWidth,
|
|
|
|
|
DirectionType.Down => _startPosY -+ EntityLocomotiv.Step < _pictureHeight
|
|
|
|
|
};
|
2023-09-19 19:04:33 +04:00
|
|
|
|
}
|
|
|
|
|
public void SetPosition(int x,int y)
|
|
|
|
|
{
|
|
|
|
|
if (EntityLocomotiv == null) return;
|
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
|
|
|
|
if (x + _vehicleWidth >= _pictureWidth || y + _vehicleHeight >= _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = 1;
|
|
|
|
|
_startPosY = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityLocomotiv == null) return;
|
|
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case DirectionType.Left:
|
|
|
|
|
if (_startPosX - EntityLocomotiv.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosX -= (int)EntityLocomotiv.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DirectionType.Right:
|
|
|
|
|
if (_startPosX + EntityLocomotiv.Step + _vehicleWidth < _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX += (int)EntityLocomotiv.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DirectionType.Up:
|
|
|
|
|
if (_startPosY - EntityLocomotiv.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosY -= (int)EntityLocomotiv.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DirectionType.Down:
|
|
|
|
|
if (_startPosY + EntityLocomotiv.Step + _vehicleHeight < _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY += (int)EntityLocomotiv.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-03 11:53:51 +04:00
|
|
|
|
public virtual void DrawLoco(Graphics g)
|
2023-09-19 19:04:33 +04:00
|
|
|
|
{
|
|
|
|
|
if (EntityLocomotiv == null) return;
|
|
|
|
|
Pen penBody = new(EntityLocomotiv.ColorBody, 3);
|
|
|
|
|
Pen penWindow = new(EntityLocomotiv.ColorWindow, 3);
|
|
|
|
|
SolidBrush doorBrush = new(EntityLocomotiv.ColorFillBody);
|
|
|
|
|
Pen penWheel = new(EntityLocomotiv.ColorBody, 2);
|
2023-10-03 11:53:51 +04:00
|
|
|
|
|
2023-09-19 19:04:33 +04:00
|
|
|
|
//Body
|
|
|
|
|
g.DrawRectangle(penBody, _startPosX, _startPosY + _vehicleHeight - 50, _vehicleWidth - 10, _vehicleHeight - 80);
|
|
|
|
|
Point[] upBodyPoints = { new Point(_startPosX, _startPosY + 60), new Point(_startPosX + 10, _startPosY + 30), new Point(_startPosX + 150, _startPosY + 30), new Point(_startPosX + 160, _startPosY + 60) };
|
|
|
|
|
g.DrawPolygon(penBody, upBodyPoints);
|
|
|
|
|
//Door
|
|
|
|
|
g.DrawRectangle(penBody, _startPosX + _vehicleWidth / 2 - 15, _startPosY + 45, _vehicleWidth / 10, _vehicleHeight / 2 - 10);
|
|
|
|
|
g.FillRectangle(doorBrush, _startPosX + _vehicleWidth / 2 - 14, _startPosY + 46, _vehicleWidth / 10 - 1, _vehicleHeight / 2 - 12);
|
|
|
|
|
//Windows
|
|
|
|
|
int xWindow = _startPosX + 15;
|
|
|
|
|
int yWindow = _startPosY + 37;
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
{
|
|
|
|
|
g.DrawRectangle(penWindow, xWindow, yWindow, 15, 15);
|
|
|
|
|
xWindow += 25;
|
|
|
|
|
}
|
|
|
|
|
xWindow += 35;
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
{
|
|
|
|
|
g.DrawRectangle(penWindow, xWindow, yWindow, 15, 15);
|
|
|
|
|
xWindow += 25;
|
|
|
|
|
}
|
|
|
|
|
//wheels
|
|
|
|
|
int xWheel = _startPosX + 5;
|
|
|
|
|
int yWheel = _startPosY + _vehicleHeight - 20;
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
g.DrawEllipse(penWheel, xWheel, yWheel, 20, 20);
|
|
|
|
|
xWheel += 40;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|