163 lines
6.2 KiB
C#
163 lines
6.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ProjectAirplaneWithRadar.Entities;
|
|
|
|
namespace ProjectAirplaneWithRadar.DrawningObjects
|
|
{
|
|
public class DrawningAirplane
|
|
{
|
|
public EntityAirplane? EntityAirplane { get; protected set; }
|
|
private int _pictureWidth;
|
|
private int _pictureHeight;
|
|
protected int _startPosX;
|
|
protected int _startPosY;
|
|
protected readonly int _airplaneWidth = 200;
|
|
protected readonly int _airplaneHeight = 78;
|
|
public int GetPosX => _startPosX;
|
|
public int GetPosY => _startPosY;
|
|
public int GetWidth => _airplaneWidth;
|
|
public int GetHeight => _airplaneHeight;
|
|
public DrawningAirplane(int speed, double weight, Color bodyColor, int
|
|
width, int height)
|
|
{
|
|
if (width < _airplaneWidth || height < _airplaneHeight)
|
|
return;
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
|
}
|
|
protected DrawningAirplane(int speed, double weight, Color bodyColor, int
|
|
width, int height, int airplaneWidth, int airplaneHeight)
|
|
{
|
|
if (width < _airplaneWidth || height < _airplaneHeight)
|
|
return;
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
_airplaneWidth = airplaneWidth;
|
|
_airplaneHeight = airplaneHeight;
|
|
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
|
}
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
if (x < 0 || y < 0 || x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight)
|
|
{
|
|
x = y = 10;
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
}
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
}
|
|
public bool CanMove(Direction direction)
|
|
{
|
|
if (EntityAirplane == null)
|
|
{
|
|
return false;
|
|
}
|
|
switch (direction)
|
|
{
|
|
case Direction.Left:
|
|
return _startPosX - EntityAirplane.Step > 0;
|
|
break;
|
|
case Direction.Up:
|
|
return _startPosY - EntityAirplane.Step > 0;
|
|
break;
|
|
case Direction.Right:
|
|
return _startPosX + EntityAirplane.Step + _airplaneWidth < _pictureWidth;
|
|
break;
|
|
case Direction.Down:
|
|
return _startPosY + EntityAirplane.Step + _airplaneHeight < _pictureHeight;
|
|
break;
|
|
default:return false;
|
|
};
|
|
}
|
|
public void MoveTransport(Direction direction)
|
|
{
|
|
if (!CanMove(direction)||EntityAirplane == null)
|
|
{
|
|
return;
|
|
}
|
|
switch (direction)
|
|
{
|
|
case Direction.Left:
|
|
if (_startPosX - EntityAirplane.Step > 0)
|
|
{
|
|
_startPosX -= (int)EntityAirplane.Step;
|
|
}
|
|
break;
|
|
case Direction.Up:
|
|
if (_startPosY - EntityAirplane.Step > 0)
|
|
{
|
|
_startPosY -= (int)EntityAirplane.Step;
|
|
}
|
|
break;
|
|
case Direction.Right:
|
|
if (_startPosX + EntityAirplane.Step + _airplaneWidth < _pictureWidth)
|
|
{
|
|
_startPosX += (int)EntityAirplane.Step;
|
|
}
|
|
break;
|
|
case Direction.Down:
|
|
if (_startPosY + EntityAirplane.Step + _airplaneHeight < _pictureHeight)
|
|
{
|
|
_startPosY += (int)EntityAirplane.Step;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
public virtual void DrawTransport(Graphics g)
|
|
{
|
|
if (EntityAirplane == null)
|
|
{
|
|
return;
|
|
}
|
|
Pen pen = new Pen(Color.Black, 3);
|
|
|
|
// корпус
|
|
Brush br = new SolidBrush(EntityAirplane.BodyColor);
|
|
g.DrawEllipse(pen, _startPosX, _startPosY + 25, 180, 30);
|
|
g.FillEllipse(br, _startPosX, _startPosY + 25, 180, 30);
|
|
// крыло
|
|
Brush blackBrush = new SolidBrush(Color.Black);
|
|
g.FillEllipse(blackBrush, _startPosX + 70, _startPosY + 35, 80, 10);
|
|
// стекла
|
|
Pen blackPen = new Pen(Color.Black, 2);
|
|
Brush blueBrush = new SolidBrush(Color.LightBlue);
|
|
Point point1 = new Point(_startPosX + 170, _startPosY + 30);
|
|
Point point2 = new Point(_startPosX + 200, _startPosY + 40);
|
|
Point point3 = new Point(_startPosX + 170, _startPosY + 50);
|
|
Point[] curvePoints =
|
|
{
|
|
point1,
|
|
point2,
|
|
point3,
|
|
};
|
|
g.FillPolygon(blueBrush, curvePoints);
|
|
g.DrawPolygon(blackPen, curvePoints);
|
|
g.DrawLine(blackPen, _startPosX + 170, _startPosY + 40, _startPosX + 200, _startPosY + 40);
|
|
// хвост
|
|
Point point4 = new Point(_startPosX, _startPosY + 35);
|
|
Point point5 = new Point(_startPosX, _startPosY + 5);
|
|
Point point6 = new Point(_startPosX + 30, _startPosY + 35);
|
|
Point[] curvePoints2 =
|
|
{
|
|
point4,
|
|
point5,
|
|
point6,
|
|
};
|
|
g.FillPolygon(br, curvePoints2);
|
|
g.DrawPolygon(blackPen, curvePoints2);
|
|
// шасси
|
|
g.DrawLine(blackPen, _startPosX + 50, _startPosY + 55, _startPosX + 50, _startPosY + 70);
|
|
g.DrawLine(blackPen, _startPosX + 150, _startPosY + 51, _startPosX + 150, _startPosY + 70);
|
|
g.FillEllipse(blackBrush, _startPosX + 40, _startPosY + 65, 10, 10);
|
|
g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 65, 10, 10);
|
|
g.FillEllipse(blackBrush, _startPosX + 145, _startPosY + 65, 10, 10);
|
|
}
|
|
}
|
|
}
|