Compare commits
2 Commits
58deca3522
...
adc31a5780
Author | SHA1 | Date | |
---|---|---|---|
|
adc31a5780 | ||
|
b26c69667b |
@ -1,27 +0,0 @@
|
||||
namespace ProjectStormtrooper;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
@ -1,284 +0,0 @@
|
||||
namespace ProjectStormtrooper;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningStormtrooper
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityStormtrooper? EntityStormtrooper { 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 _drawningStormtrooperWidth = 150;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningStormtrooperHeight = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="dvigatel">Признак наличия обвеса</param>
|
||||
/// <param name="vint">Признак наличия антикрыла</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool dvigatel, bool vint)
|
||||
{
|
||||
EntityStormtrooper = new EntityStormtrooper();
|
||||
EntityStormtrooper.Init(speed, weight, bodyColor, additionalColor, dvigatel, vint);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_drawningStormtrooperWidth <= width && _drawningStormtrooperHeight <= height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
if (_startPosX + _drawningStormtrooperWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningStormtrooperWidth;
|
||||
}
|
||||
|
||||
if (_startPosY + _drawningStormtrooperHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningStormtrooperHeight;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (x < 0) x = 0;
|
||||
else if (x + _drawningStormtrooperWidth > _pictureWidth) x = _pictureWidth.Value - _drawningStormtrooperWidth;
|
||||
|
||||
if (y < 0) y = 0;
|
||||
else if (y + _drawningStormtrooperHeight > _pictureHeight) y = _pictureHeight.Value - _drawningStormtrooperHeight;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityStormtrooper == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityStormtrooper.Step > 0)
|
||||
_startPosX -= (int)EntityStormtrooper.Step;
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityStormtrooper.Step > 0)
|
||||
_startPosY -= (int)EntityStormtrooper.Step;
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningStormtrooperWidth + EntityStormtrooper.Step < _pictureWidth)
|
||||
_startPosX += (int)EntityStormtrooper.Step;
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningStormtrooperHeight + EntityStormtrooper.Step < _pictureHeight)
|
||||
_startPosY += (int)EntityStormtrooper.Step;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityStormtrooper == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityStormtrooper.AdditionalColor);
|
||||
|
||||
Brush nosBrush = new SolidBrush(Color.Black);
|
||||
|
||||
///отрисовка носа
|
||||
Point p = new Point(_startPosX.Value +10, _startPosY.Value + 60 );
|
||||
Point p2 = new Point(_startPosX.Value + 30, _startPosY.Value + 50);
|
||||
Point p3 = new Point(_startPosX.Value + 30, _startPosY.Value + 70);
|
||||
Point p4 = new Point(_startPosX.Value +10, _startPosY.Value + 60);
|
||||
|
||||
Brush bortBrush = new SolidBrush(EntityStormtrooper.BodyColor);
|
||||
|
||||
///отрисовка борта
|
||||
g.FillRectangle(bortBrush, _startPosX.Value + 30, _startPosY.Value + 50, 130, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 50, 130, 20);
|
||||
|
||||
///отрисовка вепхнего крыла
|
||||
Point p5 = new Point(_startPosX.Value + 50, _startPosY.Value);
|
||||
Point p6 = new Point(_startPosX.Value + 65, _startPosY.Value);
|
||||
Point p7 = new Point(_startPosX.Value + 80, _startPosY.Value + 50);
|
||||
Point p8 = new Point(_startPosX.Value + 50, _startPosY.Value + 50);
|
||||
Point p9 = new Point(_startPosX.Value + 50, _startPosY.Value);
|
||||
|
||||
///отрисовка нижнего крыла
|
||||
Point p10 = new Point(_startPosX.Value +50, _startPosY.Value + 70);
|
||||
Point p11 = new Point(_startPosX.Value +80, _startPosY.Value + 70);
|
||||
Point p12 = new Point(_startPosX.Value +65, _startPosY.Value + 120);
|
||||
Point p13 = new Point(_startPosX.Value +50, _startPosY.Value + 120);
|
||||
Point p14 = new Point(_startPosX.Value +50, _startPosY.Value + 70);
|
||||
|
||||
///отрисовка верхнего хвоста
|
||||
Point p15 = new Point(_startPosX.Value + 125, _startPosY.Value + 50);
|
||||
Point p16 = new Point(_startPosX.Value + 125, _startPosY.Value + 37);
|
||||
Point p17 = new Point(_startPosX.Value + 150, _startPosY.Value + 20);
|
||||
Point p18 = new Point(_startPosX.Value + 150, _startPosY.Value + 50);
|
||||
Point p19 = new Point(_startPosX.Value + 125, _startPosY.Value + 50);
|
||||
|
||||
///отрисовка нижнего хвоста
|
||||
Point p20 = new Point(_startPosX.Value + 125, _startPosY.Value + 70);
|
||||
Point p21 = new Point(_startPosX.Value + 125, _startPosY.Value + 83);
|
||||
Point p22 = new Point(_startPosX.Value + 150, _startPosY.Value + 100);
|
||||
Point p23 = new Point(_startPosX.Value + 150, _startPosY.Value + 70);
|
||||
Point p24 = new Point(_startPosX.Value + 125, _startPosY.Value + 70);
|
||||
|
||||
///отрисовка крепления нижнего двигателя
|
||||
Point p33 = new Point(_startPosX.Value + 90, _startPosY.Value + 70);
|
||||
Point p34 = new Point(_startPosX.Value + 95, _startPosY.Value + 75);
|
||||
Point p35 = new Point(_startPosX.Value + 110, _startPosY.Value + 75);
|
||||
Point p36 = new Point(_startPosX.Value + 115, _startPosY.Value + 70);
|
||||
|
||||
///отрисовка крепления верхнего двигателя
|
||||
Point p37 = new Point(_startPosX.Value + 90, _startPosY.Value + 50);
|
||||
Point p38 = new Point(_startPosX.Value + 95, _startPosY.Value + 45);
|
||||
Point p39 = new Point(_startPosX.Value + 110, _startPosY.Value + 45);
|
||||
Point p40 = new Point(_startPosX.Value + 115, _startPosY.Value + 50);
|
||||
|
||||
///отрисовка верхней ракеты
|
||||
g.DrawEllipse(pen, _startPosX.Value +88, _startPosY.Value + 35, 34, 10);
|
||||
|
||||
///отрисовка нижней ракеты
|
||||
g.DrawEllipse(pen, _startPosX.Value + 88, _startPosY.Value + 75, 34, 10);
|
||||
|
||||
///отрисовка винта
|
||||
Point p25 = new Point(_startPosX.Value +10, _startPosY.Value + 60);
|
||||
Point p26 = new Point(_startPosX.Value +5, _startPosY.Value + 35);
|
||||
Point p27 = new Point(_startPosX.Value + 15, _startPosY.Value + 35);
|
||||
Point p28 = new Point(_startPosX.Value +10, _startPosY.Value + 60);
|
||||
|
||||
|
||||
|
||||
Point p29 = new Point(_startPosX.Value + 10, _startPosY.Value + 60);
|
||||
Point p30 = new Point(_startPosX.Value + 5, _startPosY.Value + 85);
|
||||
Point p31 = new Point(_startPosX.Value + 15, _startPosY.Value + 85);
|
||||
Point p32 = new Point(_startPosX.Value + 10, _startPosY.Value + 60);
|
||||
|
||||
if (EntityStormtrooper.Vint)
|
||||
{
|
||||
Point[] p_vint = { p25, p26, p27, p28, p29, p30, p31, p32 };
|
||||
g.DrawPolygon(pen, p_vint);
|
||||
}
|
||||
|
||||
// отрисовка двигателей
|
||||
if (EntityStormtrooper.Dvigatel)
|
||||
{
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 25, 15, 15);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 75, 15, 15);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Point[] p_nos = { p, p2, p3, p4, };
|
||||
Point[] p_krilo1 = { p5, p6, p7, p8, p9 };
|
||||
Point[] p_krilo2 = { p10, p11, p12, p13, p14 };
|
||||
Point[] p_hvost1 = { p15, p16, p17, p18, p19 };
|
||||
Point[] p_hvost2 = { p20, p21, p22, p23, p24 };
|
||||
Point[] p_kreplenie2 = { p33, p34, p35, p36 };
|
||||
Point[] p_kreplenie1 = { p37, p38, p39, p40 };
|
||||
|
||||
g.FillPolygon(nosBrush, p_nos);
|
||||
g.FillPolygon(bortBrush, p_krilo1);
|
||||
g.FillPolygon(bortBrush, p_krilo2);
|
||||
g.FillPolygon(bortBrush, p_hvost1);
|
||||
g.FillPolygon(bortBrush, p_hvost2);
|
||||
|
||||
|
||||
g.DrawPolygon(pen, p_krilo1);
|
||||
g.DrawPolygon(pen, p_krilo2);
|
||||
g.DrawPolygon(pen, p_hvost1);
|
||||
g.DrawPolygon(pen, p_hvost2);
|
||||
g.DrawPolygon(pen, p_kreplenie2);
|
||||
g.DrawPolygon(pen, p_kreplenie1);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
27
ProjectStormtrooper/Drawnings/DirectionType.cs
Normal file
27
ProjectStormtrooper/Drawnings/DirectionType.cs
Normal file
@ -0,0 +1,27 @@
|
||||
namespace ProjectStormtrooper.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
250
ProjectStormtrooper/Drawnings/DrawningAirplane.cs
Normal file
250
ProjectStormtrooper/Drawnings/DrawningAirplane.cs
Normal file
@ -0,0 +1,250 @@
|
||||
using ProjectStormtrooper.Entites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.Drawnings;
|
||||
|
||||
public class DrawningAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirplane? EntityAirplane { 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>
|
||||
private readonly int _drawningAirplaneWidth = 153;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawningAirplaneHeight = 110;
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningAirplaneWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningAirplaneHeight;
|
||||
|
||||
/// <summary>
|
||||
/// пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningAirplane()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = 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="drawningAirplaneWidth">Ширина прорисовки самолета</param>
|
||||
/// <param name="drawningAirplaneHeight">Высота прорисовки самолета</param>
|
||||
protected DrawningAirplane(int drawningAirplaneWidth, int drawningAirplaneHeight) : this()
|
||||
{
|
||||
_drawningAirplaneWidth = drawningAirplaneWidth;
|
||||
_pictureHeight = drawningAirplaneHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityAirplane.Step > 0)
|
||||
_startPosX -= (int)EntityAirplane.Step;
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityAirplane.Step > 0)
|
||||
_startPosY -= (int)EntityAirplane.Step;
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningAirplaneWidth + EntityAirplane.Step < _pictureWidth)
|
||||
_startPosX += (int)EntityAirplane.Step;
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningAirplaneHeight + EntityAirplane.Step < _pictureHeight)
|
||||
_startPosY += (int)EntityAirplane.Step;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
///отрисовка носа
|
||||
Point p = new Point(_startPosX.Value, _startPosY.Value + 50);
|
||||
Point p2 = new Point(_startPosX.Value + 20, _startPosY.Value + 40);
|
||||
Point p3 = new Point(_startPosX.Value + 20, _startPosY.Value + 60);
|
||||
Point p4 = new Point(_startPosX.Value, _startPosY.Value + 50);
|
||||
|
||||
Brush bortBrush = new SolidBrush(EntityAirplane.BodyColor);
|
||||
|
||||
///отрисовка борта
|
||||
g.FillRectangle(bortBrush, _startPosX.Value + 20, _startPosY.Value + 40, 120, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 40, 120, 20);
|
||||
|
||||
///отрисовка вепхнего крыла
|
||||
Point p5 = new Point(_startPosX.Value + 40, _startPosY.Value);
|
||||
Point p6 = new Point(_startPosX.Value + 55, _startPosY.Value);
|
||||
Point p7 = new Point(_startPosX.Value + 70, _startPosY.Value + 40);
|
||||
Point p8 = new Point(_startPosX.Value + 40, _startPosY.Value + 40);
|
||||
Point p9 = new Point(_startPosX.Value + 40, _startPosY.Value);
|
||||
|
||||
///отрисовка нижнего крыла
|
||||
Point p10 = new Point(_startPosX.Value + 40, _startPosY.Value + 60);
|
||||
Point p11 = new Point(_startPosX.Value + 70, _startPosY.Value + 60);
|
||||
Point p12 = new Point(_startPosX.Value + 55, _startPosY.Value + 110);
|
||||
Point p13 = new Point(_startPosX.Value + 40, _startPosY.Value + 110);
|
||||
Point p14 = new Point(_startPosX.Value + 40, _startPosY.Value + 60);
|
||||
|
||||
///отрисовка верхнего хвоста
|
||||
Point p15 = new Point(_startPosX.Value + 115, _startPosY.Value + 40);
|
||||
Point p16 = new Point(_startPosX.Value + 115, _startPosY.Value + 27);
|
||||
Point p17 = new Point(_startPosX.Value + 140, _startPosY.Value + 10);
|
||||
Point p18 = new Point(_startPosX.Value + 140, _startPosY.Value + 40);
|
||||
Point p19 = new Point(_startPosX.Value + 115, _startPosY.Value + 40);
|
||||
|
||||
///отрисовка нижнего хвоста
|
||||
Point p20 = new Point(_startPosX.Value + 115, _startPosY.Value + 60);
|
||||
Point p21 = new Point(_startPosX.Value + 115, _startPosY.Value + 73);
|
||||
Point p22 = new Point(_startPosX.Value + 140, _startPosY.Value + 90);
|
||||
Point p23 = new Point(_startPosX.Value + 140, _startPosY.Value + 60);
|
||||
Point p24 = new Point(_startPosX.Value + 115, _startPosY.Value + 60);
|
||||
|
||||
|
||||
|
||||
Point[] p_nos = { p, p2, p3, p4, };
|
||||
Point[] p_krilo1 = { p5, p6, p7, p8, p9 };
|
||||
Point[] p_krilo2 = { p10, p11, p12, p13, p14 };
|
||||
Point[] p_hvost1 = { p15, p16, p17, p18, p19 };
|
||||
Point[] p_hvost2 = { p20, p21, p22, p23, p24 };
|
||||
|
||||
|
||||
g.FillPolygon(bortBrush, p_nos);
|
||||
g.FillPolygon(bortBrush, p_krilo1);
|
||||
g.FillPolygon(bortBrush, p_krilo2);
|
||||
g.FillPolygon(bortBrush, p_hvost1);
|
||||
g.FillPolygon(bortBrush, p_hvost2);
|
||||
|
||||
g.DrawPolygon(pen, p_nos);
|
||||
g.DrawPolygon(pen, p_krilo1);
|
||||
g.DrawPolygon(pen, p_krilo2);
|
||||
g.DrawPolygon(pen, p_hvost1);
|
||||
g.DrawPolygon(pen, p_hvost2);
|
||||
|
||||
}
|
||||
}
|
93
ProjectStormtrooper/Drawnings/DrawningStormtrooper.cs
Normal file
93
ProjectStormtrooper/Drawnings/DrawningStormtrooper.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using ProjectStormtrooper.Entites;
|
||||
|
||||
namespace ProjectStormtrooper.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningStormtrooper : DrawningAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="dvigatel">Признак наличия обвеса</param>
|
||||
/// <param name="vint">Признак наличия антикрыла</param>
|
||||
public DrawningStormtrooper(int speed, double weight, Color bodyColor, Color additionalColor, bool dvigatel, bool vint) : base(153, 110)
|
||||
{
|
||||
EntityAirplane = new EntityStormtrooper(speed, weight, bodyColor, additionalColor, dvigatel, vint);
|
||||
}
|
||||
|
||||
public DrawningStormtrooper(int speed, double weight, Color bodyColor, Color additionalColor, bool dvigatel, bool vint, bool v) : this(speed, weight, bodyColor, additionalColor, dvigatel, vint)
|
||||
{
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAirplane == null || EntityAirplane is not EntityStormtrooper stormtrooper || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(stormtrooper.AdditionalColor);
|
||||
|
||||
if (stormtrooper.Vint)
|
||||
{
|
||||
///отрисовка винта
|
||||
Point p25 = new Point(_startPosX.Value + 10, _startPosY.Value + 60);
|
||||
Point p26 = new Point(_startPosX.Value + 5, _startPosY.Value + 35);
|
||||
Point p27 = new Point(_startPosX.Value + 15, _startPosY.Value + 35);
|
||||
Point p28 = new Point(_startPosX.Value + 10, _startPosY.Value + 60);
|
||||
|
||||
|
||||
|
||||
Point p29 = new Point(_startPosX.Value + 10, _startPosY.Value + 60);
|
||||
Point p30 = new Point(_startPosX.Value + 5, _startPosY.Value + 85);
|
||||
Point p31 = new Point(_startPosX.Value + 15, _startPosY.Value + 85);
|
||||
Point p32 = new Point(_startPosX.Value + 10, _startPosY.Value + 60);
|
||||
Point[] p_vint = { p25, p26, p27, p28, p29, p30, p31, p32 };
|
||||
g.DrawPolygon(pen, p_vint);
|
||||
|
||||
///отрисовка крепления нижнего двигателя
|
||||
Point p33 = new Point(_startPosX.Value + 90, _startPosY.Value + 66);
|
||||
Point p34 = new Point(_startPosX.Value + 95, _startPosY.Value + 70);
|
||||
Point p35 = new Point(_startPosX.Value + 110, _startPosY.Value + 70);
|
||||
Point p36 = new Point(_startPosX.Value + 115, _startPosY.Value + 65);
|
||||
|
||||
///отрисовка крепления верхнего двигателя
|
||||
Point p37 = new Point(_startPosX.Value + 90, _startPosY.Value + 45);
|
||||
Point p38 = new Point(_startPosX.Value + 95, _startPosY.Value + 40);
|
||||
Point p39 = new Point(_startPosX.Value + 110, _startPosY.Value + 40);
|
||||
Point p40 = new Point(_startPosX.Value + 115, _startPosY.Value + 45);
|
||||
|
||||
///отрисовка верхней ракеты
|
||||
g.DrawEllipse(pen, _startPosX.Value + 88, _startPosY.Value + 30, 34, 10);
|
||||
|
||||
///отрисовка нижней ракеты
|
||||
g.DrawEllipse(pen, _startPosX.Value + 88, _startPosY.Value + 70, 34, 10);
|
||||
|
||||
Point[] p_kreplenie2 = { p33, p34, p35, p36 };
|
||||
Point[] p_kreplenie1 = { p37, p38, p39, p40 };
|
||||
|
||||
g.DrawPolygon(pen, p_kreplenie2);
|
||||
g.DrawPolygon(pen, p_kreplenie1);
|
||||
}
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
|
||||
// отрисовка двигателей
|
||||
if (stormtrooper.Dvigatel)
|
||||
{
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 25, 15, 15);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 75, 15, 15);
|
||||
}
|
||||
}
|
||||
}
|
47
ProjectStormtrooper/Entites/EntityAirplane.cs
Normal file
47
ProjectStormtrooper/Entites/EntityAirplane.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.Entites;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Самолет"
|
||||
/// </summary>
|
||||
|
||||
public class EntityAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения самолета
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// консруктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityAirplane(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
59
ProjectStormtrooper/Entites/EntityStormtrooper.cs
Normal file
59
ProjectStormtrooper/Entites/EntityStormtrooper.cs
Normal file
@ -0,0 +1,59 @@
|
||||
namespace ProjectStormtrooper.Entites;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Спортивный автомобиль"
|
||||
/// </summary>
|
||||
public class EntityStormtrooper : EntityAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
public bool Dvigatel { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// </summary>
|
||||
public bool Vint { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения самолета
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса штурмовика
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="dvigatel">Признак наличия обвеса</param>
|
||||
/// <param name="vint">Признак наличия антикрыла</param>
|
||||
public EntityStormtrooper(int speed, double weight, Color bodyColor, Color additionalColor, bool dvigatel, bool vint) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Dvigatel = dvigatel;
|
||||
Vint = vint;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
namespace ProjectStormtrooper;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Спортивный автомобиль"
|
||||
/// </summary>
|
||||
public class EntityStormtrooper
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
public bool Dvigatel { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// </summary>
|
||||
public bool Vint { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="dvigatel">Признак наличия обвеса</param>
|
||||
/// <param name="vint">Признак наличия антикрыла</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool dvigatel, bool vint)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Dvigatel = dvigatel;
|
||||
Vint = vint;
|
||||
}
|
||||
}
|
20
ProjectStormtrooper/FormStormtrooper.Designer.cs
generated
20
ProjectStormtrooper/FormStormtrooper.Designer.cs
generated
@ -34,6 +34,7 @@ partial class FormStormtrooper
|
||||
buttonUp = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateAirplane = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -52,11 +53,11 @@ partial class FormStormtrooper
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 477);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(94, 29);
|
||||
buttonCreate.Size = new Size(325, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "создать";
|
||||
buttonCreate.Text = "создать штурмовик";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreateStormtrooper_Click;
|
||||
buttonCreate.Click += buttonCreateStormtrooper_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
@ -102,9 +103,21 @@ partial class FormStormtrooper
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateAirplane
|
||||
//
|
||||
buttonCreateAirplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateAirplane.Location = new Point(343, 477);
|
||||
buttonCreateAirplane.Name = "buttonCreateAirplane";
|
||||
buttonCreateAirplane.Size = new Size(325, 29);
|
||||
buttonCreateAirplane.TabIndex = 6;
|
||||
buttonCreateAirplane.Text = "создать самолет";
|
||||
buttonCreateAirplane.UseVisualStyleBackColor = true;
|
||||
buttonCreateAirplane.Click += ButtonCreateAirplane_Click;
|
||||
//
|
||||
// FormStormtrooper
|
||||
//
|
||||
ClientSize = new Size(1268, 518);
|
||||
Controls.Add(buttonCreateAirplane);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonUp);
|
||||
@ -125,5 +138,6 @@ partial class FormStormtrooper
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateAirplane;
|
||||
}
|
||||
|
||||
|
@ -4,16 +4,19 @@ using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectStormtrooper.Drawnings;
|
||||
|
||||
namespace ProjectStormtrooper;
|
||||
|
||||
public partial class FormStormtrooper : Form
|
||||
{
|
||||
|
||||
private DrawningStormtrooper? _drawningStormtrooper;
|
||||
private DrawningAirplane? _drawningAirplane;
|
||||
|
||||
public FormStormtrooper()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -24,46 +27,68 @@ public partial class FormStormtrooper : Form
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningStormtrooper == null)
|
||||
if (_drawningAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxStormtrooper.Width,
|
||||
pictureBoxStormtrooper.Height);
|
||||
Bitmap bmp = new(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningStormtrooper.DrawTransport(gr);
|
||||
_drawningAirplane.DrawTransport(gr);
|
||||
pictureBoxStormtrooper.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateStormtrooper_Click(object sender, EventArgs e)
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningStormtrooper = new DrawningStormtrooper();
|
||||
_drawningStormtrooper.Init(random.Next(650, 700), random.Next(15760,
|
||||
16130),
|
||||
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)));
|
||||
_drawningStormtrooper.SetPictureSize(pictureBoxStormtrooper.Width,
|
||||
pictureBoxStormtrooper.Height);
|
||||
_drawningStormtrooper.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningAirplane):
|
||||
_drawningAirplane = new DrawningAirplane(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningStormtrooper):
|
||||
_drawningAirplane = new DrawningStormtrooper(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)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawningAirplane.SetPictureSize(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// Обработка нажатия кнопки "Создать штурмовик"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
|
||||
private void buttonCreateStormtrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooper));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать самолет"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
///
|
||||
private void ButtonCreateAirplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirplane));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningStormtrooper == null)
|
||||
if (_drawningAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -73,19 +98,19 @@ public partial class FormStormtrooper : Form
|
||||
{
|
||||
case "buttonUp":
|
||||
result =
|
||||
_drawningStormtrooper.MoveTransport(DirectionType.Up);
|
||||
_drawningAirplane.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result =
|
||||
_drawningStormtrooper.MoveTransport(DirectionType.Down);
|
||||
_drawningAirplane.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result =
|
||||
_drawningStormtrooper.MoveTransport(DirectionType.Left);
|
||||
_drawningAirplane.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawningStormtrooper.MoveTransport(DirectionType.Right);
|
||||
_drawningAirplane.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
@ -94,4 +119,10 @@ public partial class FormStormtrooper : Form
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Шаг"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user