using System; using System.Collections.Generic; using System.Drawing; using System.Text; using SelfPropelledArtilleryUnit; using System.Windows.Forms; namespace SelfPropelledArtilleryUnit { /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// class DrawningTank { /// /// Класс-сущность /// public EntityTank? EntityTank { get; private set; } /// /// Ширина окна /// private int _pictureWidth; /// /// Высота окна /// private int _pictureHeight; /// /// /// Левая координата прорисовки автомобиля /// private int _startPosX; /// /// Верхняя кооридната прорисовки автомобиля /// private int _startPosY; /// /// Ширина прорисовки танка /// private readonly int _tankWidth = 135; /// /// Высота прорисовки танка /// private readonly int _tankHeight = 75; /// /// Инициализация свойств /// /// Скорость /// Вес /// Цвет кузова /// Дополнительный цвет /// Признак наличия пулемета /// Признак наличия пушки /// Ширина картинки /// Высота картинки /// true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool machine_gun, bool cannon, int width, int height) { _pictureWidth = width; _pictureHeight = height; if (_tankHeight >= height) { return false; } if (_tankWidth >= width) { return false; } EntityTank = new EntityTank(); EntityTank.Init(speed, weight, bodyColor, additionalColor, machine_gun, cannon); return true; //EntityTank myTank = new EntityTank(); //myTank.Init(50, 75.5, Color.Green, Color.Black, true, false, true); //return true; } public void SetPosition(int x, int y) { if (x < 0 || x > _pictureWidth - _tankWidth) { x = 0; } if (y < 0 || y > _pictureHeight - _tankHeight) { y = 0; } _startPosX = x; _startPosY = y; } public void MoveTransport(Direction direction) { if (EntityTank == null) { return; } switch (direction) { //влево case Direction.Left: if (_startPosX - EntityTank.Step > 0) { _startPosX -= (int)EntityTank.Step; } break; //вверх case Direction.Up: if (_startPosY - EntityTank.Step > 0) { _startPosY -= (int)EntityTank.Step; } break; // вправо case Direction.Right: if (_startPosX + EntityTank.Step < _pictureWidth - _tankWidth) { _startPosX += (int)EntityTank.Step; } break; //вниз case Direction.Down: if (_startPosY + EntityTank.Step < _pictureHeight - _tankHeight) { _startPosY += (int)EntityTank.Step; } break; } } /// /// Прорисовка объекта /// /// public void DrawTransport(Graphics g) { if (EntityTank == null) { return; } Pen penBlack = new(Color.Black); Brush additionalBrush = new SolidBrush(EntityTank.AdditionalColor); // пулемет if (EntityTank.Machine_gun) { //залповая усутановка g.FillRectangle(additionalBrush, _startPosX + 15, _startPosY + 20, 20, 40); g.DrawLine(penBlack, _startPosX + 5, _startPosY + 20, _startPosX + 15, _startPosY + 25); } //гусеницы Brush brBlack = new SolidBrush(Color.Black); Brush brBody = new SolidBrush(EntityTank.BodyColor); g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 50, 20, 20); g.FillEllipse(brBlack, _startPosX + 30, _startPosY + 50, 20, 20); g.FillEllipse(brBlack, _startPosX + 55, _startPosY + 50, 20, 20); g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 50, 20, 20); g.FillEllipse(brBlack, _startPosX + 105, _startPosY + 50, 20, 20); g.DrawEllipse(penBlack, _startPosX + 10, _startPosY + 55, 113, 20); //пушка Point[] pointsGun = new Point[4]; pointsGun[0].X = _startPosX + 85; pointsGun[0].Y = _startPosY + 25; pointsGun[1].X = _startPosX + 80; pointsGun[1].Y = _startPosY + 30; pointsGun[2].X = _startPosX - 15; pointsGun[2].Y = _startPosY + 5; pointsGun[3].X = _startPosX - 10; pointsGun[3].Y = _startPosY + 0; g.FillPolygon(brBody, pointsGun); g.DrawPolygon(penBlack, pointsGun); //корпус Point[] pointsCorp = new Point[4]; pointsCorp[0].X = _startPosX; pointsCorp[0].Y = _startPosY + 60; pointsCorp[1].X = _startPosX + 10; pointsCorp[1].Y = _startPosY + 30; pointsCorp[2].X = _startPosX + 130; pointsCorp[2].Y = _startPosY + 30; pointsCorp[3].X = _startPosX + 135; pointsCorp[3].Y = _startPosY + 60; g.FillPolygon(brBody, pointsCorp); g.DrawPolygon(penBlack, pointsCorp); //башня Point[] pointsHead = new Point[4]; pointsHead[0].X = _startPosX + 60; pointsHead[0].Y = _startPosY + 30; pointsHead[1].X = _startPosX + 65; pointsHead[1].Y = _startPosY + 15; pointsHead[2].X = _startPosX + 90; pointsHead[2].Y = _startPosY + 15; pointsHead[3].X = _startPosX + 95; pointsHead[3].Y = _startPosY + 30; g.FillPolygon(brBody, pointsHead); g.DrawPolygon(penBlack, pointsHead); } } }