121 lines
5.1 KiB
C#
121 lines
5.1 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; private set; }
|
|||
|
private int _pictureWidth;
|
|||
|
private int _pictureHeight;
|
|||
|
private int _startPosX;
|
|||
|
private int _startPosY;
|
|||
|
private readonly int _vehicleWidth = 170;
|
|||
|
private readonly int _vehicleHeight = 110;
|
|||
|
|
|||
|
public bool Init(int speed, double weight,int width,int height)
|
|||
|
{
|
|||
|
if (width <= _vehicleWidth || height <= _vehicleHeight) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
_pictureWidth = width;
|
|||
|
_pictureHeight = height;
|
|||
|
EntityLocomotiv = new EntityLocomotiv();
|
|||
|
EntityLocomotiv.Init(speed, weight);
|
|||
|
return true;
|
|||
|
}
|
|||
|
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 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);
|
|||
|
SolidBrush batteryBrush = new(EntityLocomotiv.ColorBody);
|
|||
|
//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);
|
|||
|
//Roga
|
|||
|
g.DrawLine(penBody, new Point(_startPosX + _vehicleWidth / 2, _startPosY + 30), new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15));
|
|||
|
g.DrawLine(penBody, new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15), new Point(_startPosX + _vehicleWidth / 2, _startPosY));
|
|||
|
//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;
|
|||
|
}
|
|||
|
//battery
|
|||
|
Point[] batteryPoints = { new Point(_startPosX + _vehicleWidth - 10,_startPosY + _vehicleHeight - 25), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 20), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 55), new Point(_startPosX + _vehicleWidth - 10, _startPosY + _vehicleHeight - 50) };
|
|||
|
g.FillPolygon(batteryBrush, batteryPoints);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|