Продвинутый объект.
This commit is contained in:
parent
73b439929b
commit
45020f50ad
@ -9,11 +9,11 @@ namespace Airbus
|
||||
//класс, отвечающий за прорисовку и перемещение объект
|
||||
internal class DrawingAirbus
|
||||
{
|
||||
public EntityAirbus Airbus { get; private set; } //класс-сущность
|
||||
public EntityAirbus Airbus { get; protected set; } //класс-сущность
|
||||
|
||||
private float _startPosX; //левая координата отрисовки
|
||||
protected float _startPosX; //левая координата отрисовки
|
||||
|
||||
private float _startPosY; //верхняя координата отрисовки
|
||||
protected float _startPosY; //верхняя координата отрисовки
|
||||
|
||||
private int? _pictureWidth = null; //ширина окна отрисовки
|
||||
|
||||
@ -28,6 +28,12 @@ namespace Airbus
|
||||
{
|
||||
Airbus = new EntityAirbus(speed, weight, corpusColor);
|
||||
}
|
||||
protected DrawingAirbus(int speed, float weight, Color corpusColor, int airbusWidth, int airbusHeight) :
|
||||
this(speed, weight, corpusColor)
|
||||
{
|
||||
_airbusWidth = airbusWidth;
|
||||
_airbusHeight = airbusHeight;
|
||||
}
|
||||
|
||||
//установка координат позиции самолёта
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
@ -87,7 +93,7 @@ namespace Airbus
|
||||
}
|
||||
|
||||
//отрисовка самолёта
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
|
49
Airbus/Airbus/DrawingSuperAirbus.cs
Normal file
49
Airbus/Airbus/DrawingSuperAirbus.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal class DrawingSuperAirbus : DrawingAirbus
|
||||
{
|
||||
//Инициализаци свойств
|
||||
public DrawingSuperAirbus(int speed, float weight, Color corpusColor, Color addColor, bool addCompartment, bool addEngine) :
|
||||
base(speed, weight, corpusColor, 110, 60)
|
||||
{
|
||||
Airbus = new EntitySuperAirbus(speed, weight, corpusColor, addColor, addCompartment, addEngine);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Airbus is not EntitySuperAirbus superAirbus)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush addBrush = new SolidBrush(superAirbus.AddColor);
|
||||
|
||||
//дополнительный пассажирский отсек
|
||||
if (superAirbus.AddСompartment)
|
||||
{
|
||||
g.FillEllipse(addBrush, _startPosX + 60, _startPosY + 28, 27, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 28, 27, 10);
|
||||
}
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
|
||||
//дополнительный двигатель
|
||||
if (superAirbus.AddEngine)
|
||||
{
|
||||
g.FillRectangle(addBrush, _startPosX + 45, _startPosY + 52, 25, 7);
|
||||
g.DrawRectangle(pen, _startPosX + 45, _startPosY + 52, 25, 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
30
Airbus/Airbus/EntitySuperAirbus.cs
Normal file
30
Airbus/Airbus/EntitySuperAirbus.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
//класс-сущность супер аэробус
|
||||
internal class EntitySuperAirbus: EntityAirbus
|
||||
{
|
||||
//Дополнительный цвет
|
||||
public Color AddColor { get; private set; }
|
||||
|
||||
//Признак наличия дополнительно пассажирского отсека
|
||||
public bool AddСompartment { get; private set; }
|
||||
|
||||
//Признак наличия доплнительных двигателей
|
||||
public bool AddEngine { get; private set; }
|
||||
|
||||
//Инициализация свойств
|
||||
public EntitySuperAirbus(int speed, float weight, Color corpusColor, Color addColor, bool addCompartment, bool addEngine) :
|
||||
base(speed, weight, corpusColor)
|
||||
{
|
||||
AddColor = addColor;
|
||||
AddСompartment = addCompartment;
|
||||
AddEngine = addEngine;
|
||||
}
|
||||
}
|
||||
}
|
15
Airbus/Airbus/FormAirbus.Designer.cs
generated
15
Airbus/Airbus/FormAirbus.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -81,6 +82,7 @@
|
||||
this.pictureBoxAirbus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxAirbus.TabIndex = 1;
|
||||
this.pictureBoxAirbus.TabStop = false;
|
||||
this.pictureBoxAirbus.Click += new System.EventHandler(this.PictureBoxAirbus_Resize);
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
@ -142,11 +144,23 @@
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(107, 401);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(109, 23);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// FormAirbus
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
@ -177,5 +191,6 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -26,15 +26,21 @@ namespace Airbus
|
||||
pictureBoxAirbus.Image = bmp;
|
||||
}
|
||||
|
||||
//ìåòîä óñòàíîâêè äàííûõ
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airbus.Airbus?.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airbus.Airbus?.Weight}";
|
||||
toolStripStatusLabelCorpusColor.Text = $"Öâåò: {_airbus.Airbus?.CorpusColor.Name}";
|
||||
_airbus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
}
|
||||
//îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_airbus = new DrawingAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_airbus.SetPosition(rnd.Next(10, 110), rnd.Next(10, 110), pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airbus.Airbus?.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airbus.Airbus?.Weight}";
|
||||
toolStripStatusLabelCorpusColor.Text = $"Öâåò: {_airbus.Airbus?.CorpusColor.Name}";
|
||||
_airbus = new DrawingAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000),Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
@ -60,11 +66,23 @@ namespace Airbus
|
||||
Draw();
|
||||
}
|
||||
|
||||
// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
||||
private void PictureBoxCar_Resize(object sender, EventArgs e)
|
||||
// èçìåíåíèå ðàçìåðîâ ôîðìû
|
||||
private void PictureBoxAirbus_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_airbus?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
//îáðàáîòêà íàæèòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_airbus = new DrawingSuperAirbus(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)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user