diff --git a/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs b/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs index cc21783..a37f4e1 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs @@ -26,19 +26,19 @@ namespace ProjectStormtrooper /// /// Левая координата начала прорисовки /// - private int _startPosX; + protected int _startPosX; /// /// Верхняя координата начала прорисовки /// - private int _startPosY; + protected int _startPosY; /// /// Ширина прорисовки /// - private readonly int _planeWidth = 110; + protected readonly int _planeWidth = 110; /// /// Высота прорисовки /// - private readonly int _planeHeight = 110; + protected readonly int _planeHeight = 110; /// /// Конструктор /// @@ -153,7 +153,7 @@ namespace ProjectStormtrooper /// Прорисовка объекта /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (EntityPlane == null) { diff --git a/ProjectStormtrooper/ProjectStormtrooper/DrawingStormTrooper.cs b/ProjectStormtrooper/ProjectStormtrooper/DrawingStormTrooper.cs index 76ef983..ce97860 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/DrawingStormTrooper.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/DrawingStormTrooper.cs @@ -9,38 +9,10 @@ namespace ProjectStormtrooper /// /// Класс отвечающий за прорисовку и перемещение объекта-сущности /// - public class DrawingStormtrooper + public class DrawingStormtrooper : DrawingPlane { /// - /// Класс-сущность - /// - public EntityStormtrooper? EntityStormtrooper { get; private set; } - /// - /// Ширина окна - /// - private int _pictureWidth; - /// - /// Высота окна - /// - private int _pictureHeight; - /// - /// Левая координата начала прорисовки - /// - private int _startPosX; - /// - /// Верхняя координата начала прорисовки - /// - private int _startPosY; - /// - /// Ширина прорисовки - /// - private readonly int _stormtrooperWidth = 110; - /// - /// Высота прорисовки - /// - private readonly int _stormtrooperHeight = 110; - /// - /// Инициализация свойств + /// Конструктор /// /// Скорость /// Вес @@ -50,121 +22,45 @@ namespace ProjectStormtrooper /// Признак наличия бомб /// Ширина картинки /// Высота картинки - /// true - если объект успешно создан, false - проверка не пройдена, - /// т.к. нельзя создать объект в этих размерах - public bool Init(int speed, double weight, Color bodyColor, + public DrawingStormtrooper(int speed, double weight, Color bodyColor, Color additionalColor, bool rockets, bool bombs, - int width, int height) + int width, int height) : base(speed, weight, bodyColor, width, height, 110, 110) { - if (width < _stormtrooperWidth && height < _stormtrooperHeight) + if (EntityPlane != null) { - return false; - } - _pictureWidth = width; - _pictureHeight = height; - EntityStormtrooper = new EntityStormtrooper(); - EntityStormtrooper.Init(speed, weight, bodyColor, additionalColor, rockets, bombs); - return true; - } - /// - /// Установка позиции - /// - /// Координата X - /// Координата Y - public void SetPosition(int x, int y) - { - if (x < 0) - { - x = 0; - } - else if (x > _pictureWidth - _stormtrooperWidth) - { - x = _pictureWidth - _stormtrooperWidth; - } - _startPosX = x; - - if (y < 0) - { - y = 0; - } - else if (y > _pictureHeight - _stormtrooperHeight) - { - y = _pictureHeight - _stormtrooperHeight; - } - _startPosY = y; - } - /// - /// Перемещение объекта - /// - /// Направление перемещения - public void MoveTransport(DirectionType direction) - { - if (EntityStormtrooper == null) - { - return; - } - switch (direction) - { - // Вверх - case DirectionType.Up: - if (_startPosY - EntityStormtrooper.Step >= 0) - { - _startPosY -= (int)EntityStormtrooper.Step; - } - break; - // Вниз - case DirectionType.Down: - if (_startPosY + _stormtrooperHeight + EntityStormtrooper.Step <= _pictureHeight) - { - _startPosY += (int)EntityStormtrooper.Step; - } - break; - // Влево - case DirectionType.Left: - if (_startPosX - EntityStormtrooper.Step >= 0) - { - _startPosX -= (int)EntityStormtrooper.Step; - } - break; - // Вправо - case DirectionType.Right: - if (_startPosX + _stormtrooperWidth + EntityStormtrooper.Step <= _pictureWidth) - { - _startPosX += (int)EntityStormtrooper.Step; - } - break; + EntityPlane = new EntityStormtrooper(speed, weight, bodyColor, additionalColor, rockets, bombs); } } /// /// Прорисовка объекта /// /// - public void DrawTransport(Graphics g) + public override void DrawTransport(Graphics g) { - if (EntityStormtrooper == null) + if (EntityPlane is not EntityStormtrooper stormtrooper) { return; } Pen penBlack = new Pen(Color.Black); Brush brushBlack = new SolidBrush(Color.Black); - Brush brushBodyColor = new SolidBrush(EntityStormtrooper.BodyColor); - Brush brushAdditionalColor = new SolidBrush(EntityStormtrooper.AdditionalColor); + Brush brushBodyColor = new SolidBrush(stormtrooper.BodyColor); + Brush brushAdditionalColor = new SolidBrush(stormtrooper.AdditionalColor); // Высота фюзеляжа - int bodyHeight = _stormtrooperHeight / 9; + int bodyHeight = _planeHeight / 9; // Рисуем бомбы - if (EntityStormtrooper.Bombs) + if (stormtrooper.Bombs) { Point[] pointsBombTail = { - new Point(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8 + bodyHeight * 3 - 5, - _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3 + bodyHeight / 2), - new Point(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8 + bodyHeight * 3 + 5, - _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3 + bodyHeight / 2 - 5), - new Point(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8 + bodyHeight * 3 + 5, - _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3 + bodyHeight / 2 + 5), - new Point(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8 + bodyHeight * 3 - 5, - _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3 + bodyHeight / 2) + new Point(_startPosX + _planeWidth / 2 - _planeWidth / 8 + bodyHeight * 3 - 5, + _startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3 + bodyHeight / 2), + new Point(_startPosX + _planeWidth / 2 - _planeWidth / 8 + bodyHeight * 3 + 5, + _startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3 + bodyHeight / 2 - 5), + new Point(_startPosX + _planeWidth / 2 - _planeWidth / 8 + bodyHeight * 3 + 5, + _startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3 + bodyHeight / 2 + 5), + new Point(_startPosX + _planeWidth / 2 - _planeWidth / 8 + bodyHeight * 3 - 5, + _startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3 + bodyHeight / 2) }; g.FillPolygon(brushAdditionalColor, pointsBombTail); @@ -173,7 +69,7 @@ namespace ProjectStormtrooper for (int i = 0; i < pointsBombTail.Length; i++) { Point p = pointsBombTail[i]; - p.Y = _startPosY + _stormtrooperHeight - (p.Y - _startPosY); + p.Y = _startPosY + _planeHeight - (p.Y - _startPosY); pointsBombTail[i] = p; } @@ -181,30 +77,30 @@ namespace ProjectStormtrooper g.DrawPolygon(penBlack, pointsBombTail); g.FillEllipse(brushAdditionalColor, - _startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8, - _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3, + _startPosX + _planeWidth / 2 - _planeWidth / 8, + _startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3, bodyHeight * 3, bodyHeight); g.DrawEllipse(penBlack, - _startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8, - _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3, + _startPosX + _planeWidth / 2 - _planeWidth / 8, + _startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3, bodyHeight * 3, bodyHeight); g.FillEllipse(brushAdditionalColor, - _startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8, - _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 + _stormtrooperHeight / 3, + _startPosX + _planeWidth / 2 - _planeWidth / 8, + _startPosY + _planeHeight / 2 - bodyHeight / 2 + _planeHeight / 3, bodyHeight * 3, bodyHeight); g.DrawEllipse(penBlack, - _startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8, - _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 + _stormtrooperHeight / 3, + _startPosX + _planeWidth / 2 - _planeWidth / 8, + _startPosY + _planeHeight / 2 - bodyHeight / 2 + _planeHeight / 3, bodyHeight * 3, bodyHeight); } // Рисуем ракеты - if (EntityStormtrooper.Rockets) + if (stormtrooper.Rockets) { int rocketWidth = bodyHeight * 4; int rocketHeight = bodyHeight / 2; @@ -212,21 +108,21 @@ namespace ProjectStormtrooper Brush brushRed = new SolidBrush(Color.Red); Point[] pointsRocketCockPit = { - new Point(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5 - rocketHeight, - _startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight / 2), - new Point(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5, - _startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2), - new Point(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5, - _startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight) + new Point(_startPosX + _planeWidth / 2 - _planeWidth / 5 - rocketHeight, + _startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight / 2), + new Point(_startPosX + _planeWidth / 2 - _planeWidth / 5, + _startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2), + new Point(_startPosX + _planeWidth / 2 - _planeWidth / 5, + _startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight) }; Point[] pointsRocketTail = { - new Point(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5 - rocketHeight + rocketWidth - 10, - _startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight / 2), - new Point(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5 + rocketWidth, - _startPosY + _stormtrooperHeight / 2 - bodyHeight * 2 + rocketHeight / 2), - new Point(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5 + rocketWidth, - _startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight + bodyHeight / 2 - rocketHeight / 2) + new Point(_startPosX + _planeWidth / 2 - _planeWidth / 5 - rocketHeight + rocketWidth - 10, + _startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight / 2), + new Point(_startPosX + _planeWidth / 2 - _planeWidth / 5 + rocketWidth, + _startPosY + _planeHeight / 2 - bodyHeight * 2 + rocketHeight / 2), + new Point(_startPosX + _planeWidth / 2 - _planeWidth / 5 + rocketWidth, + _startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight + bodyHeight / 2 - rocketHeight / 2) }; g.FillPolygon(brushRed, pointsRocketCockPit); @@ -238,14 +134,14 @@ namespace ProjectStormtrooper for (int i = 0; i < pointsRocketCockPit.Length; i++) { Point p = pointsRocketCockPit[i]; - p.Y = _startPosY + _stormtrooperHeight - (p.Y - _startPosY); + p.Y = _startPosY + _planeHeight - (p.Y - _startPosY); pointsRocketCockPit[i] = p; } for (int i = 0; i < pointsRocketTail.Length; i++) { Point p = pointsRocketTail[i]; - p.Y = _startPosY + _stormtrooperHeight - (p.Y - _startPosY); + p.Y = _startPosY + _planeHeight - (p.Y - _startPosY); pointsRocketTail[i] = p; } @@ -256,68 +152,29 @@ namespace ProjectStormtrooper g.DrawPolygon(penBlack, pointsRocketTail); g.FillRectangle(brushAdditionalColor, - _startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5, - _startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2, + _startPosX + _planeWidth / 2 - _planeWidth / 5, + _startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2, rocketWidth, rocketHeight); g.DrawRectangle(penBlack, - _startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5, - _startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2, + _startPosX + _planeWidth / 2 - _planeWidth / 5, + _startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2, rocketWidth, rocketHeight); g.FillRectangle(brushAdditionalColor, - _startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5, - _startPosY + _stormtrooperHeight / 2 + bodyHeight / 2 + bodyHeight / 2, + _startPosX + _planeWidth / 2 - _planeWidth / 5, + _startPosY + _planeHeight / 2 + bodyHeight / 2 + bodyHeight / 2, rocketWidth, rocketHeight); g.DrawRectangle(penBlack, - _startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5, - _startPosY + _stormtrooperHeight / 2 + bodyHeight / 2 + bodyHeight / 2, + _startPosX + _planeWidth / 2 - _planeWidth / 5, + _startPosY + _planeHeight / 2 + bodyHeight / 2 + bodyHeight / 2, rocketWidth, rocketHeight); } - // Рисуем нос - - Point[] pointsCockPit = { - new Point(_startPosX, _startPosY + _stormtrooperHeight / 2), - new Point(_startPosX + _stormtrooperWidth / 8, _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2), - new Point(_startPosX + _stormtrooperWidth / 8, _startPosY + _stormtrooperHeight / 2 + bodyHeight / 2) - }; - - g.FillPolygon(brushBlack, pointsCockPit); - - // Рисуем крылья - - Point[] pointsWings = { - new Point(_startPosX + _stormtrooperWidth / 2, _startPosY), - new Point(_startPosX + _stormtrooperWidth / 2 + _stormtrooperWidth / 15, _startPosY), - new Point(_startPosX + _stormtrooperWidth / 2 + _stormtrooperWidth / 6, _startPosY + _stormtrooperHeight / 2), - new Point(_startPosX + _stormtrooperWidth / 2 + _stormtrooperWidth / 15, _startPosY + _stormtrooperHeight), - new Point(_startPosX + _stormtrooperWidth / 2 , _startPosY + _stormtrooperHeight) - }; - - g.FillPolygon(brushBodyColor, pointsWings); - g.DrawPolygon(penBlack, pointsWings); - - // Рисуем хвостовое оперение - - Point[] pointsTail = { - new Point(_startPosX + _stormtrooperWidth, _startPosY + _stormtrooperHeight / 2 - _stormtrooperHeight / 3), - new Point(_startPosX + _stormtrooperWidth - _stormtrooperWidth / 8, _startPosY + _stormtrooperHeight / 2 - _stormtrooperHeight / 8), - new Point(_startPosX + _stormtrooperWidth - _stormtrooperWidth / 8, _startPosY + _stormtrooperHeight / 2 + _stormtrooperHeight / 8), - new Point(_startPosX + _stormtrooperWidth, _startPosY + _stormtrooperHeight / 2 + _stormtrooperHeight / 3) - - }; - - g.FillPolygon(brushBodyColor, pointsTail); - g.DrawPolygon(penBlack, pointsTail); - - // Рисуем фюзеляж - - g.FillRectangle(brushBodyColor, _startPosX + _stormtrooperWidth / 8, _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2, _stormtrooperWidth - _stormtrooperWidth / 8, bodyHeight); - g.DrawRectangle(penBlack, _startPosX + _stormtrooperWidth / 8, _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2, _stormtrooperWidth - _stormtrooperWidth / 8, bodyHeight); + base.DrawTransport(g); } } } diff --git a/ProjectStormtrooper/ProjectStormtrooper/EntityStormtrooper.cs b/ProjectStormtrooper/ProjectStormtrooper/EntityStormtrooper.cs index 72dc96d..dc7c33e 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/EntityStormtrooper.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/EntityStormtrooper.cs @@ -22,7 +22,7 @@ namespace ProjectStormtrooper /// public bool Bombs { get; private set; } public EntityStormtrooper(int speed, double weight, Color bodyColor, - Color additionalColor, bool rockets, bool bombs) + Color additionalColor, bool rockets, bool bombs) : base(speed, weight, bodyColor) { AdditionalColor = additionalColor; Rockets = rockets;