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

This commit is contained in:
Denis 2022-10-06 02:47:38 +04:00
parent 7196d002ec
commit ee82eb4206
6 changed files with 96 additions and 8 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirplaneWithRadar
{
internal class DrawingAirplane
internal class DrawningAirplane
{
public EntityAirplane Airplane { get; protected set; }
protected float _startPosX;
@ -15,11 +15,11 @@ namespace AirplaneWithRadar
private int? _pictureHeight = null;
private readonly int _airplaneWidth = 50;
private readonly int _airplaneHeight = 27;
public DrawingAirplane(int speed, float weight, Color bodyColor)
public DrawningAirplane(int speed, float weight, Color bodyColor)
{
Airplane = new EntityAirplane(speed, weight, bodyColor);
}
protected DrawingAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) :
protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) :
this(speed, weight, bodyColor)
{
_airplaneWidth = airplaneWidth;
@ -126,5 +126,13 @@ namespace AirplaneWithRadar
_startPosY = _pictureHeight.Value - _airplaneHeight;
}
}
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _airplaneWidth, _startPosY + _airplaneHeight);
}
}
}

View File

@ -6,10 +6,10 @@ using System.Threading.Tasks;
namespace AirplaneWithRadar
{
internal class DrawningAirplaneWithRadar : DrawingAirplane
internal class DrawningAirplaneWithRadar : DrawningAirplane
{
public DrawningAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool ladder, bool window) :
base(speed, weight, bodyColor, 135, 60)
base(speed, weight, bodyColor, 50, 27)
{
Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, ladder, window);
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
internal class DrawningObjectAirplane : IDrawningObject
{
private DrawningAirplane _airplane = null;
public DrawningObjectAirplane(DrawningAirplane airplane)
{
_airplane = airplane;
}
public float Step => _airplane?.Airplane?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _airplane?.GetCurrentPosition() ?? default;
}
public void MoveObject(Direction direction)
{
_airplane?.MoveTransport(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_airplane.SetPosition(x, y, width, height);
}
void IDrawningObject.DrawningObject(Graphics g)
{
_airplane.DrawTransport(g);
}
}
}

View File

@ -88,7 +88,7 @@
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(11, 392);
this.buttonCreate.Location = new System.Drawing.Point(11, 391);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 2;

View File

@ -2,7 +2,7 @@ namespace AirplaneWithRadar
{
public partial class FormAirplane : Form
{
private DrawingAirplane _airplane;
private DrawningAirplane _airplane;
public FormAirplane()
{
InitializeComponent();
@ -28,7 +28,7 @@ namespace AirplaneWithRadar
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_airplane = new DrawingAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
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 AirplaneWithRadar
{
internal interface IDrawningObject
{
/// <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 DrawningObject(Graphics g);
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
}
}