Lab1 perfecto
This commit is contained in:
parent
b62aed4c67
commit
e17240421c
@ -9,11 +9,8 @@ namespace ProjectAirBomber
|
||||
public enum DirectionType
|
||||
{
|
||||
Up = 1,
|
||||
|
||||
Down = 2,
|
||||
|
||||
Left = 3,
|
||||
|
||||
Right = 4
|
||||
}
|
||||
}
|
@ -7,44 +7,61 @@ using System.Drawing;
|
||||
|
||||
namespace ProjectAirBomber
|
||||
{
|
||||
|
||||
public class DrawingAirBomber
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirBomber? EntityAirBomber { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
|
||||
private int _startPosX;
|
||||
|
||||
private int _startPosY;
|
||||
|
||||
private readonly int _airBomberWidth = 160;
|
||||
|
||||
private readonly int _airBomberHeight = 160;
|
||||
|
||||
private readonly int _planeWidth = 160;
|
||||
private readonly int _planeHeight = 160;
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <param name="additionalColor"></param>
|
||||
/// <param name="bombs"></param>
|
||||
/// <param name="fuel"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bombs, bool wing, int width, int height)
|
||||
additionalColor, bool bombs, bool fuel, int width, int height)
|
||||
{
|
||||
if (_planeWidth > width || _planeHeight > height)
|
||||
return false;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_airBomberWidth > _pictureWidth || _airBomberHeight > _pictureHeight)
|
||||
return false;
|
||||
EntityAirBomber = new EntityAirBomber();
|
||||
EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, bombs, wing);
|
||||
EntityAirBomber.Init(speed, weight, bodyColor, additionalColor,
|
||||
bombs, fuel);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || y < 0 || x + _airBomberWidth >= _pictureWidth || y + _airBomberHeight >= _pictureHeight)
|
||||
if (x < 0 || y < 0 || x + _planeWidth >= _pictureWidth || y + _planeHeight >= _pictureHeight)
|
||||
x = y = 2;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAirBomber == null)
|
||||
@ -69,20 +86,23 @@ namespace ProjectAirBomber
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntityAirBomber.Step + _airBomberWidth < _pictureWidth)
|
||||
if (_startPosX + _planeWidth + (int)EntityAirBomber.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityAirBomber.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntityAirBomber.Step + _airBomberHeight < _pictureHeight)
|
||||
if (_startPosY + _planeHeight + (int)EntityAirBomber.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAirBomber.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAirBomber == null)
|
||||
@ -91,11 +111,11 @@ namespace ProjectAirBomber
|
||||
}
|
||||
Pen pen = new Pen(Color.Black, 2);
|
||||
Brush additionalBrush = new SolidBrush(EntityAirBomber.AdditionalColor);
|
||||
//фюзеляж
|
||||
Brush br = new SolidBrush(EntityAirBomber.BodyColor);
|
||||
//фюзеляж
|
||||
g.FillRectangle(br, _startPosX + 20, _startPosY + 70, 140, 20);
|
||||
//кабина
|
||||
Point[] point = new Point[3]{
|
||||
Point[] point = new Point[3]{
|
||||
new Point(_startPosX + 0, _startPosY + 80),
|
||||
new Point(_startPosX + 20, _startPosY + 70),
|
||||
new Point(_startPosX + 20, _startPosY + 90)
|
||||
@ -138,7 +158,7 @@ namespace ProjectAirBomber
|
||||
};
|
||||
g.FillPolygon(br, point);
|
||||
g.DrawPolygon(pen, point);
|
||||
// крыло
|
||||
// топливо
|
||||
if (EntityAirBomber.Fuel)
|
||||
{
|
||||
g.FillEllipse(additionalBrush, _startPosX + 60, _startPosY - 1, 40, 10);
|
||||
|
@ -10,19 +10,20 @@ namespace ProjectAirBomber
|
||||
public class EntityAirBomber
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
|
||||
public double Weight { get; private set; }
|
||||
|
||||
public double Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
public bool Bombs { get; private set; }
|
||||
|
||||
public bool Fuel { get; private set; }
|
||||
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <param name="additionalColor"></param>
|
||||
/// <param name="bombs"></param>
|
||||
/// <param name="fuel"></param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bombs, bool fuel)
|
||||
{
|
||||
|
@ -7,6 +7,8 @@ namespace ProjectAirBomber
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingAirBomber == null)
|
||||
@ -18,6 +20,10 @@ namespace ProjectAirBomber
|
||||
_drawingAirBomber.DrawTransport(gr);
|
||||
pictureBoxAirBomber.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
@ -32,6 +38,10 @@ namespace ProjectAirBomber
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingAirBomber == null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user