using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.Pkcs; using System.Text; using System.Threading.Tasks; using Lab.Entities; using Lab.MovementStrategy; namespace Lab.DrawningObjects { public class DrawTanker { public BaseTanker? _gasolineTanker { get; protected set; } protected int _pictureWidth; protected int _pictureHeight; protected int _startPosX; protected int _startPosY; protected readonly int _carWidth = 100; protected readonly int _carHeight = 80; public int GetPosX => _startPosX; public int GetPosY => _startPosY; public int GetWidth => _carWidth; public int GetHeight => _carHeight; public bool CanMove(Direction direction) { if (_gasolineTanker == null) return false; return direction switch { Direction.Left => _startPosX - _gasolineTanker.Step > 0, Direction.Up => _startPosY - _gasolineTanker.Step > 0, Direction.Right => _startPosX + _carWidth + _gasolineTanker.Step < _pictureWidth, Direction.Down => _startPosY + _carHeight + _gasolineTanker.Step < _pictureHeight, _ => false }; } // Конструктор класса public DrawTanker(int speed, double weight, Color bodyColor, int width, int height) { _pictureHeight = height; _pictureWidth = width; _gasolineTanker = new BaseTanker(speed, weight, bodyColor); } public DrawTanker(int speed, double weight, Color bodyColor, int width, int height, int carWidth, int carHeight) { _pictureHeight = height; _pictureWidth = width; _carHeight = carHeight; _carWidth = carWidth; _gasolineTanker = new BaseTanker(speed, weight, bodyColor); } public void SetBaseColor(Color bodyColor) { _gasolineTanker.ChangeBodyColor(bodyColor); } public void SetPosition(int x, int y) { _startPosX = x; _startPosY = y; } public void MoveTransport(Direction direction) { if (!CanMove(direction) || _gasolineTanker == null) return; switch (direction) { case Direction.Left: { if (_startPosX - _gasolineTanker.Step > 0) { _startPosX -= (int)_gasolineTanker.Step; } } break; case Direction.Up: { if (_startPosY - _gasolineTanker.Step > 0) { _startPosY -= (int)_gasolineTanker.Step; } } break; case Direction.Right: { if (_startPosX + _carWidth + _gasolineTanker.Step < _pictureWidth) { _startPosX += (int)_gasolineTanker.Step; } } break; case Direction.Down: { if (_startPosY + _gasolineTanker.Step + _carHeight < _pictureHeight) { _startPosY += (int)_gasolineTanker.Step; } } break; } } public virtual void DrawTransport(Graphics g) { if (_gasolineTanker == null) return; Pen pen = new(_gasolineTanker.BodyColor, 2); Brush brush = new SolidBrush(_gasolineTanker.BodyColor); // Отрисовка корпуса g.FillRectangle(brush, 10 + _startPosX, 40 + _startPosY, 90, 20); g.FillRectangle(brush, 80 + _startPosX, 10 + _startPosY, 20, 40); // Отрисовка колесиков g.FillEllipse(brush, 10 + _startPosX, 60 + _startPosY, 20, 20); g.FillEllipse(brush, 30 + _startPosX, 60 + _startPosY, 20, 20); g.FillEllipse(brush, 80 + _startPosX, 60 + _startPosY, 20, 20); } public IMoveableObject GetMoveableObject => new DrawingObjectTanker(this); } }