2023-12-02 19:04:07 +04:00

167 lines
6.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using RPP.Entities;
using RPP.MovementStrategy;
namespace RPP.DrawningObjects
{
public class DrawningAirbus
{
public EntityAirbus? _EntityAirbus { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
private readonly int _AirbusWidth = 200;
private readonly int _AirbusHeight = 100;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _AirbusWidth;
public int GetHeight => _AirbusHeight;
public bool CanMove(Direction direction)
{
if (_EntityAirbus == null)
{
return false;
}
return direction switch
{
//влево
Direction.Left => _startPosX - _EntityAirbus.Step > 5,
//вверх
Direction.Up => _startPosY - _EntityAirbus.Step > 0,
// вправо
Direction.Right => _startPosX + _EntityAirbus.Step + _AirbusWidth < _pictureWidth,
Direction.Down => _startPosY + _EntityAirbus.Step + _AirbusHeight < _pictureHeight
};
}
public DrawningAirbus(int speed, double weight, Color bodyColor, int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
_EntityAirbus = new EntityAirbus(speed, weight, bodyColor);
}
protected DrawningAirbus(int speed, double weight, Color bodyColor, int
width, int height, int airbusWidth, int airbusHeight)
{
_pictureWidth = width;
_pictureHeight = height;
_AirbusWidth = airbusWidth;
_AirbusHeight = airbusHeight;
_EntityAirbus = new EntityAirbus(speed, weight, bodyColor);
}
public void SetBodyColor(Color bodyColor)
{
_EntityAirbus.ChangeColor(bodyColor);
}
public void SetPosition(int x, int y)
{
_startPosX = x;
_startPosY = y;
}
public IMoveableObject GetMoveableObject => new DrawningObjectAirbus(this);
public void MoveTransport(Direction direction)
{
if (!CanMove(direction) || _EntityAirbus == null)
{
return;
}
switch (direction)
{
//влево
case Direction.Left:
if (_startPosX - _EntityAirbus.Step > 5)
{
_startPosX -= (int)_EntityAirbus.Step;
}
break;
//вверх
case Direction.Up:
if (_startPosY - _EntityAirbus.Step > 0)
{
_startPosY -= (int)_EntityAirbus.Step;
}
break;
//вправо
case Direction.Right:
if (_startPosX + _EntityAirbus.Step + _AirbusWidth < _pictureWidth)
{
_startPosX += (int)_EntityAirbus.Step;
}
break;
//вниз
case Direction.Down:
if (_startPosY + _EntityAirbus.Step + _AirbusHeight < _pictureHeight)
{
_startPosY += (int)_EntityAirbus.Step;
}
break;
}
}
public virtual void DrawTransport(Graphics g)
{
if (_EntityAirbus == null)
{
return;
}
Pen pen = new(_EntityAirbus.BodyColor, 3);
//Тело
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 50, 170, 30);
g.DrawPie(pen, _startPosX - 5, _startPosY + 50, 20, 30, 90, 180);
Pen whitePen = new(Color.White, 3);
g.DrawLine(whitePen, _startPosX + 5, _startPosY + 52, _startPosX + 5, _startPosY + 79);
//Заднее крыло
g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 50, _startPosY + 50);
g.DrawLine(pen, _startPosX, _startPosY, _startPosX, _startPosY + 52);
//Заднее боковые крылья
Pen bigPen = new Pen(_EntityAirbus.BodyColor, 8);
g.DrawPie(pen, _startPosX - 7, _startPosY + 45, 5, 10, 90, 180);
g.DrawLine(bigPen, _startPosX - 6, _startPosY + 48, _startPosX + 30, _startPosY + 48);
g.DrawLine(bigPen, _startPosX - 6, _startPosY + 52, _startPosX + 30, _startPosY + 52);
g.DrawPie(pen, _startPosX + 25, _startPosY + 45, 5, 9, 180, 270);
//Нос
g.DrawLine(pen, _startPosX + 175, _startPosY + 50, _startPosX + 200, _startPosY + 65);
g.DrawLine(pen, _startPosX + 200, _startPosY + 65, _startPosX + 175, _startPosY + 80);
g.DrawLine(pen, _startPosX + 175, _startPosY + 50, _startPosX + 175, _startPosY + 80);
g.DrawLine(pen, _startPosX + 175, _startPosY + 65, _startPosX + 200, _startPosY + 65);
//Крылья
g.DrawPie(pen, _startPosX + 55, _startPosY + 62, 5, 5, 90, 180);
g.DrawLine(bigPen, _startPosX + 56, _startPosY + 65, _startPosX + 140, _startPosY + 65);
g.DrawPie(pen, _startPosX + 139, _startPosY + 62, 5, 5, 180, 270);
//Задние шасси
g.DrawLine(pen, _startPosX + 55, _startPosY + 80, _startPosX + 55, _startPosY + 90);
g.DrawEllipse(pen, _startPosX + 47, _startPosY + 90, 5, 5);
g.DrawEllipse(pen, _startPosX + 57, _startPosY + 90, 5, 5);
//Передние шасси
g.DrawLine(pen, _startPosX + 165, _startPosY + 80, _startPosX + 165, _startPosY + 90);
g.DrawEllipse(pen, _startPosX + 163, _startPosY + 91, 5, 5);
}
}
}