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

This commit is contained in:
Катя Ихонкина 2022-10-02 19:42:09 +04:00
parent 31532e6d54
commit f97ced21c7
3 changed files with 85 additions and 1 deletions

View File

@ -40,7 +40,7 @@ namespace MotorBoat
if (_startPosY - _boatHeight < 0) { _startPosY = _boatHeight + 10; }
if (_startPosY + _boatHeight > _pictureHeight) { _startPosY -= _boatHeight; }
}
public void MoveBoats(Direction direction)
public void MoveTransport(Direction direction)
{
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
{
@ -124,5 +124,9 @@ namespace MotorBoat
_startPosY = _pictureHeight.Value - _boatHeight;
}
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _boatWidth, _startPosY + _boatHeight);
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MotorBoat
{
internal class DrawningObjectBoat : IDrawningObject
{
private DrawningBoat _boat = null;
public DrawningObjectBoat(DrawningBoat boat)
{
_boat = boat;
}
public float Step => _boat?.Boat?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _boat?.GetCurrentPosition() ?? default;
}
public void MoveObject(Direction direction)
{
_boat?.MoveTransport(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_boat.SetPosition(x, y, width, height);
}
void IDrawningObject.DrawningObject(Graphics g)
{
// TODO
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MotorBoat
{
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();
}
}