Entities и DrawningOblects готовы
This commit is contained in:
parent
b7dcc0892e
commit
a6ecfa293f
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using AirplaneWithRadar.DrawningObjects;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
@ -50,14 +51,11 @@ namespace AirplaneWithRadar
|
||||
private void buttonCreateAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningAirplane = new DrawningAirplane();
|
||||
_drawningAirplane.Init(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_drawningAirplane = new DrawningAirplane(random.Next(100,100),random.Next(1000,3000), Color.FromArgbb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
@ -4,8 +4,10 @@ using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirplaneWithRadar.Entities;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
|
||||
namespace AirplaneWithRadar.DrawningObjects
|
||||
{/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
@ -14,7 +16,7 @@ namespace AirplaneWithRadar
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirplaneWithRadar? EntityAirplaneWithRadar{ get; private set; }
|
||||
public EntityAirplane? EntityAirplane{ get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -22,23 +24,23 @@ namespace AirplaneWithRadar
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
private int _pictureHeight;
|
||||
/// <summary>
|
||||
/// /// Левая координата прорисовки самолета
|
||||
/// </summary>
|
||||
private int _startPosX;
|
||||
protected int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки самолета
|
||||
/// </summary>
|
||||
private int _startPosY;
|
||||
protected int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _airplaneWidth = 200;
|
||||
protected readonly int _airplaneWidth = 200;
|
||||
/// <summary>
|
||||
/// Высота прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _airplaneHeight = 85;
|
||||
protected readonly int _airplaneHeight = 85;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
@ -46,24 +48,43 @@ namespace AirplaneWithRadar
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет фюзеляжа</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия радара</param>
|
||||
/// <param name="tank">Признак наличия доп.бака</param>
|
||||
/// <param name="pin">Признак наличия штыря</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 radar, bool tank, bool pin, int width, int height)
|
||||
public DrawningAirplane(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureWidth < _airplaneWidth || _pictureHeight < _airplaneHeight)
|
||||
{
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
EntityAirplaneWithRadar = new EntityAirplaneWithRadar();
|
||||
EntityAirplaneWithRadar.Init(speed, weight, bodyColor, additionalColor, radar, tank, pin);
|
||||
return true;
|
||||
EntityAirplane = new EntityAirplane(speed, weight, bodyColor, additionalColor);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <param name="airplaneWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="airplaneHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawningAirplane(int speed, double weight, Color bodyColor, Color additionalColor, int
|
||||
width, int height, int airplaneWidth, int airplaneHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_airplaneWidth = airplaneWidth;
|
||||
_airplaneHeight = airplaneHeight;
|
||||
if (_pictureWidth < _airplaneWidth || _pictureHeight < _airplaneHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EntityAirplane = new EntityAirplane(speed, weight, bodyColor, additionalColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
@ -81,7 +102,7 @@ namespace AirplaneWithRadar
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAirplaneWithRadar == null)
|
||||
if (EntityAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -89,30 +110,30 @@ namespace AirplaneWithRadar
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityAirplaneWithRadar.Step > 0)
|
||||
if (_startPosX - EntityAirplane.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityAirplaneWithRadar.Step;
|
||||
_startPosX -= (int)EntityAirplane.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityAirplaneWithRadar.Step > 0)
|
||||
if (_startPosY - EntityAirplane.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAirplaneWithRadar.Step;
|
||||
_startPosY -= (int)EntityAirplane.Step;
|
||||
}
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntityAirplaneWithRadar.Step + _airplaneWidth < _pictureWidth)
|
||||
if (_startPosX + EntityAirplane.Step + _airplaneWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityAirplaneWithRadar.Step;
|
||||
_startPosX += (int)EntityAirplane.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntityAirplaneWithRadar.Step + _airplaneHeight < _pictureHeight)
|
||||
if (_startPosY + EntityAirplane.Step + _airplaneHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAirplaneWithRadar.Step;
|
||||
_startPosY += (int)EntityAirplane.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -121,24 +142,16 @@ namespace AirplaneWithRadar
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAirplaneWithRadar == null)
|
||||
if (EntityAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen penBlack = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityAirplaneWithRadar.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityAirplaneWithRadar.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(EntityAirplane.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityAirplane.BodyColor);
|
||||
|
||||
// радар
|
||||
if (EntityAirplaneWithRadar.Radar)
|
||||
{
|
||||
g.FillEllipse(additionalBrush, _startPosX + 65, _startPosY + 25, 50, 10);
|
||||
g.DrawEllipse(penBlack, _startPosX + 65, _startPosY + 25, 50, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 85, _startPosY + 35, 10, 5);
|
||||
g.DrawRectangle(penBlack, _startPosX + 85, _startPosY + 35, 10, 5);
|
||||
}
|
||||
//фюзеляж
|
||||
g.FillRectangle(bodyBrush, _startPosX + 4, _startPosY + 40, 150, 30);
|
||||
g.DrawRectangle(penBlack, _startPosX + 4, _startPosY + 40, 150, 30);
|
||||
@ -175,19 +188,6 @@ namespace AirplaneWithRadar
|
||||
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 72), new Point(_startPosX + 150, _startPosY + 55));
|
||||
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 72), new Point(_startPosX + 190, _startPosY + 55));
|
||||
|
||||
// Штырь
|
||||
if (EntityAirplaneWithRadar.Pin)
|
||||
{
|
||||
g.DrawLine(penGray, new Point(_startPosX + 190, _startPosY + 55), new Point(_startPosX + 200, _startPosY + 55));
|
||||
}
|
||||
|
||||
// бак
|
||||
if (EntityAirplaneWithRadar.Tank)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 70, _startPosY + 65, 45, 15);
|
||||
g.FillPolygon(additionalBrush, new Point[] { new Point(_startPosX + 70, _startPosY + 65), new Point(_startPosX + 60, _startPosY + 72), new Point(_startPosX + 70, _startPosY + 80) });
|
||||
g.FillPolygon(additionalBrush, new Point[] { new Point(_startPosX + 115, _startPosY + 65), new Point(_startPosX + 125, _startPosY + 72), new Point(_startPosX + 115, _startPosY + 80) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirplaneWithRadar.Entities;
|
||||
|
||||
namespace AirplaneWithRadar.DrawningObjects
|
||||
{
|
||||
public class DrawningAirplaneWithRadar : DrawningAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет фюзеляжа</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия радара</param>
|
||||
/// <param name="tank">Признак наличия бака</param>
|
||||
/// <param name="pin">Признак наличия штыря</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||
public DrawningAirplaneWithRadar(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool radar, bool tank, bool pin, int width, int height) :
|
||||
base(speed, weight, bodyColor, additionalColor, width, height, 200, 85)
|
||||
{
|
||||
if (EntityAirplane != null)
|
||||
{
|
||||
EntityAirplane = new EntityAirplaneWithRadar(speed, weight, bodyColor,
|
||||
additionalColor, radar, tank, pin);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAirplane is not EntityAirplaneWithRadar airplaneWithRadar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen penBlack = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityAirplane.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityAirplane.BodyColor);
|
||||
Pen penGray = new Pen(Color.Gray);
|
||||
// радар
|
||||
if (airplaneWithRadar.Radar)
|
||||
{
|
||||
g.FillEllipse(additionalBrush, _startPosX + 65, _startPosY + 25, 50, 10);
|
||||
g.DrawEllipse(penBlack, _startPosX + 65, _startPosY + 25, 50, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 85, _startPosY + 35, 10, 5);
|
||||
g.DrawRectangle(penBlack, _startPosX + 85, _startPosY + 35, 10, 5);
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
// Штырь
|
||||
if (airplaneWithRadar.Pin)
|
||||
{
|
||||
g.DrawLine(penGray, new Point(_startPosX + 190, _startPosY + 55), new Point(_startPosX + 200, _startPosY + 55));
|
||||
}
|
||||
|
||||
// бак
|
||||
if (airplaneWithRadar.Tank)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 70, _startPosY + 65, 45, 15);
|
||||
g.FillPolygon(additionalBrush, new Point[] { new Point(_startPosX + 70, _startPosY + 65), new Point(_startPosX + 60, _startPosY + 72), new Point(_startPosX + 70, _startPosY + 80) });
|
||||
g.FillPolygon(additionalBrush, new Point[] { new Point(_startPosX + 115, _startPosY + 65), new Point(_startPosX + 125, _startPosY + 72), new Point(_startPosX + 115, _startPosY + 80) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,12 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
namespace AirplaneWithRadar.Entities
|
||||
{
|
||||
public class EntityAirplaneWithRadar
|
||||
/// <summary>
|
||||
/// Класс-сущность "Самолет"
|
||||
/// </summary>
|
||||
public class EntityAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -25,18 +28,6 @@ namespace AirplaneWithRadar
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия радара
|
||||
/// </summary>
|
||||
public bool Radar { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия доп.бака
|
||||
/// </summary>
|
||||
public bool Tank { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия штыря
|
||||
/// </summary>
|
||||
public bool Pin { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения самолета
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
@ -47,19 +38,13 @@ namespace AirplaneWithRadar
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия радара</param>
|
||||
/// <param name="tank">Признак наличия доп.бака</param>
|
||||
/// <param name="pin">Признак наличия штыря</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool radar, bool tank, bool pin)
|
||||
public EntityAirplane(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Radar = radar;
|
||||
Tank = tank;
|
||||
Pin = pin;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Самолет с радаром"
|
||||
/// </summary>
|
||||
public class EntityAirplaneWithRadar : EntityAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия радара
|
||||
/// </summary>
|
||||
public bool Radar { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия доп.бака
|
||||
/// </summary>
|
||||
public bool Tank { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия штыря
|
||||
/// </summary>
|
||||
public bool Pin { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса самолета с радаром
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия радара</param>
|
||||
/// <param name="tank">Признак наличия доп.бака</param>
|
||||
/// <param name="pin">Признак наличия штыря</param>
|
||||
public EntityAirplaneWithRadar(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool radar, bool tank, bool pin)
|
||||
{
|
||||
Radar = radar;
|
||||
Tank = tank;
|
||||
Pin = pin;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user