Created class "DrawingLoco

This commit is contained in:
ekallin 2023-09-23 20:12:55 +04:00
parent 9965a02c98
commit abc845461b
2 changed files with 176 additions and 1 deletions

View File

@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ElectricLocomotive;
using ProjectElectricLocomotive.Entities;
using ProjectElectricLocomotive.Properties;
namespace ProjectElectricLocomotive.DrawingObjects
{
public class DrawingLocomotive
{
public EntityLocomotive? EntityLocomotive { get; protected set; }
private int _pictureHeight;
private int _pictureWidth;
protected int _startPosX;
protected int _startPosY;
protected readonly int _locoWidth = 150;
protected readonly int _locoHeight = 50;
public DrawingLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
{
if(EntityLocomotive == null)
{
return;
}
_locoWidth = width;
_locoHeight = heigth;
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
}
protected DrawingLocomotive(int speed, double weight, Color bodyColor, int width,
int height, int locoWidth, int locoHeight)
{
if (EntityLocomotive == null)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_locoWidth = locoWidth;
_locoHeight = locoHeight;
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
}
//Установка позиции
public void SetPosition(int x, int y)
{
if(x < 0 || x + _locoWidth > _pictureWidth)
{
x = _pictureWidth - _locoWidth;
}
if (y < 0 || y + _locoHeight > _pictureHeight)
{
y = _pictureHeight - _locoHeight;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(DirectionType direction)
{
if (EntityLocomotive == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
if (_startPosX - EntityLocomotive.Step > 0)
{
_startPosX -= (int)EntityLocomotive.Step;
}
break;
case DirectionType.Up:
if (_startPosY - EntityLocomotive.Step > 0)
{
_startPosY -= (int)EntityLocomotive.Step;
}
break;
case DirectionType.Right:
if (_startPosX + EntityLocomotive.Step + _locoWidth < _pictureWidth)
{
_startPosX += (int)EntityLocomotive.Step;
}
break;
case DirectionType.Down:
if (_startPosY + EntityLocomotive.Step + _locoHeight < _pictureHeight)
{
_startPosY += (int)EntityLocomotive.Step;
}
break;
}
}
public virtual void DrawTransport(Graphics g)
{
{
if (EntityLocomotive == null) return;
}
Pen pen = new(Color.Black);
Brush blackBrush = new SolidBrush(Color.Black);
Brush windows = new SolidBrush(Color.LightBlue);
Brush bodyColor = new SolidBrush(EntityLocomotive.BodyColor);
//локомотив
g.FillPolygon(bodyColor, new Point[]
{
new Point(_startPosX, _startPosY + 40),
new Point(_startPosX, _startPosY + 30),
new Point(_startPosX + 20, _startPosY + 20),
new Point(_startPosX + 70, _startPosY + 20),
new Point(_startPosX +80, _startPosY + 30),
new Point(_startPosX +80, _startPosY + 40),
new Point(_startPosX +75, _startPosY + 45),
new Point(_startPosX +5, _startPosY + 45),
new Point(_startPosX, _startPosY + 40),
}
);
g.DrawPolygon(pen, new Point[]
{
new Point(_startPosX, _startPosY + 40),
new Point(_startPosX, _startPosY + 30),
new Point(_startPosX + 20, _startPosY + 20),
new Point(_startPosX + 70, _startPosY + 20),
new Point(_startPosX +80, _startPosY + 30),
new Point(_startPosX +80, _startPosY + 40),
new Point(_startPosX +75, _startPosY + 45),
new Point(_startPosX +5, _startPosY + 45),
new Point(_startPosX, _startPosY + 40),
}
);
//окошки
g.FillPolygon(windows, new Point[]
{
new Point(_startPosX + 10, _startPosY + 30),
new Point(_startPosX +15, _startPosY + 25),
new Point(_startPosX + 20, _startPosY + 25),
new Point(_startPosX + 20, _startPosY + 30),
new Point(_startPosX +10, _startPosY + 30),
}
);
g.DrawPolygon(pen, new Point[]
{
new Point(_startPosX + 10, _startPosY + 30),
new Point(_startPosX +15, _startPosY + 25),
new Point(_startPosX + 20, _startPosY + 25),
new Point(_startPosX + 20, _startPosY + 30),
new Point(_startPosX +10, _startPosY + 30),
}
);
g.FillRectangle(windows, _startPosX + 25, _startPosY + 25, 10, 5);
g.DrawRectangle(pen, _startPosX + 25, _startPosY + 25, 10, 5);
//обязательные колеса
//loco
g.FillEllipse(blackBrush, _startPosX + 10, _startPosY + 45, 5, 5);
g.FillEllipse(blackBrush, _startPosX + 25, _startPosY + 45, 5, 5);
g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 45, 5, 5);
g.FillEllipse(blackBrush, _startPosX + 65, _startPosY + 45, 5, 5);
}
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive
namespace ProjectElectricLocomotive.Entities
{
public class EntityLocomotive
{