PIbd-23-Kondratev-N.D.-Gaso.../GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs

189 lines
6.5 KiB
C#
Raw Normal View History

2024-10-03 01:16:11 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectGasolineTanker.Entities;
2024-10-03 01:40:53 +04:00
using ProjectGasolineTanker.MovementStratg;
2024-10-03 01:16:11 +04:00
2024-10-03 01:40:53 +04:00
namespace ProjectGasolineTanker.Drawings
2024-10-03 01:16:11 +04:00
{
2024-10-03 01:43:12 +04:00
2024-10-03 01:16:11 +04:00
public class DrawingTruck
{
2024-10-03 01:40:53 +04:00
public IMoveableObject GetMoveableObject => new DrawingObjectTruck(this);
2024-10-03 01:16:11 +04:00
public EntityTruck? EntityTruck { get; protected set; }
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
private int _pictureWidth;
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
private int _pictureHeight;
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
protected int _startPosX;
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
protected int _startPosY;
2024-10-03 01:40:53 +04:00
protected readonly int _tankerWidth = 130;
protected readonly int _tankerHeight = 70;
2024-10-03 01:43:12 +04:00
2024-10-03 01:16:11 +04:00
public int GetPosX => _startPosX;
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
public int GetPosY => _startPosY;
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
public int GetWidth => _tankerWidth;
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
public int GetHeight => _tankerHeight;
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
public DrawingTruck(int speed, double weight, Color bodyColor, int width, int height)
{
2024-10-03 01:44:06 +04:00
// TODO: Продумать проверки
2024-10-03 01:16:11 +04:00
if (width < _tankerWidth || height < _tankerHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityTruck = new EntityTruck(speed, weight, bodyColor);
}
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
protected DrawingTruck(int speed, double weight, Color bodyColor, int width, int height, int tankerWidth, int tankerHeight)
{
2024-10-03 01:43:12 +04:00
// TODO: Продумать проверки
2024-10-03 01:16:11 +04:00
if (width < _tankerWidth || height < _tankerHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_tankerWidth = tankerWidth;
_tankerHeight = tankerHeight;
EntityTruck = new EntityTruck(speed, weight, bodyColor);
}
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
public void SetPosition(int x, int y)
{
if (x > _pictureWidth || y > _pictureHeight)
{
return;
}
_startPosX = x;
_startPosY = y;
}
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityTruck == null)
{
return;
}
switch (direction)
{
2024-10-03 01:40:53 +04:00
//влево
2024-10-03 01:16:11 +04:00
case DirectionType.Left:
if (_startPosX - EntityTruck.Step > 0)
{
_startPosX -= (int)EntityTruck.Step;
}
break;
2024-10-03 01:40:53 +04:00
//вверх
2024-10-03 01:16:11 +04:00
case DirectionType.Up:
if (_startPosY - EntityTruck.Step > 0)
{
_startPosY -= (int)EntityTruck.Step;
}
break;
2024-10-03 01:40:53 +04:00
// вправо
2024-10-03 01:16:11 +04:00
case DirectionType.Right:
if (_startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth)
{
_startPosX += (int)EntityTruck.Step;
}
break;
2024-10-03 01:40:53 +04:00
//вниз
2024-10-03 01:16:11 +04:00
case DirectionType.Down:
if (_startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight)
{
_startPosY += (int)EntityTruck.Step;
}
break;
}
}
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
public virtual void DrawTransport(Graphics g)
{
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityTruck.BodyColor);
2024-10-03 01:40:53 +04:00
2024-10-03 01:44:06 +04:00
g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 11, 71, 28); //канистра-бак
g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 20, 71, 9); //полосы
2024-10-03 01:40:53 +04:00
2024-10-03 01:44:06 +04:00
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 11, 71, 28); //канистра-бак
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 20, 71, 9); //полосы
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
Brush additionalBrush1 = new
SolidBrush(EntityTruck.BodyColor);
2024-10-03 01:44:06 +04:00
//кабина
2024-10-03 01:16:11 +04:00
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);
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
g.DrawLine(pen, _startPosX + 100, _startPosY + 26, _startPosX + 133, _startPosY + 39);
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
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);
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
Brush additionalBrush2 = new
SolidBrush(EntityTruck.BodyColor);
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
g.FillRectangle(additionalBrush2, _startPosX + 4, _startPosY + 40, 130, 25);
g.DrawLine(pen, _startPosX + 4, _startPosY + 65, _startPosX + 25, _startPosY + 40);
2024-10-03 01:40:53 +04:00
2024-10-03 01:44:06 +04:00
//колёса
2024-10-03 01:16:11 +04:00
Brush gr = new SolidBrush(Color.Gray);
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
g.FillEllipse(additionalBrush, _startPosX + 15, _startPosY + 50, 26, 26);
g.FillEllipse(additionalBrush, _startPosX + 110, _startPosY + 55, 22, 22);
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
g.FillEllipse(gr, _startPosX + 18, _startPosY + 53, 20, 20);
g.FillEllipse(gr, _startPosX + 112, _startPosY + 57, 18, 18);
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 50, 26, 26);
g.DrawEllipse(pen, _startPosX + 110, _startPosY + 55, 22, 22);
}
2024-10-03 01:40:53 +04:00
2024-10-03 01:16:11 +04:00
public bool CanMove(DirectionType direction)
{
if (EntityTruck == null)
{
return false;
}
return direction switch
{
2024-10-03 01:40:53 +04:00
//влево
2024-10-03 01:16:11 +04:00
DirectionType.Left => _startPosX - EntityTruck.Step > 0,
2024-10-03 01:40:53 +04:00
//вверх
2024-10-03 01:16:11 +04:00
DirectionType.Up => _startPosY - EntityTruck.Step > 0,
2024-10-03 01:40:53 +04:00
// вправо
2024-10-03 01:43:12 +04:00
DirectionType.Right => _startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth,// TODO: Продумать логику
2024-10-03 01:40:53 +04:00
//вниз
2024-10-03 01:43:12 +04:00
DirectionType.Down => _startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight,// TODO: Продумать логику
2024-10-03 01:16:11 +04:00
_ => false,
};
}
2024-10-03 01:43:12 +04:00
public void ChangePictureSize(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
}
2024-10-03 01:16:11 +04:00
}
2024-10-03 01:40:53 +04:00
}