using ProjectTank.Entities; using System; using System.Collections.Generic; using System.Drawing.Drawing2D; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProjectTank.DrawningObjects { public class DrawningTankBase { public EntityTankBase? EntityTankBase { get; protected set; } private int pictureWidth; private int pictureHeight; protected int startPosX; protected int startPosY; protected readonly int tankWidth = 150; protected readonly int tankHeight = 100; public int GetPosX => startPosX; public int GetPosY => startPosY; public int GetWidth => tankWidth; public int GetHeight => tankHeight; public DrawningTankBase(int speed, int weight, Color bodyColor, int width, int height) { if (width <= tankWidth || height <= tankHeight) return; pictureWidth = width; pictureHeight = height; EntityTankBase = new EntityTankBase(speed, weight, bodyColor); } protected DrawningTankBase(int speed, int weight, Color bodyColor, int width, int height, int _tankWidth, int _tankHeight) { if (width <= tankWidth || height <= tankHeight) return; pictureWidth = width; pictureHeight = height; tankWidth = _tankWidth; tankHeight = _tankHeight; EntityTankBase = new EntityTankBase(speed, weight, bodyColor); } public bool CanMove(DirectionType direction) { if (EntityTankBase == null) return false; return direction switch { DirectionType.Left => startPosX - EntityTankBase.Step > 0, DirectionType.Up => startPosY - EntityTankBase.Step > 0, DirectionType.Right => startPosX + tankWidth + EntityTankBase.Step < pictureWidth, DirectionType.Down => startPosY + tankHeight + EntityTankBase.Step < pictureHeight, _ => false, }; } public void SetPosition(int x, int y) { if (EntityTankBase == null) return; startPosX = x; startPosX = y; if (x + tankWidth >= pictureWidth || y + tankHeight >= pictureHeight) { startPosX = 1; startPosY = 1; } } public void MoveTransport(DirectionType direction) { if (!CanMove(direction) || EntityTankBase == null) return; switch (direction) { //влево case DirectionType.Left: startPosX -= (int)EntityTankBase.Step; break; //вверх case DirectionType.Up: startPosY -= (int)EntityTankBase.Step; break; // вправо case DirectionType.Right: startPosX += (int)EntityTankBase.Step; break; //вниз case DirectionType.Down: startPosY += (int)EntityTankBase.Step; break; } } public virtual void DrawTransport(Graphics g) { if (EntityTankBase == null) return; Pen pen = new(EntityTankBase.BodyColor); // гусеница GraphicsPath path = new GraphicsPath(); int cornerRadius = 20; path.AddArc(startPosX, startPosY + 65, cornerRadius, cornerRadius, 180, 90); path.AddArc(startPosX + tankWidth - cornerRadius, startPosY + 65, cornerRadius, cornerRadius, 270, 90); path.AddArc(startPosX + tankWidth - cornerRadius, startPosY + tankHeight - cornerRadius, cornerRadius, cornerRadius, 0, 90); path.AddArc(startPosX, startPosY + tankHeight - cornerRadius, cornerRadius, cornerRadius, 90, 90); path.CloseFigure(); g.DrawPath(pen, path); // колеса g.DrawEllipse(pen, startPosX + 1, startPosY + tankHeight - 5 - 25, 25, 25); for (int i = 1; i < 5; i++) { g.DrawEllipse(pen, startPosX + 30 + 5 * i + 15 * (i - 1), startPosY + tankHeight - 5 - 15, 15, 15); } g.DrawEllipse(pen, startPosX + tankWidth - 25 - 1, startPosY + tankHeight - 5 - 25, 25, 25); // башня SolidBrush brush = new SolidBrush(EntityTankBase.BodyColor); g.FillRectangle(brush, startPosX + 45, startPosY + 30, 60, 25); g.FillRectangle(brush, startPosX + 5, startPosY + 55 + 1, tankWidth - 10, 9); } } }