diff --git a/Airbus/Airbus/DrawingAirbus.cs b/Airbus/Airbus/DrawingAirbus.cs index ced977d..7452b16 100644 --- a/Airbus/Airbus/DrawingAirbus.cs +++ b/Airbus/Airbus/DrawingAirbus.cs @@ -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) { diff --git a/Airbus/Airbus/DrawingSuperAirbus.cs b/Airbus/Airbus/DrawingSuperAirbus.cs new file mode 100644 index 0000000..2fbf20c --- /dev/null +++ b/Airbus/Airbus/DrawingSuperAirbus.cs @@ -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); + } + } + } +} diff --git a/Airbus/Airbus/EntitySuperAirbus.cs b/Airbus/Airbus/EntitySuperAirbus.cs new file mode 100644 index 0000000..fd95042 --- /dev/null +++ b/Airbus/Airbus/EntitySuperAirbus.cs @@ -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; + } + } +} diff --git a/Airbus/Airbus/FormAirbus.Designer.cs b/Airbus/Airbus/FormAirbus.Designer.cs index fe67844..6a3a792 100644 --- a/Airbus/Airbus/FormAirbus.Designer.cs +++ b/Airbus/Airbus/FormAirbus.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/Airbus/Airbus/FormAirbus.cs b/Airbus/Airbus/FormAirbus.cs index 06362ca..8c7b0e4 100644 --- a/Airbus/Airbus/FormAirbus.cs +++ b/Airbus/Airbus/FormAirbus.cs @@ -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(); + } } } \ No newline at end of file