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

This commit is contained in:
Nikolaeva_Y.A 2022-10-24 23:59:41 +04:00
parent 73b439929b
commit 45020f50ad
5 changed files with 129 additions and 11 deletions

View File

@ -9,11 +9,11 @@ namespace Airbus
//класс, отвечающий за прорисовку и перемещение объект //класс, отвечающий за прорисовку и перемещение объект
internal class DrawingAirbus 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; //ширина окна отрисовки private int? _pictureWidth = null; //ширина окна отрисовки
@ -28,6 +28,12 @@ namespace Airbus
{ {
Airbus = new EntityAirbus(speed, weight, corpusColor); 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) 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) if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{ {

View 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);
}
}
}
}

View 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;
}
}
}

View File

@ -38,6 +38,7 @@
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
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.buttonCreateModif = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -81,6 +82,7 @@
this.pictureBoxAirbus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxAirbus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxAirbus.TabIndex = 1; this.pictureBoxAirbus.TabIndex = 1;
this.pictureBoxAirbus.TabStop = false; this.pictureBoxAirbus.TabStop = false;
this.pictureBoxAirbus.Click += new System.EventHandler(this.PictureBoxAirbus_Resize);
// //
// buttonCreate // buttonCreate
// //
@ -142,11 +144,23 @@
this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); 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 // FormAirbus
// //
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(884, 461); this.ClientSize = new System.Drawing.Size(884, 461);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonRight);
@ -177,5 +191,6 @@
private Button buttonRight; private Button buttonRight;
private Button buttonLeft; private Button buttonLeft;
private Button buttonUp; private Button buttonUp;
private Button buttonCreateModif;
} }
} }

View File

@ -26,15 +26,21 @@ namespace Airbus
pictureBoxAirbus.Image = bmp; 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) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); 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 = 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); SetData();
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airbus.Airbus?.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_airbus.Airbus?.Weight}";
toolStripStatusLabelCorpusColor.Text = $"Öâåò: {_airbus.Airbus?.CorpusColor.Name}";
Draw(); Draw();
} }
@ -60,11 +66,23 @@ namespace Airbus
Draw(); Draw();
} }
// Èçìåíåíèå ðàçìåðîâ ôîðìû // èçìåíåíèå ðàçìåðîâ ôîðìû
private void PictureBoxCar_Resize(object sender, EventArgs e) private void PictureBoxAirbus_Resize(object sender, EventArgs e)
{ {
_airbus?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height); _airbus?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
Draw(); 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();
}
} }
} }