PIbd-23-Kondratev-N.D.-Gaso.../GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs
2024-10-03 00:19:45 +03:00

183 lines
6.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectGasolineTanker.Entities;
using ProjectGasolineTanker.MovementStratg;
namespace ProjectGasolineTanker.Drawings
{
public class DrawingTruck
{
public IMoveableObject GetMoveableObject => new DrawingObjectTruck(this);
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)
{
// TODO: Продумать проверки
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,// TODO: Продумать логику
//вниз
DirectionType.Down => _startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight,// TODO: Продумать логику
_ => false,
};
}
}
}