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

This commit is contained in:
ArtemEmelyanov 2022-10-15 22:40:19 +04:00
parent 928fa3a1df
commit 5ac86cbb43
5 changed files with 171 additions and 12 deletions

View File

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Airbus
{
internal class DrawningAirbus : DrawningPlane
{
/// <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 DrawningAirbus(int speed, float weight, Color bodyColor, Color
dopColor, bool bodyKit, bool wing, bool sportLine) :
base(speed, weight, bodyColor, 140, 70)
{
Plane = new EntityAirbus(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
}
public override void DrawTransport(Graphics g)
{
if (Plane is not EntityAirbus Airbus)
{
return;
}
Pen pen = new(Color.Black);
Brush dopBrush = new SolidBrush(Airbus.DopColor);
Brush fireBrush = new SolidBrush(Color.Red);
Brush WindowBrush = new SolidBrush(Color.Blue);
_startPosX += 10;
_startPosY += 5;
base.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 5;
if (Airbus.BodyKit)
{
//1 реактор
g.DrawRectangle(pen, _startPosX + 70, _startPosY + 50, 22, 16);
g.FillRectangle(dopBrush, _startPosX + 70, _startPosY + 50, 22, 16);
g.FillEllipse(dopBrush, _startPosX + 84, _startPosY + 50, 16, 16);
g.DrawEllipse(pen, _startPosX + 62, _startPosY + 50, 16, 16);
g.FillEllipse(fireBrush, _startPosX + 62, _startPosY + 50, 16, 16);
//2 реактор
g.DrawRectangle(pen, _startPosX + 8, _startPosY + 18, 22, 16);
g.FillRectangle(dopBrush, _startPosX + 8, _startPosY + 18, 22, 16);
g.FillEllipse(dopBrush, _startPosX + 24, _startPosY + 18, 16, 16);
g.DrawEllipse(pen, _startPosX, _startPosY + 18, 16, 16);
g.FillEllipse(fireBrush, _startPosX, _startPosY + 18, 16, 16);
}
if (Airbus.Wing)
{
g.DrawLine(pen, _startPosX + 70, _startPosY + 20, _startPosX + 70, _startPosY + 35);
g.DrawLine(pen, _startPosX + 70, _startPosY + 20, _startPosX + 90, _startPosY + 35);
}
if (Airbus.SportLine)
{
g.DrawEllipse(pen, _startPosX + 110, _startPosY + 40, 9, 9);
g.FillEllipse(WindowBrush, _startPosX + 110, _startPosY + 40, 9, 9);
}
}
}
}

View File

@ -11,16 +11,16 @@ namespace Airbus
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность
/// </summary> /// </summary>
public EntityPlane Plane { get; private set; } public EntityPlane Plane { get; protected set; }
/// <summary> /// <summary>
/// Левая координата отрисовки самолета /// Левая координата отрисовки самолета
/// </summary> /// </summary>
private float _startPosX; protected float _startPosX;
/// <summary> /// <summary>
/// Верхняя кооридната отрисовки самолета /// Верхняя кооридната отрисовки самолета
/// </summary> /// </summary>
private float _startPosY; protected float _startPosY;
/// <summary> /// <summary>
/// Ширина окна отрисовки /// Ширина окна отрисовки
/// </summary> /// </summary>
@ -114,7 +114,13 @@ namespace Airbus
/// Отрисовка самолета /// Отрисовка самолета
/// </summary> /// </summary>
/// <param name="g"></param> /// <param name="g"></param>
public void DrawTransport(Graphics g) ///
protected DrawningPlane(int speed, float weight, Color bodyColor, int planeWidth, int planeHeight) : this(speed, weight, bodyColor)
{
_PlaneWidth = planeWidth;
_PlaneHeight = planeHeight;
}
public virtual void DrawTransport(Graphics g)
{ {
if (_startPosX < 0 || _startPosY < 0 if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue) || !_pictureHeight.HasValue || !_pictureWidth.HasValue)

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Airbus
{
internal class EntityAirbus : EntityPlane
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; private set; }
/// <summary>
/// Признак наличия обвеса
/// </summary>
public bool BodyKit { get; private set; }
/// <summary>
/// Признак наличия антикрыла
/// </summary>
public bool Wing { get; private set; }
/// <summary>
/// Признак наличия гоночной полосы
/// </summary>
public bool SportLine { get; private set; }
/// <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 EntityAirbus(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : base(speed, weight, bodyColor)
{
DopColor = dopColor;
BodyKit = bodyKit;
Wing = wing;
SportLine = sportLine;
}
}
}

View File

@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -149,11 +150,22 @@
this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// FormAirbus // buttonCreateModif
//
this.buttonCreateModif.Location = new System.Drawing.Point(98, 285);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(99, 23);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
//
// FormPlane
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(700, 338); this.ClientSize = new System.Drawing.Size(700, 338);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonLeft);
@ -162,7 +174,7 @@
this.Controls.Add(this.statusStrip1); this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.pictureBoxAirbus); this.Controls.Add(this.pictureBoxAirbus);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormAirbus"; this.Name = "FormPlane";
this.Text = "Самолет"; this.Text = "Самолет";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).EndInit();
this.statusStrip1.ResumeLayout(false); this.statusStrip1.ResumeLayout(false);
@ -184,5 +196,6 @@
private Button buttonLeft; private Button buttonLeft;
private Button buttonUp; private Button buttonUp;
private Button buttonDown; private Button buttonDown;
private Button buttonCreateModif;
} }
} }

View File

@ -28,6 +28,15 @@ namespace Airbus
_plane?.DrawTransport(gr); _plane?.DrawTransport(gr);
pictureBoxAirbus.Image = bmp; pictureBoxAirbus.Image = bmp;
} }
private void SetData()
{
Random rnd = new();
_plane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_plane.Plane.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_plane.Plane.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {_plane.Plane.BodyColor.Name}";
}
/// <summary> /// <summary>
/// Обработка нажатия кнопки "Создать" /// Обработка нажатия кнопки "Создать"
/// </summary> /// </summary>
@ -35,13 +44,9 @@ namespace Airbus
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_plane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _plane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_plane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height); SetData();
toolStripStatusLabelSpeed.Text = $"Скорость: {_plane.Plane.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_plane.Plane.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {_plane.Plane.BodyColor.Name}";
Draw(); Draw();
} }
/// <summary> /// <summary>
@ -81,7 +86,13 @@ namespace Airbus
Draw(); Draw();
} }
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_plane = new DrawningAirbus(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();
}
} }
} }