PIbd-22-Romanov-E.V.-Hoisti.../HoistingCrane/DrawingHoistingCrane.cs

147 lines
6.3 KiB
C#
Raw Normal View History

2022-10-10 17:33:38 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoistingCrane
{
internal class DrawingHoistingCrane
{
public EntityHoistingCrane HoistingCrane { get; private set; }
private float _startPosX;
private float _startPosY;
private int? _pictureWidth = null;
private int? _pictureHeight = null;
private readonly int _hoistingCraneWidth = 80;
private readonly int _hoistingCraneHeight = 50;
public void Init(int speed, float weight, Color bodyColor)
{
HoistingCrane = new EntityHoistingCrane();
HoistingCrane.Init(speed, weight, bodyColor);
}
public void SetPosition(int x, int y, int width, int height)
{
// TODO checks
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
public void MoveTransport(Direction direction)
{
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
{
return;
}
switch (direction)
{
// вправо
case Direction.Right:
if (_startPosX + _hoistingCraneWidth + HoistingCrane.Step < _pictureWidth)
{
_startPosX += HoistingCrane.Step;
}
break;
//влево
case Direction.Left:
if (_startPosX - HoistingCrane.Step > 0)
{
_startPosX -= HoistingCrane.Step;
}
break;
//вверх
case Direction.Up:
if (_startPosY - HoistingCrane.Step > 0)
{
_startPosY -= HoistingCrane.Step;
}
break;
//вниз
case Direction.Down:
if (_startPosY + _hoistingCraneHeight + HoistingCrane.Step < _pictureHeight)
{
_startPosY += HoistingCrane.Step;
}
break;
}
}
public void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
Pen pen = new Pen(Color.Black);
//границы
g.DrawRectangle(pen, _startPosX, _startPosY + 25, 75, 20);
g.DrawRectangle(pen, _startPosX, _startPosY, 25, 25);
g.DrawRectangle(pen, _startPosX + 4, _startPosY + 4, 17, 17);
g.DrawRectangle(pen, _startPosX + 52, _startPosY + 7, 6, 18);
g.DrawEllipse(pen, _startPosX - 5, _startPosY + 45, 20, 20);
g.DrawEllipse(pen, _startPosX + 63, _startPosY + 45, 20, 20);
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45, 68, 20);
g.DrawEllipse(pen, _startPosX - 1, _startPosY + 46, 18, 18);
g.DrawEllipse(pen, _startPosX + 62, _startPosY + 46, 18, 18);
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 53, 10, 10);
g.DrawEllipse(pen, _startPosX + 35, _startPosY + 53, 10, 10);
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 53, 10, 10);
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 45, 4, 6);
g.DrawRectangle(pen, _startPosX + 45, _startPosY + 45, 4, 6);
//корпус
Brush br = new SolidBrush(HoistingCrane?.BodyColor ?? Color.Black);
g.FillRectangle(br, _startPosX, _startPosY + 25, 75, 25);
g.FillRectangle(br, _startPosX, _startPosY, 25, 25);
//окно
Brush brBlue = new SolidBrush(Color.Blue);
g.FillRectangle(brBlue, _startPosX + 4, _startPosY + 4, 17, 17);
//выхлопная труба
Brush brBrown = new SolidBrush(Color.DarkGray);
g.FillRectangle(brBrown, _startPosX + 52, _startPosY + 7, 6, 18);
//гусеница
Brush brDarkGray = new SolidBrush(Color.DarkGray);
g.FillEllipse(brDarkGray, _startPosX - 5, _startPosY + 45, 20, 20);
g.FillEllipse(brDarkGray, _startPosX + 63, _startPosY + 45, 20, 20);
g.FillRectangle(brDarkGray, _startPosX + 5, _startPosY + 45, 68, 20);
Brush brBlack = new SolidBrush(Color.Black);
g.FillEllipse(brBlack, _startPosX - 1, _startPosY + 46, 18, 18);
g.FillEllipse(brBlack, _startPosX + 62, _startPosY + 46, 18, 18);
g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 53, 10, 10);
g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 53, 10, 10);
g.FillEllipse(brBlack, _startPosX + 50, _startPosY + 53, 10, 10);
g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 45, 4, 6);
g.FillRectangle(brBlack, _startPosX + 45, _startPosY + 45, 4, 6);
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _hoistingCraneWidth || _pictureHeight <= _hoistingCraneHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _hoistingCraneWidth > _pictureWidth)
{
_startPosX = _pictureWidth.Value - _hoistingCraneWidth;
}
if (_startPosY + _hoistingCraneHeight > _pictureHeight)
{
_startPosY = _pictureHeight.Value - _hoistingCraneHeight;
}
}
}
}