2022-11-04 13:12:14 +04:00

83 lines
4.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boats
{
/// <summary>
/// Класс для отрисовки катамарана
/// </summary>
internal class DrawingCatamaran : DrawingBoat
{
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес катамарана</param>
/// <param name="bodyColor">Цвет корпуса</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bobbers">Признак наличия поплавков</param>
/// <param name="sail">Признак наличия паруса</param>
public DrawingCatamaran(int speed, float weight, Color bodyColor,
Color dopColor, bool bobbers, bool sail) :
base(speed, weight, bodyColor, 110, 60)
{
Boat = new EntityCatamaran(speed, weight, bodyColor, dopColor, bobbers, sail);
}
/// <summary>
/// Метод для отрисовки катамарана
/// </summary>
/// <param name="g"></param>
public override void DrawTransport(Graphics g)
{
if (Boat is not EntityCatamaran catamaran)
{
return;
}
Brush dopBrush = new SolidBrush(catamaran.DopColor);
int bobbersWidth = _boatWidth / 4;
int bobbersHeight = _boatHeight / 5;
base.DrawTransport(g);
if (catamaran.Bobbers)
{
// Отрисовка верхних поплавков
g.FillRectangle(dopBrush, _startPosX, _startPosY, bobbersWidth, bobbersHeight);
g.DrawRectangle(Pens.Black, _startPosX, _startPosY, bobbersWidth, bobbersHeight);
g.DrawRectangle(Pens.Black, _startPosX + bobbersWidth / 4, _startPosY, bobbersWidth / 2, bobbersHeight);
g.FillRectangle(dopBrush, _startPosX + _boatWidth / 2, _startPosY, _boatWidth / 4, bobbersHeight);
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2, _startPosY, _boatWidth / 4, bobbersHeight);
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2 + bobbersWidth / 4, _startPosY, bobbersWidth / 2, bobbersHeight);
// Отрисовка нижних поплавков
g.FillRectangle(dopBrush, _startPosX, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
g.DrawRectangle(Pens.Black, _startPosX, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
g.DrawRectangle(Pens.Black, _startPosX + bobbersWidth / 4, _startPosY + _boatHeight - bobbersHeight, bobbersWidth / 2, bobbersHeight);
g.FillRectangle(dopBrush, _startPosX + _boatWidth / 2, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2 + bobbersWidth / 4, _startPosY + _boatHeight - bobbersHeight, bobbersWidth / 2, bobbersHeight);
}
if (catamaran.Sail)
{
float downPointSailX = _startPosX + _boatWidth / 2 - _boatWidth / 8;
float downPointSailY = _startPosY + _boatHeight / 2 + _boatWidth / 8;
PointF[] sailPoints = new PointF[3];
sailPoints[0] = new PointF(downPointSailX, downPointSailY);
sailPoints[1] = new PointF(downPointSailX, _startPosY);
sailPoints[2] = new PointF(downPointSailX - _boatWidth / 4, downPointSailY - _boatHeight / 4);
// Отрисовка паруса
g.FillPolygon(dopBrush, sailPoints);
g.DrawPolygon(Pens.Black, sailPoints);
}
}
}
}