Создание папки Drawnings

This commit is contained in:
Павел Ладягин 2024-03-23 15:26:35 +04:00
parent a0f64e592f
commit ef5352ab0c
5 changed files with 154 additions and 83 deletions

View File

@ -1,5 +1,4 @@
 namespace ProjectAirplaneWithRadar.Drawnings
namespace ProjectAirplaneWithRadar
{ {
/// <summary> /// <summary>
/// Направление перемещения /// Направление перемещения

View File

@ -0,0 +1,75 @@
using ProjectAirplaneWithRadar.Entities;
namespace ProjectAirplaneWithRadar.Drawnings
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawingAirplaneWithRadar : DrawningAirplane
{
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="wheels">Шасси</param>
/// <param name="radar">Радар</param>
public DrawingAirplaneWithRadar(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool radar) : base(150, 93)
{
EntityAirplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, additionalColor, wheels, radar);
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public override void DrawTransport(Graphics g)
{
if (EntityAirplane == null || EntityAirplane is not EntityAirplaneWithRadar airplaneWithRadar || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(airplaneWithRadar.AdditionalColor);
if (airplaneWithRadar.Wheels)
{
//Задняя стойка
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10);
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10);
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10);
g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10);
//Передняя стойка
g.DrawRectangle(pen, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10);
g.FillRectangle(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10);
g.DrawEllipse(pen, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10);
}
_startPosY += 10;
base.DrawTransport(g);
_startPosY -= 10;
//Радар
if (airplaneWithRadar.Radar)
{
g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value + 40, 10, 10);
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 40, 10, 10);
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 30, 50, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 30, 50, 10);
}
}
}
}

View File

