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 { internal class DrawingTank { public Tank? TankEntity { get; private set; } private int pictureWidth; private int pictureHeight; private int startPosX; private int startPosY; private readonly int tankWidth = 150; private readonly int tankHeight = 100; public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, bool isAntiAircraftGun, bool isTankTower) { if (width <= tankWidth || height <= tankHeight) return false; pictureWidth = width; pictureHeight = height; TankEntity = new Tank(); TankEntity.Init(speed, weight, bodyColor, additionalColor, isAntiAircraftGun, isTankTower); return true; } public void SetPosition(int x, int y) { if (TankEntity == null) return; startPosX = x; startPosX = y; if (x + tankWidth >= pictureWidth || y + tankHeight >= pictureHeight) { startPosX = 1; startPosY = 1; } } public void MoveTransport(DirectionType direction) { if (TankEntity == null) return; switch (direction) { //влево case DirectionType.Left: if (startPosX - TankEntity.Step > 0) { startPosX -= (int)TankEntity.Step; } break; //вверх case DirectionType.Up: if (startPosY - TankEntity.Step > 0) { startPosY -= (int)TankEntity.Step; } break; // вправо case DirectionType.Right: if (startPosX + TankEntity.Step + tankWidth <= pictureWidth) { startPosX += (int)TankEntity.Step; } break; //вниз case DirectionType.Down: if (startPosY + TankEntity.Step + tankHeight <= pictureHeight) { startPosY += (int)TankEntity.Step; } break; } } public void DrawTransport(Graphics g) { if (TankEntity == null) return; Pen pen = new(TankEntity.BodyColor); // границы g.DrawRectangle(new Pen(Color.Red), startPosX, startPosY, tankWidth, tankHeight); // гусеница 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); if (TankEntity.IsTankMuzzle) { // дуло g.DrawRectangle(pen, startPosX + 15, startPosY + 37, 30, 7); } // башня SolidBrush brush = new SolidBrush(TankEntity.AdditionalColor); g.FillRectangle(brush, startPosX + 45, startPosY + 30, 60, 25); g.FillRectangle(brush, startPosX + 5, startPosY + 55 + 1, tankWidth - 10, 9); if (TankEntity.IsAntiAircraftGun) { // зенитное орудие g.DrawRectangle(pen, startPosX + 65, startPosY + 18, 8, 12); g.DrawRectangle(pen, startPosX + 65 + 8, startPosY + 16, 8, 14); Point[] leftRectanglePoints = { new Point(startPosX + 52, startPosY + 5), new Point(startPosX + 67, startPosY + 18), new Point(startPosX + 67 + 5, startPosY + 18), new Point(startPosX + 57, startPosY + 5), }; g.DrawPolygon(pen, leftRectanglePoints); Point[] rightRectanglePoints = { new Point(startPosX + 59, startPosY), new Point(startPosX + 74, startPosY + 16), new Point(startPosX + 74 + 5, startPosY + 16), new Point(startPosX + 66, startPosY), }; g.DrawPolygon(pen, rightRectanglePoints); } } } }