Добавление интерфейса

This commit is contained in:
devil_1nc 2022-09-26 22:34:19 +04:00
parent a367bf8cea
commit 1fd12d0fae
7 changed files with 288 additions and 23 deletions

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPlane
{
internal class DrawingObject : IDrawingObject
{
private DrawingPlane _plane = null;
public DrawingObject(DrawingPlane plane)
{
_plane = plane;
}
public float Step => _plane?.Plane?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _plane?.GetCurrentPosition() ?? default;
}
public void MoveObject(Direction direction)
{
_plane?.MoveTransport(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_plane.SetPosition(x, y, width, height);
}
void IDrawingObject.DrawingObject(Graphics g)
{
// TODO
}
}
}

View File

@ -12,15 +12,15 @@ namespace ProjectPlane
/// <summary>
/// Класс-сущность
/// </summary>
public EntityPlane Plane { get; private set; }
public EntityPlane Plane { get; protected set; }
/// <summary>
/// Левая координата отрисовки самолета
/// </summary>
private float _startPosX;
protected float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки самолета
/// </summary>
private float _startPosY;
/// </summary>
protected float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -56,13 +56,29 @@ namespace ProjectPlane
Plane = new EntityPlane(speed, weight, bodyColor);
}
/// <summary>
/// Установка позиции самолета
/// Инициализация свойств
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public void SetPosition(int x, int y, int width, int height)
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес самолета</param>
/// <param name="bodyColor">Цвет корпуса</param>
/// <param name="planeWidth">Ширина отрисовки самолета</param>
/// <param name="planeHeight">Высота отрисовки самолета</param>
protected DrawingPlane(int speed, float weight, Color bodyColor, int planeWidth, int planeHeight)
: this(speed, weight, bodyColor)
{
_planeWidth = planeWidth;
_planeHeight = planeHeight;
}
/// <summary>
/// Установка позиции самолета
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
///
public void SetPosition(int x, int y, int width, int height)
{
if (x >= _minX && x <= width && y >= _minY && y <= height)
{
@ -120,7 +136,7 @@ namespace ProjectPlane
/// Отрисовка самолета
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@ -175,6 +191,7 @@ namespace ProjectPlane
// window
Brush brBlue = new SolidBrush(Color.LightBlue);
Brush brBlack = new SolidBrush(Color.Black);
Point[] Triangle3 = new Point[3];
Triangle3[0].X = Convert.ToInt32(_startPosX + 108); Triangle3[0].Y = Convert.ToInt32(_startPosY - 2);
@ -184,13 +201,11 @@ namespace ProjectPlane
g.DrawLine(pen, _startPosX + 37, _startPosY + 20, _startPosX + 37, _startPosY + 25);
g.DrawLine(pen, _startPosX + 32, _startPosY + 25, _startPosX + 40, _startPosY + 25);
g.DrawRectangle(pen, _startPosX + 32, _startPosY + 25, 3, 3);
g.DrawRectangle(pen, _startPosX + 39, _startPosY + 25, 3, 3);
g.FillRectangle(brBlack, _startPosX + 32, _startPosY + 25, 3, 3);
g.FillRectangle(brBlack, _startPosX + 39, _startPosY + 25, 3, 3);
g.DrawLine(pen, _startPosX + 102, _startPosY + 20, _startPosX + 102, _startPosY + 25);
g.DrawRectangle(pen, _startPosX + 101, _startPosY + 25, 3, 3);
Brush brBlack = new SolidBrush(Color.Black);
g.FillRectangle(brBlack, _startPosX + 101, _startPosY + 25, 3, 3);
g.FillRectangle(brBlack, _startPosX + 5, _startPosY - 2, 18, 7);
g.FillEllipse(brBlack, _startPosX, _startPosY - 2, 7, 7);
@ -224,5 +239,9 @@ namespace ProjectPlane
_startPosY = _pictureHeight.Value - _planeHeight;
}
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _planeWidth, _startPosY + _planeHeight);
}
}
}

