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

This commit is contained in:
Programmist73 2022-09-25 01:12:44 +04:00
parent 7b553ddbb5
commit c4a88ba804
7 changed files with 137 additions and 16 deletions

View File

@ -6,14 +6,14 @@ using System.Threading.Tasks;
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; //ширина окна отрисовки
@ -29,6 +29,13 @@ 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 +94,7 @@ namespace Airbus
}
//отрисовка самолёта
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,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(Color.Black);
Brush addBrush = new SolidBrush(superAirbus.AddColor);
//дополнительный пассажирский отсек
if (superAirbus.AddСompartment)
{
g.FillRectangle(addBrush, _startPosX + 30, _startPosY + 12, 14, 3);
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 12, 14, 3);
}
_startPosX += 10;
_startPosY += 5;
base.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 5;
//дополнительный двигатель
if (superAirbus.AddEngine)
{
g.FillEllipse(addBrush, _startPosX + 24, _startPosY + 22, 10, 5);
g.DrawEllipse(pen, _startPosX + 24, _startPosY + 22, 10, 5);
}
}
}
}

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
namespace Airbus
{
//класс-сущность аэробус
internal class EntityAirbus
{
public int Speed { get; private set; } //скорость

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

@ -39,6 +39,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.pictureBoxAirbus)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@ -89,7 +90,7 @@
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(12, 392);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.Size = new System.Drawing.Size(95, 30);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
@ -143,11 +144,23 @@
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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(112, 392);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(120, 30);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
@ -177,5 +190,6 @@
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonCreateModif;
}
}

View File

@ -27,22 +27,30 @@ namespace Airbus
_airbus?.DrawTransport(gr);
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, 100), rnd.Next(10, 100), 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();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
//Получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
@ -62,11 +70,23 @@ namespace Airbus
Draw();
}
// Изменение размеров формы
//изменение размеров формы
private void PictureBoxCar_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();
}
}
}

View File

@ -64,7 +64,7 @@
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA5gAAAOYBAMAAABC5kGOAAAABGdBTUEAALGPC/xhBQAAABtQTFRF////
AAAA5ubmAP8Aq6urAP4AAI0AVVVVAEAANUbI4gAAAAlwSFlzAAAOwAAADsABataJCQAAFsZJREFUeNrt
AAAA5ubmAP8Aq6urAP4AAI0AVVVVAEAANUbI4gAAAAlwSFlzAAAOvgAADr4B6kKxwAAAFsZJREFUeNrt
nT2LJMkVRZNC0O4WNDtrptppWxS9rDkjBLLFMItcIRZkqmBBrtbS/mzNR+1OV1V+RGbGu++9yHO9O1bl
HE69jIzI6u7pS/ruSxqs/eGvv3z389t2L/BrbfriPtc/nI8f86bdC/xam764z3l3/JzHVi/wVW364j7l
+XjJvxu9wFe16Yv7lPNvMB8bvcCb+jGHyz+1VvuH4+952+IFvq5dyxf3qZy/wvxvixe4I5ivxTw+Hp6A
@ -168,7 +168,7 @@
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA5gAAAOYBAMAAABC5kGOAAAABGdBTUEAALGPC/xhBQAAABtQTFRF////
AAAA5ubmAP8Aq6urAP4AAI0AVVVVAEAANUbI4gAAAAlwSFlzAAAOwAAADsABataJCQAAFodJREFUeNrt
AAAA5ubmAP8Aq6urAP4AAI0AVVVVAEAANUbI4gAAAAlwSFlzAAAOvgAADr4B6kKxwAAAFodJREFUeNrt
nU2PHEd2RQsFAdy6BvRQy56GAf+AhgwvJcOA1gYhw1vD0KxbhhbeDgb632aTzSYZnVFVWRkf7508x6s3
Xsx0HVxGRUTeysPhcLz/xOETA8affzvBeff7lA92/H/n8afTDni7C5l3u3D5ZHMHMr877YQf+TL3EswP
0Rwv88PH+/wfPf8nvcfTbhj8wX6cx/53vjnthke8zL+cdsM/4GXit5hfeKdMDt/jZZ52BF3m8bQj7uAy
@ -271,7 +271,7 @@
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA5gAAAOYBAMAAABC5kGOAAAABGdBTUEAALGPC/xhBQAAABtQTFRF////
AAAA5ubmAP8Aq6urAP4AAI0AVVVVAEAANUbI4gAAAAlwSFlzAAAOwAAADsABataJCQAAGCxJREFUeNrt
AAAA5ubmAP8Aq6urAP4AAI0AVVVVAEAANUbI4gAAAAlwSFlzAAAOvgAADr4B6kKxwAAAGCxJREFUeNrt
nU2LHEcWRdNFg2dbM7bby6LwP2jK6xEY/ANEe2+M963GMLM1xoN/9thSy5Ki4kXlV0S8G++c3dNGBIeb
2ZWRN2M6n0/TO87vGG48Hb7/9Y9fTuMu8O8xgMzDm+Of3J+QqT+eXh3f8gUy9cfPjy88DbrAQDLfB/PP
C+005ALPgWTeHY9JNJEpO372QeZLNJGpOn64yv4VzcN4C/x4HF7mm49k3p/GW+DH4/CX2ePHPA24wHNU