Продвинутый объект.

This commit is contained in:
Андрей Абазов 2022-09-20 13:00:14 +04:00
parent 79b4ee847c
commit f5f9486ec0
5 changed files with 172 additions and 4 deletions

View File

@ -11,15 +11,15 @@ namespace AirBomber
/// <summary>
/// Класс-сущность
/// </summary>
public EntityAirBomber AirBomber { private set; get; }
public EntityAirBomber AirBomber { protected set; get; }
/// <summary>
/// Левая координата отрисовки бомбардировщика
/// </summary>
private float _startPosX;
protected float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки бомбардировщика
/// </summary>
private float _startPosY;
protected float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -47,6 +47,21 @@ namespace AirBomber
AirBomber = new EntityAirBomber(speed, weight, bodyColor);
}
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес бомбардировщика</param>
/// <param name="bodyColor">Цвет корпуса</param>
/// <param name="carWidth">Ширина отрисовки бомбардировщика</param>
/// <param name="carHeight">Высота отрисовки бомбардировщика</param>
protected DrawingAirBomber(int speed, float weight, Color bodyColor, int carWidth, int carHeight) :
this(speed, weight, bodyColor)
{
_airBomberWidth = carWidth;
_airBomberHeight = carHeight;
}
/// <summary>
/// Установка позиции омбардировщика
/// </summary>
@ -112,7 +127,7 @@ namespace AirBomber
/// Отрисовка бомбардировщика
/// </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)

View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
internal class DrawingHeavyAirBomber : DrawingAirBomber
{
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public DrawingHeavyAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) :
base(speed, weight, bodyColor, 110, 100)
{
AirBomber = new EntityHeavyAirBomber(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
}
public override void DrawTransport(Graphics g)
{
if (AirBomber is not EntityHeavyAirBomber heavyAirBomber)
{
return;
}
Pen pen = new(Color.Black);
Brush dopBrush = new SolidBrush(heavyAirBomber.DopColor);
if (heavyAirBomber.Bombs)
{
g.FillEllipse(dopBrush, _startPosX + 45, _startPosY, 20, 10);
g.FillEllipse(dopBrush, _startPosX + 45, _startPosY + 90, 20, 10);
g.DrawEllipse(pen, _startPosX + 45, _startPosY, 20, 10);
g.DrawEllipse(pen, _startPosX + 45, _startPosY + 90, 20, 10);
}
base.DrawTransport(g);
if (heavyAirBomber.TailLine) //TODO отрисовка полоски на хвосте
{
g.FillRectangle(dopBrush, _startPosX + 95, _startPosY + 30, 15, 5);
g.FillRectangle(dopBrush, _startPosX + 95, _startPosY + 65, 15, 5);
}
if (heavyAirBomber.FuelTank) //TODO отрисовка топливных баков
{
g.FillEllipse(dopBrush, _startPosX + 23, _startPosY + 42, 25, 15);
g.FillEllipse(dopBrush, _startPosX + 53, _startPosY + 42, 25, 15);
g.FillEllipse(dopBrush, _startPosX + 83, _startPosY + 42, 25, 15);
g.DrawEllipse(pen, _startPosX + 23, _startPosY + 42, 25, 15);
g.DrawEllipse(pen, _startPosX + 53, _startPosY + 42, 25, 15);
g.DrawEllipse(pen, _startPosX + 83, _startPosY + 42, 25, 15);
}
}
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
/// <summary>
/// Класс-сущность "Тяжелый бомбардировщик"
/// </summary>
internal class EntityHeavyAirBomber : EntityAirBomber
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; private set; }
/// <summary>
/// Признак наличия бомб
/// </summary>
public bool Bombs { get; private set; }
/// <summary>
/// Признак наличия топливных баков
/// </summary>
public bool FuelTank { get; private set; }
/// <summary>
/// Признак наличия полосы на хвосте
/// </summary>
public bool TailLine { get; private set; }
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес бомбардировщика</param>
/// <param name="bodyColor">Цвет корпуса</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bombs">Признак наличия обвеса</param>
/// <param name="fuelTank">Признак наличия антикрыла</param>
/// <param name="tailLine">Признак наличия гоночной полосы</param>
public EntityHeavyAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool bombs, bool fuelTank, bool tailLine) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
Bombs = bombs;
FuelTank = fuelTank;
TailLine = tailLine;
}
}
}

View File

@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirBomber)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@ -143,11 +144,22 @@
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonCreateModif
//
this.buttonCreateModif.Location = new System.Drawing.Point(112, 395);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(120, 29);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
//
// FormAirBomber
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(882, 453);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonCreateAirBomber);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
@ -177,5 +189,6 @@
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonCreateModif;
}
}

View File

@ -67,5 +67,33 @@ namespace AirBomber
_airBomber?.ChangeBorders(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
Draw();
}
/// <summary>
/// Ìåòîä óñòàíîâêè äàííûõ
/// </summary>
private void SetData()
{
Random rnd = new();
_airBomber.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airBomber.AirBomber.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_airBomber.AirBomber.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airBomber.AirBomber.BodyColor.Name}";
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_airBomber = new DrawingHeavyAirBomber(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)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
}
}