Create class: drawing electroLocomotive
This commit is contained in:
parent
abc845461b
commit
9bd4a33db6
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectElectricLocomotive.DrawingObjects;
|
||||
using ProjectElectricLocomotive.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -6,83 +8,22 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
public class DrawingElectricLocomotive
|
||||
public class DrawingElectricLocomotive : DrawingLocomotive
|
||||
{
|
||||
public EntityElectricLocomotive? EntityElectricLocomotive;
|
||||
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
private readonly int _locoWidth = 150;
|
||||
private readonly int _locoHeight = 50;
|
||||
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool horns, bool seifbatteries,
|
||||
int width, int height)
|
||||
public DrawingElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit,
|
||||
bool horns, bool seifBatteries, int width, int height) : base(speed, weight, bodyColor, width, height, 150, 50)
|
||||
{
|
||||
|
||||
if (width < _locoWidth || height < _locoHeight)
|
||||
|
||||
if (EntityLocomotive != null)
|
||||
{
|
||||
return false;
|
||||
EntityLocomotive = new EntityElectricLocomotive(speed, width, bodyColor, additionalColor, horns, seifBatteries);
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityElectricLocomotive = new EntityElectricLocomotive();
|
||||
EntityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, horns, seifbatteries);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (x < 0 || x + _locoWidth > _pictureWidth)
|
||||
{
|
||||
x = 20;
|
||||
}
|
||||
if (y < 0 || y + _locoHeight > _pictureHeight)
|
||||
{
|
||||
y = 20;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityElectricLocomotive == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityElectricLocomotive.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityElectricLocomotive.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityElectricLocomotive.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityElectricLocomotive.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntityElectricLocomotive.Step + _locoWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityElectricLocomotive.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntityElectricLocomotive.Step + _locoHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityElectricLocomotive.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityElectricLocomotive == null)
|
||||
if (EntityLocomotive is not EntityElectricLocomotive electricLocomotive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -90,10 +31,10 @@ namespace ElectricLocomotive
|
||||
Pen pen = new(Color.Black);
|
||||
Brush blackBrush = new SolidBrush(Color.Black);
|
||||
Brush windows = new SolidBrush(Color.LightBlue);
|
||||
Brush bodyColor = new SolidBrush(EntityElectricLocomotive.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(EntityElectricLocomotive.AdditionalColor);
|
||||
Brush bodyColor = new SolidBrush(electricLocomotive.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(electricLocomotive.AdditionalColor);
|
||||
|
||||
if (EntityElectricLocomotive.Horns)
|
||||
if (electricLocomotive.Horns)
|
||||
{
|
||||
//horns
|
||||
g.FillRectangle(blackBrush, _startPosX + 30, _startPosY + 15, 20, 5);
|
||||
@ -103,22 +44,7 @@ namespace ElectricLocomotive
|
||||
g.DrawLine(pen, _startPosX + 50, _startPosY + 10, _startPosX + 40, _startPosY);
|
||||
}
|
||||
|
||||
//локомотив
|
||||
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),
|
||||
}
|
||||
);
|
||||
|
||||
if (EntityElectricLocomotive.Seifbatteries)
|
||||
if (electricLocomotive.SeifBatteries)
|
||||
{
|
||||
g.DrawPolygon(pen, new Point[]
|
||||
{
|
||||
@ -130,21 +56,8 @@ namespace ElectricLocomotive
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
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[]
|
||||
{
|
||||
@ -211,7 +124,13 @@ namespace ElectricLocomotive
|
||||
g.DrawLine(pen, _startPosX + 80, _startPosY + 40, _startPosX + 90, _startPosY + 40);
|
||||
g.FillRectangle(windows, _startPosX + 95, _startPosY + 30, 10, 5);
|
||||
g.FillRectangle(windows, _startPosX + 115, _startPosY + 30, 10, 5);
|
||||
g.FillRectangle(windows, _startPosX + 135, _startPosY + 30, 10, 5);
|
||||
g.FillRectangle(windows, _startPosX + 135, _startPosY + 30, 10, 5);*/
|
||||
|
||||
|
||||
base.DrawTransport(g);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,29 +1,23 @@
|
||||
using System;
|
||||
using ProjectElectricLocomotive.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
namespace ProjectElectricLocomotive.Entities
|
||||
{
|
||||
public class EntityElectricLocomotive
|
||||
public class EntityElectricLocomotive : EntityLocomotive
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public Color AdditionalColor { get; private set; }
|
||||
public bool Horns { get; private set; }
|
||||
public bool Seifbatteries { get; private set; }
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool horns, bool seifbatteries)
|
||||
public bool SeifBatteries { get; private set; }
|
||||
public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool horns,
|
||||
bool seifBatteries) : base(speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Horns = horns;
|
||||
Seifbatteries = seifbatteries;
|
||||
SeifBatteries = seifBatteries;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user