using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAirFighter
{
public class DrawningAirFighter
{
///
/// Класс-сущность
///
public EntityAirFighter? EntityAirFighter { get; private set; }
///
///
private int _pictureWidth;
///
///
private int _pictureHeight;
///
///
private int _startPosX;
///
///
private int _startPosY;
///
///
private readonly int _airfighterWidth = 163;
///
///
private readonly int _airfighterHeight = 70;
private readonly int _airfighterwingkorpusHeight = 90;
///
/// Инициализация свойств
///
/// Скорость
/// Вес
///
/// Дополнительный цвет
/// Ширина картинки
/// Высота картинки
/// true - объект создан, false - проверка не пройдена,
public bool Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool racket, bool wing, int width, int height)
{
// TODO: Продумать проверки
if (width <= _airfighterWidth || height <= _airfighterHeight)
return false;
_pictureWidth = width;
_pictureHeight = height;
EntityAirFighter = new EntityAirFighter();
EntityAirFighter.Init(speed, weight, bodyColor, additionalColor,
racket, wing);
return true;
}
///
/// Установка позиции
///
/// Координата X
/// Координата Y
public void SetPosition(int x, int y)
{
// TODO: Изменение x, y
_startPosX = x;
_startPosY = y;
if (x + _airfighterWidth >= _pictureWidth || y + _airfighterHeight >= _pictureHeight)
{
_startPosX = 1;
_startPosY = (_airfighterHeight+_airfighterwingkorpusHeight)/2;
}
}
///
/// Изменение направления перемещения
///
/// Направление
public void MoveTransport(DirectionType direction)
{
if (EntityAirFighter == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX - EntityAirFighter.Step > 0)
{
_startPosX -= (int)EntityAirFighter.Step;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - _airfighterHeight - EntityAirFighter.Step > 0)
{
_startPosY -= (int)EntityAirFighter.Step;
}
break;
// вправо
case DirectionType.Right:
if (_startPosX + EntityAirFighter.Step + _airfighterWidth < _pictureWidth)
{
_startPosX += (int)EntityAirFighter.Step;
}
else
_startPosX = _pictureWidth - _airfighterWidth;
break;
//вниз
case DirectionType.Down:
if (_startPosY + EntityAirFighter.Step + _airfighterwingkorpusHeight < _pictureHeight)
{
_startPosY += (int)EntityAirFighter.Step;
}
else
_startPosY = _pictureHeight - _airfighterwingkorpusHeight;
break;
}
}
///
/// Прорисовка объекта
///
///
public void DrawTransport(Graphics g)
{
if (EntityAirFighter == null)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new
SolidBrush(EntityAirFighter.AdditionalColor);
// ракеты
if (EntityAirFighter.Racket)
{
Brush brGrey = new SolidBrush(Color.LightGray);
g.FillRectangle(brGrey, _startPosX + 70, _startPosY - 15, 10, 10);
g.DrawRectangle(pen, _startPosX + 70, _startPosY - 15, 10, 10);
Point[] noseracketPoints =
{
new Point(_startPosX + 70, _startPosY -5),
new Point(_startPosX + 70, _startPosY - 15),
new Point(_startPosX + 60,_startPosY -10)
};
Brush brRed = new SolidBrush(Color.Red);
g.FillPolygon(brRed, noseracketPoints);
g.DrawPolygon(pen, noseracketPoints);
g.FillRectangle(brGrey, _startPosX + 70, _startPosY - 40, 10, 10);
g.DrawRectangle(pen, _startPosX + 70, _startPosY - 40, 10, 10);
Point[] noseracketPoints2 =
{
new Point(_startPosX + 70, _startPosY -30),
new Point(_startPosX + 70, _startPosY - 40),
new Point(_startPosX + 60,_startPosY -35)
};
g.FillPolygon(brRed, noseracketPoints2);
g.DrawPolygon(pen, noseracketPoints2);
g.FillPolygon(brRed, noseracketPoints);
g.DrawPolygon(pen, noseracketPoints);
g.FillRectangle(brGrey, _startPosX + 70, _startPosY + 59, 10, 10);
g.DrawRectangle(pen, _startPosX + 70, _startPosY + 59, 10, 10);
Point[] noseracketPoints3 =
{
new Point(_startPosX + 70, _startPosY +59),
new Point(_startPosX + 70, _startPosY + 69),
new Point(_startPosX + 60,_startPosY + 64)
};
g.FillPolygon(brRed, noseracketPoints3);
g.DrawPolygon(pen, noseracketPoints3);
g.FillRectangle(brGrey, _startPosX + 70, _startPosY + 34, 10, 10);
g.DrawRectangle(pen, _startPosX + 70, _startPosY + 34, 10, 10);
Point[] noseracketPoints4 =
{
new Point(_startPosX + 70, _startPosY +34),
new Point(_startPosX + 70, _startPosY + 44),
new Point(_startPosX + 60,_startPosY + 39)
};
g.FillPolygon(brRed, noseracketPoints4);
g.DrawPolygon(pen, noseracketPoints4);
}
Point[] nosePoints =
{
new Point(_startPosX + 20, _startPosY + 4),
new Point(_startPosX + 20, _startPosY + 24),
new Point(_startPosX-3,_startPosY + 12)
};
Brush brBlack = new SolidBrush(Color.Black);
g.FillPolygon(brBlack, nosePoints);
g.DrawPolygon(pen, nosePoints);
Point[] rightwingPoints =
{
new Point(_startPosX + 80, _startPosY + 4),
new Point(_startPosX+80,_startPosY - 66),
new Point(_startPosX+85,_startPosY - 66),
new Point(_startPosX + 100, _startPosY + 4)
};
g.FillPolygon(additionalBrush, rightwingPoints);
g.DrawPolygon(pen, rightwingPoints);
Point[] lefttwingPoints =
{
new Point(_startPosX + 80, _startPosY + 24),
new Point(_startPosX + 100, _startPosY + 24),
new Point(_startPosX+85,_startPosY + 94),
new Point(_startPosX+80,_startPosY + 94)
};
g.FillPolygon(additionalBrush, lefttwingPoints);
g.DrawPolygon(pen, lefttwingPoints);
Point[] leftenginePoints =
{
new Point(_startPosX + 140, _startPosY + 24),
new Point(_startPosX + 160, _startPosY + 24),
new Point(_startPosX+160,_startPosY + 50),
new Point(_startPosX+140,_startPosY + 32)
};
g.FillPolygon(additionalBrush, leftenginePoints);
g.DrawPolygon(pen, leftenginePoints);
Point[] rightenginePoints =
{
new Point(_startPosX + 140, _startPosY + 24),
new Point(_startPosX + 160, _startPosY + 24),
new Point(_startPosX+160,_startPosY - 16),
new Point(_startPosX+140,_startPosY -4)
};
g.FillPolygon(additionalBrush, rightenginePoints);
g.DrawPolygon(pen, rightenginePoints);
g.FillRectangle(additionalBrush, _startPosX + 20, _startPosY + 4, 140, 20);
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 140, 20);
// крыло
if (EntityAirFighter.Wing)
{
Point[] doprightwingPoints =
{
new Point(_startPosX + 30, _startPosY + 4),
new Point(_startPosX+30,_startPosY - 34),
new Point(_startPosX+35,_startPosY - 34),
new Point(_startPosX + 45, _startPosY + 4)
};
g.FillPolygon(additionalBrush, doprightwingPoints);
g.DrawPolygon(pen, doprightwingPoints);
Point[] doplefttwingPoints =
{
new Point(_startPosX + 30, _startPosY + 24),
new Point(_startPosX + 30, _startPosY + 59),
new Point(_startPosX+35,_startPosY + 59),
new Point(_startPosX+45,_startPosY + 24)
};
g.FillPolygon(additionalBrush, doplefttwingPoints);
g.DrawPolygon(pen, doplefttwingPoints);
}
}
}
}