137 lines
6.2 KiB
C#
137 lines
6.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Airbus
|
|
{
|
|
public class DrawningAirplane
|
|
{
|
|
/// Класс-сущность
|
|
public EntityAirplane airplane { protected set; get; }
|
|
public IPorthole porthole { private set; get; }
|
|
|
|
/// Левая координата отрисовки автомобиля
|
|
protected float _startPosX;
|
|
/// Верхняя кооридната отрисовки автомобиля
|
|
protected float _startPosY;
|
|
/// Ширина окна отрисовки
|
|
private int? _pictureWidth = null;
|
|
/// Высота окна отрисовки
|
|
private int? _pictureHeight = null;
|
|
/// Ширина отрисовки автомобиля
|
|
protected readonly int _airplaneWidth = 150; //Ширина отрисовки корабля
|
|
protected readonly int _airplaneHeight = 30; //Высота отрисовки корабля
|
|
public DrawningAirplane(int speed, float weight, Color bodyColor, IPorthole formPorthole)
|
|
{
|
|
airplane = new EntityAirplane(speed, weight, bodyColor);
|
|
porthole = formPorthole;
|
|
}
|
|
public DrawningAirplane(EntityAirplane entityAirplane, IPorthole formPorthole)
|
|
{
|
|
airplane = entityAirplane;
|
|
porthole = formPorthole;
|
|
}
|
|
public void SetPosition(int x, int y, int width, int height)
|
|
{
|
|
if (width < _airplaneWidth || height < _airplaneHeight) return;
|
|
Random random = new Random();
|
|
_startPosX = x < 0 || x + _airplaneWidth > width ? random.Next(0, width - _airplaneWidth) : x;
|
|
_startPosY = y < 0 || y + _airplaneHeight > height ? random.Next(0, height - _airplaneHeight) : y;
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
}
|
|
|
|
public void MoveTransport(Direction direction)
|
|
{
|
|
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) return;
|
|
switch (direction)
|
|
{
|
|
case Direction.Left: //Влево
|
|
|
|
if (_startPosX - airplane.Step > 0) _startPosX -= airplane.Step;
|
|
break;
|
|
case Direction.Up: //Вверх
|
|
if (_startPosY - airplane.Step > 0) _startPosY -= airplane.Step;
|
|
break;
|
|
case Direction.Right: //Вправо
|
|
if (_startPosX + _airplaneWidth + airplane.Step - 6 < _pictureWidth) _startPosX += airplane.Step;
|
|
break;
|
|
case Direction.Down: //Вниз
|
|
if (_startPosY + _airplaneHeight + airplane.Step + 25 < _pictureHeight) _startPosY += airplane.Step;
|
|
break;
|
|
}
|
|
}
|
|
protected DrawningAirplane(int speed, float weight, Color bodyColor, int
|
|
carWidth, int carHeight, IPorthole formPorthole) :
|
|
this(speed, weight, bodyColor, formPorthole)
|
|
{
|
|
_airplaneWidth = carWidth;
|
|
_airplaneHeight = carHeight;
|
|
}
|
|
public virtual void DrawTransport(Graphics g)
|
|
{
|
|
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
Pen pen = new(Color.Black);
|
|
|
|
SolidBrush brush = new SolidBrush(airplane?.BodyColor ?? Color.White);
|
|
g.FillPolygon(brush, new[]
|
|
{
|
|
new Point((int)(_startPosX + _airplaneWidth - 25), (int)(_startPosY + 25)),
|
|
new Point((int)(_startPosX + _airplaneWidth), (int)(_startPosY + 40)),
|
|
new Point((int)(_startPosX + _airplaneWidth - 25), (int)(_startPosY + 55)),
|
|
new Point((int)(_startPosX + _airplaneWidth - 25), (int)(_startPosY + 15)),
|
|
});
|
|
g.FillRectangle(brush, _startPosX, _startPosY + 25, _airplaneWidth - 25, _airplaneHeight);
|
|
g.DrawPolygon(pen, new[]
|
|
{
|
|
new Point((int)(_startPosX), (int)(_startPosY)),
|
|
new Point((int)(_startPosX + 25), (int)(_startPosY + 25)),
|
|
new Point((int)(_startPosX), (int)(_startPosY + 25)),
|
|
new Point((int)(_startPosX), (int)(_startPosY)),
|
|
});
|
|
g.DrawEllipse(new(Color.Blue, 2), _startPosX, _startPosY + 15, 25, 5);
|
|
|
|
g.DrawEllipse(new(Color.Black, 2), _startPosX + _airplaneWidth - 30, _startPosY + _airplaneHeight + 25, 4, 4);
|
|
g.DrawEllipse(new(Color.Black, 2), _startPosX + _airplaneWidth - 35, _startPosY + _airplaneHeight + 25, 4, 4);
|
|
g.DrawEllipse(new(Color.Black, 2), _startPosX , _startPosY + _airplaneHeight + 25, 4, 4);
|
|
|
|
porthole.DrawPortholes(g, Color.Red, _startPosX, _startPosY);
|
|
}
|
|
public void Upd_count_Porthole(CountPorthole count)
|
|
{
|
|
porthole.CountPorthole = (int)count;
|
|
}
|
|
public void ChangeBorders(int width, int height)
|
|
{
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
if (_pictureWidth <= _airplaneWidth || _pictureHeight <= _airplaneHeight)
|
|
{
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
return;
|
|
}
|
|
if (_startPosX + _airplaneWidth > _pictureWidth)
|
|
{
|
|
_startPosX = _pictureWidth.Value - _airplaneWidth;
|
|
}
|
|
if (_startPosY + _airplaneHeight > _pictureHeight)
|
|
{
|
|
_startPosY = _pictureHeight.Value - _airplaneHeight;
|
|
}
|
|
}
|
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
|
{
|
|
return (_startPosX, _startPosX + _airplaneWidth, _startPosY, _startPosY + _airplaneHeight);
|
|
}
|
|
}
|
|
|
|
}
|