208 lines
6.2 KiB
C#
208 lines
6.2 KiB
C#
|
|
|
|
namespace ProjectBulldozer
|
|
{
|
|
internal class DrawningBulldozer
|
|
{
|
|
|
|
public EntityBulldozer? EntityBulldozer { get; private set; }
|
|
|
|
private int _pictureWidth;
|
|
|
|
private int _pictureHeight;
|
|
|
|
private int _startPosX;
|
|
|
|
private int _startPosY;
|
|
|
|
private readonly int _BulldozerWidth = 180;
|
|
|
|
private readonly int _BulldozerHeight = 140;
|
|
|
|
public bool Init(int speed, double weight, Color bodyColor, Color
|
|
additionalColor, bool additionalEngine, bool additionalCompartment, int width, int height)
|
|
{
|
|
if (_pictureWidth < _BulldozerWidth | _pictureHeight < _BulldozerHeight)
|
|
{
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
EntityBulldozer = new EntityBulldozer();
|
|
EntityBulldozer.Init(speed, weight, bodyColor, additionalColor,
|
|
additionalEngine, additionalCompartment);
|
|
return true;
|
|
}
|
|
else return false;
|
|
}
|
|
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
if (_startPosY + _BulldozerHeight < _pictureHeight)
|
|
_startPosY = y;
|
|
else
|
|
_startPosY = _pictureHeight - _BulldozerHeight;
|
|
if (_startPosX + _BulldozerWidth < _pictureWidth)
|
|
_startPosX = x;
|
|
else
|
|
_startPosX = _pictureWidth - _BulldozerWidth;
|
|
}
|
|
|
|
public void MoveTransport(Direction direction)
|
|
{
|
|
if (EntityBulldozer == null)
|
|
{
|
|
return;
|
|
}
|
|
switch (direction)
|
|
{
|
|
//влево
|
|
case Direction.Left:
|
|
if (_startPosX - EntityBulldozer.Step > 0)
|
|
{
|
|
_startPosX -= (int)EntityBulldozer.Step;
|
|
}
|
|
else _startPosX = 0;
|
|
break;
|
|
//вверх
|
|
case Direction.Up:
|
|
if (_startPosY - EntityBulldozer.Step > 0)
|
|
{
|
|
_startPosY -= (int)EntityBulldozer.Step;
|
|
}
|
|
else _startPosY = 0;
|
|
break;
|
|
// вправо
|
|
case Direction.Right:
|
|
if (_startPosX + _BulldozerWidth + EntityBulldozer.Step < _pictureWidth)
|
|
{
|
|
_startPosX += (int)EntityBulldozer.Step;
|
|
}
|
|
else _startPosX = _pictureWidth - _BulldozerWidth;
|
|
break;
|
|
//вниз
|
|
case Direction.Down:
|
|
if (_startPosY + _BulldozerHeight + EntityBulldozer.Step < _pictureHeight)
|
|
{
|
|
_startPosY += (int)EntityBulldozer.Step;
|
|
}
|
|
else _startPosY = _pictureHeight - _BulldozerHeight;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void DrawTransport(Graphics g)
|
|
{
|
|
if (EntityBulldozer == null)
|
|
{
|
|
return;
|
|
}
|
|
Pen pen = new(Color.Black);
|
|
Brush brush = new SolidBrush(Color.Black);
|
|
Brush bl = new SolidBrush(EntityBulldozer.AdditionalColor);
|
|
Brush bodyBrush = new SolidBrush(EntityBulldozer.BodyColor);
|
|
Brush bodyBrush2 = new SolidBrush(EntityBulldozer.AdditionalColor);
|
|
|
|
|
|
|
|
|
|
//основное тело
|
|
g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 40, 120, 60);
|
|
|
|
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 40, 120, 60);
|
|
|
|
|
|
|
|
//Гусеницы
|
|
Brush gg = new SolidBrush(Color.LightGray);
|
|
g.FillEllipse(gg, _startPosX + 23, _startPosY + 101, 118, 35);
|
|
g.DrawEllipse(pen, _startPosX + 23, _startPosY + 101, 118, 35);
|
|
|
|
|
|
|
|
|
|
g.DrawEllipse(pen, _startPosX + 26, _startPosY + 103, 110, 30);
|
|
|
|
//катки в гусеницах
|
|
Brush gr = new SolidBrush(Color.Gray);
|
|
g.FillEllipse(gr, _startPosX + 40, _startPosY + 108, 20, 20);
|
|
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 108, 20, 20);
|
|
|
|
|
|
g.FillEllipse(gr, _startPosX + 65, _startPosY + 110, 20, 20);
|
|
g.DrawEllipse(pen, _startPosX + 65, _startPosY + 110, 20, 20);
|
|
|
|
g.FillEllipse(gr, _startPosX + 115, _startPosY + 110, 15, 15);
|
|
g.DrawEllipse(pen, _startPosX + 115, _startPosY + 110, 15, 15);
|
|
|
|
g.FillEllipse(gr, _startPosX + 90, _startPosY + 110, 20, 20);
|
|
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 110, 20, 20);
|
|
|
|
|
|
|
|
|
|
//кабина водителя
|
|
g.FillRectangle(bodyBrush2, _startPosX + 20, _startPosY, 40, 40);
|
|
g.DrawRectangle(pen, _startPosX + 20, _startPosY, 40, 40);
|
|
|
|
|
|
//выхлопная труба
|
|
Brush brBr = new SolidBrush(Color.Brown);
|
|
|
|
g.FillRectangle(brBr, _startPosX + 110, _startPosY, 15, 40);
|
|
g.DrawRectangle(pen, _startPosX + 110, _startPosY, 15, 40);
|
|
|
|
|
|
|
|
//Brush bl = new SolidBrush(Color.LightYellow);
|
|
/////////отвал
|
|
///
|
|
Point[] Otval =
|
|
{
|
|
new Point(_startPosX + 142, _startPosY + 70),
|
|
new Point(_startPosX + 172, _startPosY + 130),
|
|
new Point(_startPosX+ 142, _startPosY + 130),
|
|
|
|
|
|
};
|
|
|
|
g.FillPolygon(bl, Otval);
|
|
g.DrawPolygon(pen, Otval);
|
|
|
|
|
|
|
|
Brush black = new SolidBrush(Color.Black);
|
|
Point[] Rihl =
|
|
{
|
|
new Point(_startPosX + 18 , _startPosY + 60),
|
|
new Point(_startPosX + 18, _startPosY + 80),
|
|
new Point(_startPosX, _startPosY + 120),
|
|
|
|
};
|
|
|
|
g.FillPolygon(black, Rihl);
|
|
g.DrawPolygon(pen, Rihl);
|
|
|
|
|
|
|
|
Point[] Ttt =
|
|
{
|
|
new Point(_startPosX + 18 , _startPosY + 80),
|
|
new Point(_startPosX + 18, _startPosY + 120),
|
|
new Point(_startPosX, _startPosY + 50),
|
|
|
|
};
|
|
g.FillPolygon(black, Ttt);
|
|
g.DrawPolygon(pen, Ttt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|