diff --git a/Sailboat/Sailboat/DrawningSailboat.cs b/Sailboat/Sailboat/DrawningSailboat.cs
index 01b6837..c9dda29 100644
--- a/Sailboat/Sailboat/DrawningSailboat.cs
+++ b/Sailboat/Sailboat/DrawningSailboat.cs
@@ -1,157 +1,51 @@
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Sailboat
+using Sailboat.Entities;
+
+namespace Sailboat.DrawingObjects
{
///
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
///
- public class DrawingSailboat
+ public class DrawingSailboat : DrawingBoat
{
///
- /// Класс-сущность
- ///
- public EntitySailboat? EntitySailboat { get; private set; }
-
- ///
- /// Ширина окна
- ///
- private int _pictureWidth;
-
- ///
- /// Высота окна
- ///
- private int _pictureHeight;
-
- ///
- /// Левая координата прорисовки лодки
- ///
- private int _startPosX;
-
- ///
- /// Верхняя координата прорисовки лодки
- ///
- private int _startPosY;
-
- ///
- /// Ширина прорисовки лодки
- ///
- private readonly int _boatWidth = 185;
-
- ///
- /// Высота прорисовки лодки
- ///
- private readonly int _boatHeight = 160;
-
- ///
- /// Инициализация свойств
+ /// Конструктор
///
/// Скорость
/// Вес
- /// Цвет кузова
+ /// Основной цвет
/// Дополнительный цвет
- /// Признак наличия усиленного корпуса парусника
- /// Признак наличия основного корпуса парусника
+ /// Признак наличия усиленного корпуса
/// Признак наличия паруса
/// Ширина картинки
/// Высота картинки
- /// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах
- public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool hullCooler, bool hull, bool sail, int width, int height)
+ public DrawingSailboat(int speed, double weight, Color bodyColor, Color additionalColor, bool hull, bool sail, int width, int height) :
+ base(speed, weight, bodyColor, width, height, 200, 160)
{
- // Проверки
- if (width < _boatWidth || height < _boatHeight)
+ if (EntityBoat != null)
{
- return false;
+ EntityBoat = new EntitySailboat(speed, weight, bodyColor,
+ additionalColor, hull, sail);
}
- _pictureWidth = width;
- _pictureHeight = height;
- EntitySailboat = new EntitySailboat();
- EntitySailboat.Init(speed, weight, bodyColor, additionalColor, hull, sail);
- return true;
}
-
- ///
- /// Установка позиции
- ///
- /// Координата X
- /// Координата Y
- public void SetPosition(int x, int y)
+ public override void DrawTransport(Graphics g)
{
- // Изменение x, y
- if (x < 0 || x + _boatWidth > _pictureWidth)
- {
- x = 0;
- }
- if (y < 0 || y + _boatHeight > _pictureHeight)
- {
- y = 0;
- }
- _startPosX = x;
- _startPosY = y;
- }
-
- ///
- /// Изменение направления перемещения
- ///
- /// Направление
- public void MoveTransport(DirectionType direction)
- {
- if (EntitySailboat == null)
+ if (EntityBoat is not EntitySailboat sailboat)
{
return;
}
- switch (direction)
- {
- //влево
- case DirectionType.Left:
- if (_startPosX - EntitySailboat.Step > 0)
- {
- _startPosX -= (int)EntitySailboat.Step;
- }
- break;
- //вверх
- case DirectionType.Up:
- if (_startPosY - EntitySailboat.Step > 0)
- {
- _startPosY -= (int)EntitySailboat.Step;
- }
- break;
- //вправо
- case DirectionType.Right:
- if (_startPosX + EntitySailboat.Step + _boatWidth < _pictureWidth)
- {
- _startPosX += (int)EntitySailboat.Step;
- }
- break;
- //вниз
- case DirectionType.Down:
- if (_startPosY + EntitySailboat.Step + _boatHeight < _pictureHeight)
- {
- _startPosY += (int)EntitySailboat.Step;
- }
- break;
- }
- }
-
- ///
- /// Прорисовка объекта
- ///
- ///
- public void DrawTransport(Graphics g)
- {
- if (EntitySailboat == null)
- {
- return;
- }
- Pen pen = new(Color.Black, 4);
+ Pen pen = new(Color.Black);
Brush additionalBrush = new
- SolidBrush(EntitySailboat.AdditionalColor);
+ SolidBrush(sailboat.AdditionalColor);
// Усиленный корпус парусника
- if (EntitySailboat.Hull)
+ if (sailboat.Hull)
{
Point[] hullCooler = new Point[]
{
@@ -165,38 +59,18 @@ namespace Sailboat
g.DrawPolygon(pen, hullCooler);
}
-
- // Основной корпус парусника
- Brush Brush = new
- SolidBrush(EntitySailboat.BodyColor);
-
- Point[] hull = new Point[]
- {
- new Point(_startPosX + 5, _startPosY + 90),
- new Point(_startPosX + 120, _startPosY + 90),
- new Point(_startPosX + 180, _startPosY + 120),
- new Point(_startPosX + 120, _startPosY + 150),
- new Point(_startPosX + 5, _startPosY + 150)
- };
- g.FillPolygon(Brush, hull);
- g.DrawPolygon(pen, hull);
-
- Brush addBrush = new
- SolidBrush(Color.Green);
-
- g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 100, 40);
- g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 100, 40);
+ base.DrawTransport(g);
// Парус
- if (EntitySailboat.Sail)
+ if (sailboat.Sail)
{
Brush sailBrush = new
- SolidBrush(EntitySailboat.AdditionalColor);
+ SolidBrush(sailboat.AdditionalColor);
Point[] sail = new Point[]
{
new Point(_startPosX + 65, _startPosY),
- new Point(_startPosX + 150, _startPosY + 120),
+ new Point(_startPosX + 130, _startPosY + 120),
new Point(_startPosX + 15, _startPosY + 120)
};
g.FillPolygon(sailBrush, sail);