PIbd-22_Fedorenko_G.Y._Hydr.../Hydroplane/DrawningPlane.cs

197 lines
7.5 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 Hydroplane
{
public class DrawningPlane
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityPlane? EntityPlane { get; protected set; }
/// <summary>
/// Ширина окна
/// </summary>
private int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int _pictureHeight;
/// <summary>
/// Левая координата прорисовки гидроплана
/// </summary>
protected int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки гидроплана
/// </summary>
protected int _startPosY;
/// <summary>
/// Ширина прорисовки гидроплана
/// </summary>
protected readonly int _planeWidth = 175;
/// <summary>
/// Высота прорисовки гидроплана
/// </summary>
protected readonly int _planeHeight = 80;
/// <summary>
/// Конструктор с параметрами
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawningPlane(int speed, double weight, Color bodyColor, int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth < _planeWidth || _pictureHeight < _planeHeight)
{
return;
}
EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
/// <param name="planeWidth">Ширина прорисовки гидроплана</param>
/// <param name="planeHeight">Высота прорисовки гидроплана</param>
protected DrawningPlane(int speed, double weight, Color bodyColor,
int width, int height, int planeWidth, int planeHeight)
{
// TODO: Продумать проверки
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth < _planeWidth || _pictureHeight < _planeHeight)
{
return;
}
_planeWidth = planeWidth;
_planeHeight = planeHeight;
EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
_startPosX = Math.Min(x, _pictureWidth - _planeWidth);
_startPosY = Math.Min(y, _pictureHeight - _planeHeight);
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (EntityPlane == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX - EntityPlane.Step > 0)
{
_startPosX -= (int)EntityPlane.Step;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - EntityPlane.Step > 0)
{
_startPosY -= (int)EntityPlane.Step;
}
break;
// вправо
case DirectionType.Right:
if (_startPosX + EntityPlane.Step + _planeWidth < _pictureWidth)
{
_startPosX += (int)EntityPlane.Step;
}
break;
//вниз
case DirectionType.Down:
if (_startPosY + EntityPlane.Step + _planeHeight < _pictureHeight)
{
_startPosY += (int)EntityPlane.Step;
}
break;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (EntityPlane == null)
{
return;
}
Pen pen = new(Color.Black);
Brush bodyBrush = new SolidBrush(EntityPlane.BodyColor);
//раскраска основы
g.FillPolygon(bodyBrush, new[] {
new Point(_startPosX + 5, _startPosY),
new Point(_startPosX + 5, _startPosY + 55),
new Point(_startPosX + 130, _startPosY + 55),
new Point(_startPosX + 160, _startPosY + 40),
new Point(_startPosX + 130, _startPosY + 40),
new Point(_startPosX + 130, _startPosY + 25),
new Point(_startPosX + 55, _startPosY + 25) });
//раскраска ножек
g.FillRectangle(bodyBrush, _startPosX + 65, _startPosY + 55, 5, 15);
g.FillRectangle(bodyBrush, _startPosX + 125, _startPosY + 55, 5, 15);
//основа
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 25, 125, 30);
//хвост
g.DrawLine(pen, _startPosX + 5, _startPosY + 25, _startPosX + 5, _startPosY);
g.DrawLine(pen, _startPosX + 55, _startPosY + 25, _startPosX + 5, _startPosY);
//нос
g.DrawLine(pen, _startPosX + 130, _startPosY + 25, _startPosX + 160, _startPosY + 40);
g.DrawLine(pen, _startPosX + 130, _startPosY + 55, _startPosX + 160, _startPosY + 40);
g.DrawLine(pen, _startPosX + 130, _startPosY + 40, _startPosX + 160, _startPosY + 40);
//иллюминаторы
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 30, 10, 10);
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 30, 10, 10);
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 30, 10, 10);
//крыло сбоку
g.DrawEllipse(pen, _startPosX + 35, _startPosY + 43, 80, 7);
//ножки снизу
g.DrawLine(pen, _startPosX + 65, _startPosY + 55, _startPosX + 65, _startPosY + 70);
g.DrawLine(pen, _startPosX + 70, _startPosY + 55, _startPosX + 70, _startPosY + 70);
g.DrawLine(pen, _startPosX + 125, _startPosY + 55, _startPosX + 125, _startPosY + 70);
g.DrawLine(pen, _startPosX + 130, _startPosY + 55, _startPosX + 130, _startPosY + 70);
}
}
}