152 lines
5.9 KiB
C#
152 lines
5.9 KiB
C#
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
|
|
{
|
|
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 IMoveableObject GetMoveableObject => new DrawingObjectLocomotiv(this);
|
|
|
|
public DrawingLocomotiv(int speed, double weight,int width,int height, Color mainColor, Color dopColor)
|
|
{
|
|
if (width <= _vehicleWidth || height <= _vehicleHeight) {
|
|
return;
|
|
}
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
EntityLocomotiv = new EntityLocomotiv(speed, weight, mainColor, dopColor);
|
|
}
|
|
protected DrawingLocomotiv(int speed, double weight,int width,int height, int vehicleHeight, int vehicleWidth, Color mainColor, Color dopColor)
|
|
{
|
|
if (width <= _vehicleWidth || height <= _vehicleHeight) {
|
|
return;
|
|
}
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
EntityLocomotiv = new EntityLocomotiv(speed, weight, mainColor, dopColor);
|
|
}
|
|
|
|
public void ChangeColor(Color col)
|
|
{
|
|
if (EntityLocomotiv == null)
|
|
return;
|
|
EntityLocomotiv.ColorBody = col;
|
|
EntityLocomotiv.ColorWindow = col;
|
|
}
|
|
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
|
|
};
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
|
|
{
|
|
_pictureHeight = pictureBoxHeight;
|
|
_pictureWidth = pictureBoxWidth;
|
|
}
|
|
public virtual void DrawLoco(Graphics g)
|
|
{
|
|
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);
|
|
|
|
//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;
|
|
}
|
|
}
|
|
}
|
|
}
|