PIbd-23-Kondratev-N.D.-Gaso.../GasolineTanker/ProjectGasolineTanker/DrawingTruck.cs
2024-10-03 00:16:11 +03:00

136 lines
5.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectGasolineTanker.Entities;
namespace ProjectGasolineTanker.DrawingObjects
{
public class DrawingTruck
{
public EntityTruck? EntityTruck { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _tankerWidth = 130;
protected readonly int _tankerHeight = 70;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _tankerWidth;
public int GetHeight => _tankerHeight;
public DrawingTruck(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _tankerWidth || height < _tankerHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityTruck = new EntityTruck(speed, weight, bodyColor);
}
protected DrawingTruck(int speed, double weight, Color bodyColor, int width, int height, int tankerWidth, int tankerHeight)
{
if (width < _tankerWidth || height < _tankerHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_tankerWidth = tankerWidth;
_tankerHeight = tankerHeight;
EntityTruck = new EntityTruck(speed, weight, bodyColor);
}
public void SetPosition(int x, int y)
{
if (x > _pictureWidth || y > _pictureHeight)
{
return;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityTruck == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
if (_startPosX - EntityTruck.Step > 0)
{
_startPosX -= (int)EntityTruck.Step;
}
break;
case DirectionType.Up:
if (_startPosY - EntityTruck.Step > 0)
{
_startPosY -= (int)EntityTruck.Step;
}
break;
case DirectionType.Right:
if (_startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth)
{
_startPosX += (int)EntityTruck.Step;
}
break;
case DirectionType.Down:
if (_startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight)
{
_startPosY += (int)EntityTruck.Step;
}
break;
}
}
public virtual void DrawTransport(Graphics g)
{
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityTruck.BodyColor);
g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 11, 71, 28);
g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 20, 71, 9);
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 11, 71, 28);
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 20, 71, 9);
Brush additionalBrush1 = new
SolidBrush(EntityTruck.BodyColor);
g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 24, 16);
g.FillRectangle(additionalBrush1, _startPosX + 124, _startPosY + 10, 9, 16);
g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 33, 16);
g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 26, 33, 13);
g.DrawLine(pen, _startPosX + 100, _startPosY + 26, _startPosX + 133, _startPosY + 39);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 24, 16);
g.DrawRectangle(pen, _startPosX + 124, _startPosY + 10, 9, 16);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 33, 16);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 26, 33, 13);
Brush additionalBrush2 = new
SolidBrush(EntityTruck.BodyColor);
g.FillRectangle(additionalBrush2, _startPosX + 4, _startPosY + 40, 130, 25);
g.DrawLine(pen, _startPosX + 4, _startPosY + 65, _startPosX + 25, _startPosY + 40);
Brush gr = new SolidBrush(Color.Gray);
g.FillEllipse(additionalBrush, _startPosX + 15, _startPosY + 50, 26, 26);
g.FillEllipse(additionalBrush, _startPosX + 110, _startPosY + 55, 22, 22);
g.FillEllipse(gr, _startPosX + 18, _startPosY + 53, 20, 20);
g.FillEllipse(gr, _startPosX + 112, _startPosY + 57, 18, 18);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 50, 26, 26);
g.DrawEllipse(pen, _startPosX + 110, _startPosY + 55, 22, 22);
}
public bool CanMove(DirectionType direction)
{
if (EntityTruck == null)
{
return false;
}
return direction switch
{
DirectionType.Left => _startPosX - EntityTruck.Step > 0,
DirectionType.Up => _startPosY - EntityTruck.Step > 0,
DirectionType.Right => _startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth,
DirectionType.Down => _startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight,
_ => false,
};
}
}
}