@ -1,14 +1,15 @@
namespace ProjectAirplaneWithRadar.Entities using ProjectAirplaneWithRadar.Entities;
namespace ProjectAirplaneWithRadar.Drawnings
{ {
/// <summary> public class DrawningAirplane
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawingAirplaneWithRadar
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность
/// </summary> /// </summary>
public EntityAirplaneWithRadar? EntityAirplaneWithRadar { get; private set; } public EntityAirplane? EntityAirplane { get; protected set; }
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
@ -23,43 +24,76 @@
/// <summary> /// <summary>
/// Левая координата прорисовки /// Левая координата прорисовки
/// </summary> /// </summary>
private int? _startPosX; protected int? _startPosX;
/// <summary> /// <summary>
/// Верхняя кооридната прорисовки /// Верхняя кооридната прорисовки
/// </summary> /// </summary>
private int? _startPosY; protected int? _startPosY;
/// <summary> /// <summary>
/// Ширина прорисовки самолета /// Ширина прорисовки самолета
/// </summary> /// </summary>
public readonly int PlaneWidth = 150; private readonly int PlaneWidth = 150;
/// <summary> /// <summary>
/// Высота прорисовки самолета /// Высота прорисовки самолета
/// </summary> /// </summary>
public readonly int PlaneHeight = 95; private readonly int PlaneHeight = 85;
/// <summary> /// <summary>
/// Инициализация свойств /// Координата X объекта
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> public int? GetPosX => _startPosX;
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param> /// <summary>
/// <param name="additionalColor">Дополнительный цвет</param> /// Координата Y объекта
/// <param name="wheels">Шасси</param> /// </summary>
/// <param name="radar">Радар</param> public int? GetPosY => _startPosY;
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool radar)
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => PlaneWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => PlaneHeight;
/// <summary>
/// Пустой конструктор
/// </summary>
private DrawningAirplane()
{ {
EntityAirplaneWithRadar = new EntityAirplaneWithRadar();
EntityAirplaneWithRadar.Init(speed, weight, bodyColor, additionalColor, wheels, radar);
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
_startPosX = null; _startPosX = null;
_startPosY = null; _startPosY = null;
} }
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawningAirplane(int speed, double weight, Color bodyColor) : this()
{
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор для наследников
/// </summary>
/// <param name="planeWidth">Ширина прорисовки самолета</param>
/// <param name="planeHeight">Высота прорисовки самолета</param>
protected DrawningAirplane(int planeWidth, int planeHeight) : this()
{
PlaneWidth = planeWidth;
PlaneHeight = planeHeight;
}
/// <summary> /// <summary>
/// Установка границ поля /// Установка границ поля
/// </summary> /// </summary>
@ -138,12 +172,12 @@
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns> /// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction) public bool MoveTransport(DirectionType direction)
{ {
if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue) if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return false; return false;
} }
int step = (int)EntityAirplaneWithRadar.Step; int step = (int)EntityAirplane.Step;
switch (direction) switch (direction)
{ {
//влево //влево
@ -184,81 +218,50 @@
/// Прорисовка объекта /// Прорисовка объекта
/// </summary> /// </summary>
/// <param name="g"></param> /// <param name="g"></param>
public void DrawTransport(Graphics g) public virtual void DrawTransport(Graphics g)
{ {
if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue) if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return; return;
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityAirplaneWithRadar.AdditionalColor);
//Шасси
if (EntityAirplaneWithRadar.Wheels)
{
//Задняя стойка
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10);
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10);
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10);
g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10);
//Передняя стойка
g.DrawRectangle(pen, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10);
g.FillRectangle(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10);
g.DrawEllipse(pen, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10);
}
//Радар
if (EntityAirplaneWithRadar.Radar)
{
g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value + 40, 10, 10);
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 40, 10, 10);
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 30, 50, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 30, 50, 10);
}
//Корпус //Корпус
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 50, 100, 30); g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 100, 30);
//Хвост //Хвост
Point[] points = { Point[] points = {
new Point(_startPosX.Value + 10, _startPosY.Value + 10), new Point(_startPosX.Value + 10, _startPosY.Value),
new Point(_startPosX.Value + 10, _startPosY.Value + 50), new Point(_startPosX.Value + 10, _startPosY.Value + 40),
new Point(_startPosX.Value + 50, _startPosY.Value + 50) new Point(_startPosX.Value + 50, _startPosY.Value + 40)
}; };
g.DrawPolygon(pen, points); g.DrawPolygon(pen, points);
//Кабина //Кабина
Point[] points2 = { Point[] points2 = {
new Point(_startPosX.Value + 110, _startPosY.Value + 45), new Point(_startPosX.Value + 110, _startPosY.Value + 35),
new Point(_startPosX.Value + 110, _startPosY.Value + 65), new Point(_startPosX.Value + 110, _startPosY.Value + 55),
new Point(_startPosX.Value + 150, _startPosY.Value + 65) new Point(_startPosX.Value + 150, _startPosY.Value + 55)
}; };
g.DrawPolygon(pen, points2); g.DrawPolygon(pen, points2);
Point[] points3 = { Point[] points3 = {
new Point(_startPosX.Value + 110, _startPosY.Value + 65), new Point(_startPosX.Value + 110, _startPosY.Value + 55),
new Point(_startPosX.Value + 110, _startPosY.Value + 85), new Point(_startPosX.Value + 110, _startPosY.Value + 75),
new Point(_startPosX.Value + 150, _startPosY.Value + 65) new Point(_startPosX.Value + 150, _startPosY.Value + 55)
}; };
g.DrawPolygon(pen, points3); g.DrawPolygon(pen, points3);
//Крыло //Крыло
Brush brBlack = new SolidBrush(Color.Black); Brush brBlack = new SolidBrush(EntityAirplane.BodyColor);
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 60, 70, 10); g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 50, 70, 10);
g.FillEllipse(brBlack, _startPosX.Value + 30, _startPosY.Value + 60, 70, 10); g.FillEllipse(brBlack, _startPosX.Value + 30, _startPosY.Value + 50, 70, 10);
//Хвостовой элерон //Хвостовой элерон
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 45, 30, 10); g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 35, 30, 10);
g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 45, 30, 10); g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 35, 30, 10);
} }
} }

View File

@ -1,11 +1,4 @@
using System; namespace ProjectAirplaneWithRadar.Entities
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ProjectAirplaneWithRadar.Entities
{ {
/// <summary> /// <summary>
/// Класс-сущность "Самолет" /// Класс-сущность "Самолет"

View File

@ -1,4 +1,5 @@
using ProjectAirplaneWithRadar.Entities; using ProjectAirplaneWithRadar.Drawnings;
using ProjectAirplaneWithRadar.Entities;
namespace ProjectAirplaneWithRadar namespace ProjectAirplaneWithRadar
{ {