PIbd-23 Yakobchuk S.V. LabWork_02 #2
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawingSailboat
|
||||
public class DrawingSailboat : DrawingBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntitySailboat? EntitySailboat { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки лодки
|
||||
/// </summary>
|
||||
private int _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя координата прорисовки лодки
|
||||
/// </summary>
|
||||
private int _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки лодки
|
||||
/// </summary>
|
||||
private readonly int _boatWidth = 185;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки лодки
|
||||
/// </summary>
|
||||
private readonly int _boatHeight = 160;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="hullCooler">Признак наличия усиленного корпуса парусника</param>
|
||||
/// <param name="hull">Признак наличия основного корпуса парусника</param>
|
||||
/// <param name="hull">Признак наличия усиленного корпуса</param>
|
||||
/// <param name="sail">Признак наличия паруса</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user