144 lines
5.5 KiB
C#
144 lines
5.5 KiB
C#
namespace ProjectLainer
|
|
{
|
|
public class DrawningLainer
|
|
{
|
|
public EntityLainer? EntityLainer { get; private set; }
|
|
private int _pictureWidth;
|
|
private int _pictureHeight;
|
|
private int _startPosX;
|
|
private int _startPosY;
|
|
private readonly int _LainerWidth = 150;
|
|
private readonly int _LainerHeight = 80;
|
|
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool ispool, bool addDecks, int width, int height)
|
|
{
|
|
if(width <= _LainerWidth || height <= _LainerHeight)
|
|
{
|
|
return false;
|
|
}
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
EntityLainer = new EntityLainer();
|
|
EntityLainer.Init(speed, weight, bodyColor, additionalColor, ispool, addDecks);
|
|
return true;
|
|
}
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
if(x + _LainerWidth < _pictureWidth && x + _LainerWidth > 0)
|
|
{
|
|
_startPosX = x;
|
|
}
|
|
if (y + _LainerHeight < _pictureHeight && y + _LainerHeight > 0)
|
|
{
|
|
_startPosY = y;
|
|
}
|
|
}
|
|
public void MoveTransport(DirectionType direction)
|
|
{
|
|
if (EntityLainer == null)
|
|
|
|
{
|
|
return;
|
|
}
|
|
switch (direction)
|
|
{
|
|
//âëåâî
|
|
case DirectionType.Left:
|
|
if (_startPosX - EntityLainer.Step > 0)
|
|
{
|
|
_startPosX -= (int)EntityLainer.Step;
|
|
}
|
|
else
|
|
{
|
|
_startPosX = 1;
|
|
}
|
|
break;
|
|
//ââåðõ
|
|
case DirectionType.Up:
|
|
if (_startPosY - EntityLainer.Step > 0)
|
|
{
|
|
_startPosY -= (int)EntityLainer.Step;
|
|
}
|
|
else
|
|
{
|
|
_startPosY = 1;
|
|
}
|
|
break;
|
|
// âïðàâî
|
|
case DirectionType.Right:
|
|
if (_startPosX + EntityLainer.Step <= _pictureWidth - _LainerWidth)
|
|
{
|
|
_startPosX += (int)EntityLainer.Step;
|
|
}
|
|
else
|
|
{
|
|
_startPosX = _pictureWidth - _LainerWidth;
|
|
}
|
|
break;
|
|
//âíèç
|
|
case DirectionType.Down:
|
|
if (_startPosY + EntityLainer.Step <= _pictureHeight - _LainerHeight)
|
|
{
|
|
_startPosY += (int)EntityLainer.Step;
|
|
}
|
|
else
|
|
{
|
|
_startPosY = _pictureHeight - _LainerHeight;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
public void DrawTransport(Graphics g)
|
|
{
|
|
if (EntityLainer == null)
|
|
{
|
|
return;
|
|
}
|
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
|
Pen pen = new(Color.Black);
|
|
Brush additionalBrush = new
|
|
SolidBrush(EntityLainer.AdditionalColor);
|
|
var brush = new SolidBrush(Color.Black);
|
|
// äîï ïàëóáû è îòðèñîâêà òðóá
|
|
Rectangle smokestack1 = new Rectangle(_startPosX + 20, _startPosY, 20, 50);
|
|
Rectangle smokestack2 = new Rectangle(_startPosX + 60, _startPosY, 20, 50);
|
|
g.FillRectangle(brush, smokestack1);
|
|
g.FillRectangle(brush, smokestack2);
|
|
if (EntityLainer.Decks)
|
|
{
|
|
Rectangle deck2 = new Rectangle(_startPosX + 10, _startPosY + 10, _LainerWidth - 18, 20);
|
|
g.FillRectangle(additionalBrush, deck2);
|
|
for (int i = 2; i < 6; i++)
|
|
{
|
|
g.FillEllipse(brBlue, _startPosX + i * 16, _startPosY + 15, 12, 12);
|
|
}
|
|
}
|
|
//ãðàíèöû ëàéíåðà
|
|
pen = new(Color.Red);
|
|
brush = new SolidBrush(Color.Red);
|
|
Point point1 = new Point(_startPosX, _startPosY + 50);
|
|
Point point2 = new Point(_startPosX + _LainerWidth, _startPosY+50);
|
|
Point point3 = new Point(_startPosX + 20, _startPosY+80);
|
|
Point point4 = new Point(_startPosX + 80, _startPosY + 80);
|
|
Point[] points = { point1, point2, point4, point3};
|
|
g.DrawPolygon(pen, points);
|
|
g.FillPolygon(brush, points);
|
|
//1 ïàëóáà
|
|
brush = new SolidBrush(Color.Green);
|
|
Rectangle deck = new Rectangle(_startPosX + 5, _startPosY + 30, _LainerWidth - 10, 20);
|
|
g.FillRectangle(brush,deck);
|
|
//ñòåêëà
|
|
for (int i = 1; i < 7; i++)
|
|
{
|
|
g.FillEllipse(brBlue, _startPosX + i*16, _startPosY + 33, 14, 14);
|
|
}
|
|
// áàññåéí
|
|
if (EntityLainer.Pool)
|
|
{
|
|
g.FillEllipse(brBlue, _startPosX + _LainerWidth - 35, _startPosY + _LainerHeight - 55, 35, 12);
|
|
brush = new SolidBrush(Color.DarkGray);
|
|
Rectangle rect2 = new Rectangle(_startPosX + _LainerWidth - 35, _startPosY + _LainerHeight - 50, 35, 20);
|
|
g.FillRectangle(brush, rect2);
|
|
}
|
|
}
|
|
}
|
|
} |