PIbd_23_Kislitsa_E.D_AirFig.../AirFighter/DrawningAirplane.cs

193 lines
6.6 KiB
C#
Raw Normal View History

2023-10-02 21:42:00 +04:00
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectAirFighter.Entities;
2023-10-15 17:11:27 +04:00
using ProjectAirFighter.MovementStrategy;
2023-10-02 21:42:00 +04:00
namespace ProjectAirFighter.DrawningObjects
{
public class DrawningAirplane
{
public EntityAirplane? EntityAirplane { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
2023-12-08 22:44:38 +04:00
char separator = '|';
2023-10-02 21:42:00 +04:00
protected int _startPosY;
protected readonly int _airplaneWidth = 163;
protected readonly int _airplaneHeight = 160;
protected readonly int _airplanewingHeight = 70;
protected readonly int _airplanerwingkorpusHeight = 90;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _airplaneWidth;
public int GetHeight => _airplaneHeight;
2023-10-15 17:11:27 +04:00
public IMoveableObject GetMoveableObject => new DrawningObjectAirplane(this);
2023-10-02 21:42:00 +04:00
public DrawningAirplane(int speed, double weight, Color bodyColor,int width, int height)
{
if (width <= _airplaneWidth || height <= _airplanewingHeight)
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 <= _airplanewingHeight)
return;
_pictureWidth = width;
_pictureHeight = height;
_airplaneWidth = airplaneWidth;
_airplanewingHeight = airplaneHeight;
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
}
2023-11-19 00:11:44 +04:00
public void ChangeColor(Color col)
{
if (EntityAirplane == null)
return;
EntityAirplane.BodyColor= col;
}
2023-10-02 21:42:00 +04:00
2023-11-19 00:11:44 +04:00
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
{
_pictureHeight = pictureBoxHeight;
_pictureWidth = pictureBoxWidth;
}
2023-10-02 21:42:00 +04:00
public void SetPosition(int x, int y)
{
if (EntityAirplane == null)
return;
_startPosX = x;
_startPosY = y;
2023-10-06 17:41:21 +04:00
if (x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight)
2023-10-02 21:42:00 +04:00
{
_startPosX = 1;
_startPosY = (_airplanewingHeight+_airplanerwingkorpusHeight)/2;
}
}
public bool CanMove(DirectionType direction)
{
if (EntityAirplane == null)
{
return false;
}
return direction switch
{
DirectionType.Left => _startPosX - EntityAirplane.Step > 0,
DirectionType.Up => _startPosY - EntityAirplane.Step - (_airplaneHeight - _airplaneHeight * 125 / 1000) / 2 > 0,
DirectionType.Right => _startPosX+ EntityAirplane.Step + _airplaneWidth < _pictureWidth,
DirectionType.Down => _startPosY + EntityAirplane.Step + _airplanerwingkorpusHeight < _pictureHeight,
};
}
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityAirplane == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
_startPosX -= (int)EntityAirplane.Step;
break;
case DirectionType.Up:
_startPosY -= (int)EntityAirplane.Step;
break;
case DirectionType.Right:
_startPosX += (int)EntityAirplane.Step;
break;
case DirectionType.Down:
_startPosY += (int)EntityAirplane.Step;
break;
}
}
public virtual void DrawTransport(Graphics g)
{
if (EntityAirplane == null)
{
return;
}
Pen pen = new(Color.Black);
Brush br = new SolidBrush(EntityAirplane.BodyColor);
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 - 64),
new Point(_startPosX+85,_startPosY - 64),
new Point(_startPosX + 100, _startPosY + 4)
};
g.DrawPolygon(pen, rightwingPoints);
g.FillPolygon(br, 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.DrawPolygon(pen, lefttwingPoints);
g.FillPolygon(br, 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.DrawPolygon(pen, leftenginePoints);
g.FillPolygon(br, 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.DrawPolygon(pen, rightenginePoints);
g.FillPolygon(br, rightenginePoints);
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 140, _airplaneHeight * 125 / 1000);
g.FillRectangle(br, _startPosX + 20, _startPosY + 4, 140, _airplaneHeight * 125 / 1000);
}
}
}