View File

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPlane
{
internal class DrawingWarPlane : DrawingPlane
{
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public DrawingWarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool isBomber, bool isFighter, bool superTurbine) :
base(speed, weight, bodyColor, 110, 60)
{
Plane = new EntityWarPlane(speed, weight, bodyColor, dopColor, isBomber, isFighter, superTurbine);
}
public override void DrawTransport(Graphics g)
{
if (Plane is not EntityWarPlane warplane)
{
return;
}
Pen pen = new(Color.Black);
Brush dopBrush = new SolidBrush(warplane.DopColor);
Brush Brush = new SolidBrush(warplane.BodyColor);
Brush brBlue = new SolidBrush(Color.LightBlue);
Brush brBlack = new SolidBrush(Color.Black);
if (warplane.SuperTurbine)
{
g.FillRectangle(Brush, _startPosX, _startPosY, 30, 22);
g.DrawLine(pen, _startPosX, _startPosY + 22, _startPosX + 30, _startPosY + 22);
g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 30, _startPosY);
}
_startPosX += 10;
_startPosY += 5;
base.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 5;
if (warplane.IsBomber)
{
g.FillEllipse(brBlack, _startPosX + 88, _startPosY, 4, 4);
g.FillRectangle(Brush, _startPosX + 60, _startPosY, 30, 12);
}
if (warplane.IsFighter)
{
Point[] Nose = new Point[4];
Nose[0].X = Convert.ToInt32(_startPosX + 118); Nose[0].Y = Convert.ToInt32(_startPosY + 2);
Nose[1].X = Convert.ToInt32(_startPosX + 155); Nose[1].Y = Convert.ToInt32(_startPosY + 2);
Nose[2].X = Convert.ToInt32(_startPosX + 118); Nose[2].Y = Convert.ToInt32(_startPosY + 25);
Nose[3].X = Convert.ToInt32(_startPosX + 98); Nose[3].Y = Convert.ToInt32(_startPosY + 25);
g.FillPolygon(Brush, Nose);
Point[] NoseWin = new Point[3];
NoseWin[0].X = Convert.ToInt32(_startPosX + 120); NoseWin[0].Y = Convert.ToInt32(_startPosY + 4);
NoseWin[1].X = Convert.ToInt32(_startPosX + 148); NoseWin[1].Y = Convert.ToInt32(_startPosY + 4);
NoseWin[2].X = Convert.ToInt32(_startPosX + 132); NoseWin[2].Y = Convert.ToInt32(_startPosY + 14);
g.FillPolygon(brBlue, NoseWin);
}
}
}
}

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPlane
{
/// <summary>
/// Класс-сущность "Военный самолет"
/// </summary>
internal class EntityWarPlane : EntityPlane
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; private set; }
/// <summary>
/// Бомбандировщик ли
/// </summary>
public bool IsBomber { get; private set; }
/// <summary>
/// Истребитель ли
/// </summary>
public bool IsFighter { get; private set; }
/// <summary>
/// наличие супертурбины
/// </summary>
public bool SuperTurbine { get; private set; }
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param>
///
public EntityWarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool superturbine) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
IsBomber = bodyKit;
IsFighter = wing;
SuperTurbine = superturbine;
}
}
}

View File

@ -38,6 +38,7 @@
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@ -132,11 +133,23 @@
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
this.toolStripStatusLabelBodyColor.Text = "Color";
//
// buttonCreateModif
//
this.buttonCreateModif.BackColor = System.Drawing.SystemColors.ControlLight;
this.buttonCreateModif.Location = new System.Drawing.Point(138, 376);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(115, 47);
this.buttonCreateModif.TabIndex = 10;
this.buttonCreateModif.Text = "Modificate";
this.buttonCreateModif.UseVisualStyleBackColor = false;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
//
// FormPlane
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
@ -167,5 +180,6 @@
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreateModif;
}
}

View File

@ -19,8 +19,17 @@
_plane?.DrawTransport(gr);
pictureBoxPlane.Image = bmp;
}
private void SetData()
{
Random rand = new();
_plane.SetPosition(rand.Next(5, 100), rand.Next(40, 100),
pictureBoxPlane.Width, pictureBoxPlane.Height);
toolStripStatusLabelSpeed.Text = $"Speed: {_plane.Plane.Speed}";
toolStripStatusLabelWeight.Text = $"Weiht: {_plane.Plane.Weight}";
toolStripStatusLabelBodyColor.Text = $"Color: {_plane.Plane.BodyColor.Name}";
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
/// "Обработка нажатия на кнопки движения"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
@ -49,12 +58,8 @@
{
Random rand = new Random();
_plane = new DrawingPlane(rand.Next(200, 500), rand.Next(2000, 3000),
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)));
_plane.SetPosition(rand.Next(5, 100), rand.Next(40, 100),
pictureBoxPlane.Width, pictureBoxPlane.Height);
toolStripStatusLabelSpeed.Text = $"Speed: {_plane.Plane.Speed}";
toolStripStatusLabelWeight.Text = $"Weiht: {_plane.Plane.Weight}";
toolStripStatusLabelBodyColor.Text = $"Color: {_plane.Plane.BodyColor.Name}";
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)));
SetData();
Draw();
}
private void PictureBoxCar_Resize(object sender, EventArgs e)
@ -62,5 +67,20 @@
_plane?.ChangeBorders(pictureBoxPlane.Width, pictureBoxPlane.Height);
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_plane = new DrawingWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPlane
{
internal interface IDrawingObject
{
/// <summary>
/// Шаг перемещения объекта
/// </summary>
public float Step { get; }
/// <summary>
/// Установка позиции объекта
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина полотна</param>
/// <param name="height">Высота полотна</param>
void SetObject(int x, int y, int width, int height);
/// <summary>
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
/// <returns></returns>
void MoveObject(Direction direction);
/// <summary>
/// Отрисовка объекта
/// </summary>
/// <param name="g"></param>
void DrawingObject(Graphics g);
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
}
}