PIbd-22_Isaeva_A.I._Airbus_.../Airbus/Drawnings/DrawningAirbus.cs
2023-11-18 10:00:43 +04:00

157 lines
5.5 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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectAirbus.Entities;
namespace ProjectAirbus.Drawnings
{
internal class DrawningAirbus
{
public EntityAirbus? EntityAirbus { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _airbusWidth = 89;
protected readonly int _airbusHeight = 34;
// доработки для интерфейса
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _airbusWidth;
public int GetHeight => _airbusHeight;
public DrawningAirbus(int speed, double weight, Color bodyColor, int
width, int height)
{
if (width < _airbusWidth || height < _airbusHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityAirbus = new EntityAirbus(speed, weight, bodyColor);
}
protected DrawningAirbus(int speed, double weight, Color bodyColor, int width, int height, int carWidth, int carHeight)
{
if (width < _airbusWidth || height < _airbusHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_airbusWidth = carWidth;
_airbusHeight = carHeight;
EntityAirbus = new EntityAirbus(speed, weight, bodyColor);
}
// доработка для интерфейса
// проверка, что может переместиться
public bool CanMove(DirectionType direction)
{
if (EntityAirbus == null)
{
return false;
}
return direction switch
{
DirectionType.Left => _startPosX - EntityAirbus.Step > 0,
DirectionType.Up => _startPosY - EntityAirbus.Step > 0,
DirectionType.Right => _startPosX + _airbusWidth + EntityAirbus.Step < _pictureWidth,
DirectionType.Down => _startPosY + _airbusHeight + EntityAirbus.Step < _pictureHeight,
};
}
public void SetPosition(int x, int y)
{
if (x >= _pictureWidth || y >= _pictureHeight)
{
x = _pictureWidth - _airbusWidth;
y = _pictureHeight - _airbusHeight;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityAirbus == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
_startPosX -= (int)EntityAirbus.Step;
break;
case DirectionType.Right:
_startPosX += (int)EntityAirbus.Step;
break;
case DirectionType.Up:
_startPosY -= (int)EntityAirbus.Step;
break;
case DirectionType.Down:
_startPosY += (int)EntityAirbus.Step;
break;
}
}
// прорисовка
public virtual void DrawTransport(Graphics g)
{
if (EntityAirbus == null)
{
return;
}
Pen pen = new(Color.Black);
Brush bodyBrush = new SolidBrush(EntityAirbus.BodyColor);
Brush brYellow = new SolidBrush(Color.Yellow);
// нос
Point point1 = new Point(_startPosX + 74, _startPosY + 15);
Point point2 = new Point(_startPosX + 88, _startPosY + 22);
Point point3 = new Point(_startPosX + 74, _startPosY + 27);
Point[] PointsNose = { point1, point2, point3 };
g.DrawPolygon(pen, PointsNose);
g.FillPolygon(brYellow, PointsNose);
// хвост
Point point4 = new Point(_startPosX + 4, _startPosY + 17);
Point point5 = new Point(_startPosX + 3, _startPosY);
Point point6 = new Point(_startPosX + 21, _startPosY + 17);
Point[] PointsTail = { point4, point5, point6 };
g.DrawPolygon(pen, PointsTail);
g.FillPolygon(brYellow, PointsTail);
// тело
g.DrawRectangle(pen, _startPosX + 2, _startPosY + 14, 72, 14);
g.FillRectangle(bodyBrush, _startPosX + 2, _startPosY + 14, 72, 14);
//шасси
g.DrawEllipse(pen, _startPosX + 21, _startPosY + 30, 3, 3);
g.FillEllipse(brYellow, _startPosX + 21, _startPosY + 30, 3, 3);
g.DrawEllipse(pen, _startPosX + 25, _startPosY + 30, 3, 3);
g.FillEllipse(brYellow, _startPosX + 25, _startPosY + 30, 3, 3);
g.DrawEllipse(pen, _startPosX + 70, _startPosY + 30, 3, 3);
g.FillEllipse(brYellow, _startPosX + 70, _startPosY + 30, 3, 3);
// Крыло
g.DrawEllipse(pen, _startPosX + 24, _startPosY + 20, 31, 4);
g.FillEllipse(brYellow, _startPosX + 24, _startPosY + 20, 31, 4);
// двигатель у хвоста
g.DrawEllipse(pen, _startPosX, _startPosY + 14, 14, 5);
g.FillEllipse(brYellow, _startPosX, _startPosY + 14, 14, 5);
}
}
}