ISEbd-22 Alimova M.S. Lab Work 02 Hard #2
192
AirBomber/AirBomber/DrawningAirPlane.cs
Normal file
192
AirBomber/AirBomber/DrawningAirPlane.cs
Normal file
@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
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 = 150;
|
||||
protected readonly int _airPlaneHeight = 118;
|
||||
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 || x + _airPlaneWidth > _pictureWidth)
|
||||
{
|
||||
x = _pictureWidth - _airPlaneWidth;
|
||||
}
|
||||
if (y < 0 || y + _airPlaneHeight > _pictureHeight)
|
||||
{
|
||||
y = _pictureHeight - _airPlaneHeight;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
public virtual void DrawPlane(Graphics g)
|
||||
{
|
||||
if (EntityAirPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyColor = new SolidBrush(EntityAirPlane.BodyColor);
|
||||
Brush wingsColor = new SolidBrush(Color.DeepPink);
|
||||
g.FillPolygon(bodyColor, new Point[] //nose
|
||||
{
|
||||
new Point(_startPosX + 19, _startPosY + 50),
|
||||
new Point(_startPosX + 19, _startPosY + 69),
|
||||
new Point(_startPosX + 1, _startPosY + 59),
|
||||
}
|
||||
);
|
||||
g.FillRectangle(bodyColor, _startPosX + 20, _startPosY + 50, 120, 20); //body
|
||||
g.FillPolygon(bodyColor, new Point[] //up left wing
|
||||
{
|
||||
new Point(_startPosX + 36, _startPosY + 49),
|
||||
new Point(_startPosX + 36, _startPosY + 1),
|
||||
new Point(_startPosX + 45, _startPosY + 1),
|
||||
new Point(_startPosX + 55, _startPosY + 49),
|
||||
}
|
||||
);
|
||||
g.FillPolygon(bodyColor, new Point[] //down left wing
|
||||
{
|
||||
new Point(_startPosX + 36, _startPosY + 71),
|
||||
new Point(_startPosX + 36, _startPosY + 116),
|
||||
new Point(_startPosX + 45, _startPosY + 116),
|
||||
new Point(_startPosX + 54, _startPosY + 71),
|
||||
}
|
||||
);
|
||||
g.FillPolygon(wingsColor, new Point[] //up right wing
|
||||
{
|
||||
new Point(_startPosX + 120, _startPosY + 49),
|
||||
new Point(_startPosX + 120, _startPosY + 42),
|
||||
new Point(_startPosX + 140, _startPosY + 7),
|
||||
new Point(_startPosX + 140, _startPosY + 49),
|
||||
}
|
||||
);
|
||||
g.FillPolygon(wingsColor, new Point[] //down right wing
|
||||
{
|
||||
new Point(_startPosX + 120, _startPosY + 70),
|
||||
new Point(_startPosX + 120, _startPosY + 77),
|
||||
new Point(_startPosX + 140, _startPosY + 112),
|
||||
new Point(_startPosX + 140, _startPosY + 70),
|
||||
}
|
||||
);
|
||||
|
||||
g.DrawPolygon(pen, new Point[] //nose
|
||||
{
|
||||
new Point(_startPosX + 20, _startPosY + 49),
|
||||
new Point(_startPosX + 20, _startPosY + 70),
|
||||
new Point(_startPosX, _startPosY + 59),
|
||||
}
|
||||
);
|
||||
g.DrawRectangle(pen, _startPosX + 19, _startPosY + 49, 121, 21); //body
|
||||
g.DrawPolygon(pen, new Point[] //up left wing
|
||||
{
|
||||
new Point(_startPosX + 35, _startPosY + 49),
|
||||
new Point(_startPosX + 35, _startPosY),
|
||||
new Point(_startPosX + 45, _startPosY),
|
||||
new Point(_startPosX + 55, _startPosY + 49),
|
||||
}
|
||||
);
|
||||
g.DrawPolygon(pen, new Point[] //down left wing
|
||||
{
|
||||
new Point(_startPosX + 36, _startPosY + 71),
|
||||
new Point(_startPosX + 36, _startPosY + 116),
|
||||
new Point(_startPosX + 45, _startPosY + 116),
|
||||
new Point(_startPosX + 54, _startPosY + 71),
|
||||
}
|
||||
);
|
||||
g.DrawPolygon(pen, new Point[] //up right wing
|
||||
{
|
||||
new Point(_startPosX + 120, _startPosY + 49),
|
||||
new Point(_startPosX + 120, _startPosY + 42),
|
||||
new Point(_startPosX + 140, _startPosY + 7),
|
||||
new Point(_startPosX + 140, _startPosY + 49),
|
||||
}
|
||||
);
|
||||
g.DrawPolygon(pen, new Point[] //down right wing
|
||||
{
|
||||
new Point(_startPosX + 120, _startPosY + 70),
|
||||
new Point(_startPosX + 120, _startPosY + 77),
|
||||
new Point(_startPosX + 140, _startPosY + 112),
|
||||
new Point(_startPosX + 140, _startPosY + 70),
|
||||
}
|
||||
);
|
||||
}
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _airPlaneWidth;
|
||||
public int GetHeight => _airPlaneHeight;
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityAirPlane == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityAirPlane.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityAirPlane.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + EntityAirPlane.Step + _airPlaneWidth < _pictureWidth,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + EntityAirPlane.Step + _airPlaneHeight < _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
public void MovePlane(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user