157 lines
5.3 KiB
C#
157 lines
5.3 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Net.Http.Headers;
|
|||
|
using System.Security.Cryptography.X509Certificates;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace AirBus
|
|||
|
{
|
|||
|
public class DrawningAirBus
|
|||
|
{
|
|||
|
public EntityAirBus? EntityAirBus { get; private set; }
|
|||
|
|
|||
|
// ширина и высота картинки
|
|||
|
private int pictureWidht;
|
|||
|
private int pictureHeight;
|
|||
|
|
|||
|
// стартовые точки
|
|||
|
private int startPosX;
|
|||
|
private int startPosY;
|
|||
|
|
|||
|
private readonly int airbusWidth = 100;
|
|||
|
private readonly int airbusHeight = 37;
|
|||
|
|
|||
|
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height)
|
|||
|
{
|
|||
|
pictureWidht = width;
|
|||
|
pictureHeight = height;
|
|||
|
|
|||
|
EntityAirBus = new EntityAirBus();
|
|||
|
EntityAirBus.Init(speed, weight, bodyColor, additionalColor);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
//установка позиции
|
|||
|
public void SetPosition(int x, int y)
|
|||
|
{
|
|||
|
if (x >= 0 && x + airbusWidth <= pictureWidht && y >= 0 && y + airbusHeight <= pictureHeight)
|
|||
|
{
|
|||
|
startPosX = x;
|
|||
|
startPosY = y;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// изменение направления движения
|
|||
|
public void MoveTransport(Direction direction)
|
|||
|
{
|
|||
|
if (EntityAirBus == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
switch (direction)
|
|||
|
{
|
|||
|
case Direction.Left:
|
|||
|
if (startPosX - EntityAirBus.Step > 0)
|
|||
|
{
|
|||
|
startPosX -= (int)EntityAirBus.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
case Direction.Right:
|
|||
|
if (startPosX + EntityAirBus.Step <= pictureWidht)
|
|||
|
{
|
|||
|
startPosX += (int)EntityAirBus.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
case Direction.Up:
|
|||
|
if (startPosY - EntityAirBus.Step > 0)
|
|||
|
{
|
|||
|
startPosY -= (int)EntityAirBus.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
case Direction.Down:
|
|||
|
if (startPosY + EntityAirBus.Step <= pictureHeight)
|
|||
|
{
|
|||
|
startPosY += (int)EntityAirBus.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// РИСОВАНИЕ САМОЛЁТА
|
|||
|
public void DrawTransport(Graphics g)
|
|||
|
{
|
|||
|
if ( startPosX < 0 || startPosY < 0 || EntityAirBus == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Pen pen = new(Color.Black);
|
|||
|
Brush additionalBrush = new SolidBrush(EntityAirBus.AdditionalColor);
|
|||
|
Brush additionalBrush2 = new SolidBrush(Color.Black);
|
|||
|
|
|||
|
// нос
|
|||
|
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(additionalBrush, 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(additionalBrush, PointsTail);
|
|||
|
|
|||
|
// тело
|
|||
|
g.DrawRectangle(pen, startPosX + 2, startPosY + 14, 72, 14);
|
|||
|
g.FillRectangle(additionalBrush, startPosX + 2, startPosY + 14, 72, 14);
|
|||
|
|
|||
|
//шасси
|
|||
|
g.DrawEllipse(pen, startPosX + 21, startPosY + 30, 3, 3);
|
|||
|
g.FillEllipse(additionalBrush, startPosX + 21, startPosY + 30, 3, 3);
|
|||
|
|
|||
|
g.DrawEllipse(pen, startPosX + 25, startPosY + 30, 3, 3);
|
|||
|
g.FillEllipse(additionalBrush, startPosX + 25, startPosY + 30, 3, 3);
|
|||
|
|
|||
|
g.DrawEllipse(pen, startPosX + 70, startPosY + 30, 3, 3);
|
|||
|
g.FillEllipse(additionalBrush, startPosX + 70, startPosY + 30, 3, 3);
|
|||
|
|
|||
|
// Крыло
|
|||
|
g.DrawEllipse(pen, startPosX + 24, startPosY + 20, 31, 4);
|
|||
|
g.FillEllipse(additionalBrush, startPosX + 24, startPosY + 20, 31, 4);
|
|||
|
|
|||
|
|
|||
|
// у хвоста
|
|||
|
g.DrawEllipse(pen, startPosX, startPosY + 14, 14, 5);
|
|||
|
g.FillEllipse(additionalBrush, startPosX, startPosY + 14, 14, 5);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public void ChangeBorders(int width, int height)
|
|||
|
{
|
|||
|
pictureWidht = width;
|
|||
|
pictureHeight = height;
|
|||
|
if (pictureWidht <= airbusWidth || pictureHeight <= airbusWidth)
|
|||
|
{
|
|||
|
pictureWidht = null;
|
|||
|
pictureHeight = null;
|
|||
|
return;
|
|||
|
}
|
|||
|
if ( startPosX + airbusWidth > pictureWidht)
|
|||
|
{
|
|||
|
startPosX = pictureWidht.Value - airbusWidth;
|
|||
|
}
|
|||
|
if ( startPosY + airbusHeight > pictureHeight)
|
|||
|
{
|
|||
|
startPosY = pictureHeight.Value - airbusHeight;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|