Добавление бомбардировщика
This commit is contained in:
parent
f5cb1bfbe2
commit
7f2ffe217c
67
AirBomber/AirBomber/DrawningAirBomber.cs
Normal file
67
AirBomber/AirBomber/DrawningAirBomber.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
internal class DrawningAirBomber : DrawningAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет обшивки</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="hasBombs">Признак наличия бомб</param>
|
||||
/// <param name="hasFuelTanks">Признак наличия топливных баков</param>
|
||||
public DrawningAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks)
|
||||
: base(speed, weight, bodyColor, 115, 155)
|
||||
{
|
||||
Airplane = new EntityAirBomber(speed, weight, bodyColor, dopColor, hasBombs, hasFuelTanks);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Airplane is not EntityAirBomber airBomber)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var x = _startPosX;
|
||||
var y = _startPosY;
|
||||
var w = _airplaneWidth;
|
||||
var h = _airplaneHeight;
|
||||
Brush brush = new SolidBrush(airBomber.DopColor);
|
||||
|
||||
if (airBomber.HasBombs) // Бомбы снизу рисуются сначала
|
||||
{
|
||||
DrawBomb(g, airBomber.DopColor, new RectangleF(x + w / 2 - 15, y + h / 2 - 19, 23, 10));
|
||||
DrawBomb(g, airBomber.DopColor, new RectangleF(x + w / 2 - 15, y + h / 2 + 9, 23, 10));
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (airBomber.HasFuelTanks)
|
||||
{
|
||||
g.FillEllipse(brush, new RectangleF(x + w / 4, y + h / 2 - 6, w / 2.5f, 12));
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBomb(Graphics g, Color colorBomb, RectangleF r)
|
||||
{
|
||||
Pen pen = new(colorBomb);
|
||||
pen.Width = r.Height / 3;
|
||||
var widthTail = r.Width / 6;
|
||||
g.FillEllipse(new SolidBrush(colorBomb), r.X, r.Y, r.Width - widthTail, r.Height); // Основание бомбы
|
||||
// Хвост бомбы
|
||||
var baseTail = new PointF(r.Right - widthTail, r.Y + r.Height / 2);
|
||||
g.DrawLine(pen, baseTail, new PointF(r.Right, r.Top));
|
||||
g.DrawLine(pen, baseTail, new PointF(r.Right, r.Bottom));
|
||||
}
|
||||
}
|
||||
}
|
@ -8,31 +8,31 @@
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirplane Airplane { get; private set; }
|
||||
public EntityAirplane Airplane { get; protected set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки автомобиля
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки автомобиля
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private int? _pictureWidth = null;
|
||||
protected int? _pictureWidth = null;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private int? _pictureHeight = null;
|
||||
protected int? _pictureHeight = null;
|
||||
/// <summary>
|
||||
/// Ширина отрисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _airplaneWidth = 110;
|
||||
protected readonly int _airplaneWidth = 110;
|
||||
/// <summary>
|
||||
/// Высота отрисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _airplaneHeight = 140;
|
||||
protected readonly int _airplaneHeight = 140;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
@ -43,6 +43,21 @@
|
||||
{
|
||||
Airplane = new EntityAirplane(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет обшивки</param>
|
||||
/// <param name="airplaneWidth">Ширина отрисовки самолета</param>
|
||||
/// <param name="airplaneHeight">Высота отрисовки самолета</param>
|
||||
protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_airplaneWidth = airplaneWidth;
|
||||
_airplaneHeight = airplaneHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции самолета
|
||||
/// </summary>
|
||||
@ -111,7 +126,7 @@
|
||||
/// Отрисовка самолета
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
|
40
AirBomber/AirBomber/EntityAirBomber.cs
Normal file
40
AirBomber/AirBomber/EntityAirBomber.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
internal class EntityAirBomber : EntityAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия бомб
|
||||
/// </summary>
|
||||
public bool HasBombs { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия топливных баков
|
||||
/// </summary>
|
||||
public bool HasFuelTanks { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="hasBombs">Признак наличия бомб</param>
|
||||
/// <param name="hasFuelTanks">Признак наличия топливных баков</param>
|
||||
public EntityAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
HasBombs = hasBombs;
|
||||
HasFuelTanks = hasFuelTanks;
|
||||
}
|
||||
}
|
||||
}
|
@ -26,8 +26,9 @@ namespace AirBomber
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_airplane = new DrawningAirplane();
|
||||
_airplane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_airplane = new DrawningAirBomber(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), true, false);
|
||||
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
||||
|
Loading…
Reference in New Issue
Block a user