Abazov A. A. LabWork02 #2

Merged
eegov merged 4 commits from LabWork02 into LabWork01 2022-10-28 09:44:59 +04:00
3 changed files with 100 additions and 0 deletions
Showing only changes of commit f423917695 - Show all commits

View File

@ -222,5 +222,14 @@ namespace AirBomber
_startPosY = _pictureHeight.Value - _airBomberHeight;
}
}
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _airBomberWidth, _startPosY + _airBomberHeight);
}
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
internal class DrawingObject : IDrawingObject
{
private DrawingAirBomber _airBomber = null;
public DrawingObject(DrawingAirBomber airBomber)
{
_airBomber = airBomber;
}
public float Step => _airBomber?.AirBomber?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _airBomber?.GetCurrentPosition() ?? default;
}
public void MoveObject(Direction direction)
{
_airBomber?.MoveTransport(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_airBomber.SetPosition(x, y, width, height);
}
void IDrawingObject.DrawingObject(Graphics g)
{
if (_airBomber == null) return;
if (_airBomber is DrawingHeavyAirBomber heavyAirBomber)
{
heavyAirBomber.DrawTransport(g);
}
else
{
_airBomber.DrawTransport(g);
}
}
}
}

View File

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
/// <summary>
/// Интерфейс для работы с объектом, прорисовываемым на форме
/// </summary>
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();
}
}