Продвинутый объект без отрисовки
This commit is contained in:
parent
91aaf22ac6
commit
20c0f2302c
@ -14,15 +14,15 @@ namespace DoubleDeckerBus
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityBus Bus { private set; get; }
|
public EntityBus Bus { protected set; get; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки автобуса
|
/// Левая координата отрисовки автобуса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната отрисовки автобуса
|
/// Верхняя кооридната отрисовки автобуса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -49,6 +49,19 @@ namespace DoubleDeckerBus
|
|||||||
{
|
{
|
||||||
Bus = new EntityBus(speed, weight, bodyColor);
|
Bus = new EntityBus(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автобуса</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="carWidth">Ширина отрисовки автобуса</param>
|
||||||
|
/// <param name="carHeight">Высота отрисовки автобуса</param>
|
||||||
|
protected DrawningBus(int speed, float weight, Color bodyColor, int busWidth, int busHeight) :
|
||||||
|
this(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
_busWidth = busWidth;
|
||||||
|
_busHeight = busHeight;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции автобуса
|
/// Установка позиции автобуса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -112,7 +125,7 @@ namespace DoubleDeckerBus
|
|||||||
/// Отрисовка автобуса
|
/// Отрисовка автобуса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
|
51
DoubleDeckerBus/DoubleDeckerBus/DrawningDoubleDeckerBus.cs
Normal file
51
DoubleDeckerBus/DoubleDeckerBus/DrawningDoubleDeckerBus.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus
|
||||||
|
{
|
||||||
|
internal class DrawningDoubleDeckerBus : DrawningBus
|
||||||
|
{
|
||||||
|
/// <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 DrawningDoubleDeckerBus(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) :
|
||||||
|
base(speed, weight, bodyColor, 112, 50)
|
||||||
|
{
|
||||||
|
Bus = new EntityDoubleDeckerBus(speed, weight, bodyColor, dopColor, bodyKit,wing, sportLine);
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Bus is not EntityDoubleDeckerBus doubleDeckerBus)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush dopBrush = new SolidBrush(doubleDeckerBus.DopColor);
|
||||||
|
if (doubleDeckerBus.BodyKit)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
_startPosX += 10;
|
||||||
|
_startPosY += 5;
|
||||||
|
base.DrawTransport(g);
|
||||||
|
_startPosX -= 10;
|
||||||
|
_startPosY -= 5;
|
||||||
|
if (doubleDeckerBus.SportLine)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
if (doubleDeckerBus.Wing)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
47
DoubleDeckerBus/DoubleDeckerBus/EntityDoubleDeckerBus.cs
Normal file
47
DoubleDeckerBus/DoubleDeckerBus/EntityDoubleDeckerBus.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus
|
||||||
|
{
|
||||||
|
internal class EntityDoubleDeckerBus : EntityBus
|
||||||
|
{
|
||||||
|
/// <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 EntityDoubleDeckerBus(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
DoubleDeckerBus/DoubleDeckerBus/FormBus.Designer.cs
generated
13
DoubleDeckerBus/DoubleDeckerBus/FormBus.Designer.cs
generated
@ -38,6 +38,7 @@
|
|||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).BeginInit();
|
||||||
this.statusStrip.SuspendLayout();
|
this.statusStrip.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -140,11 +141,22 @@
|
|||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
|
// buttonCreateModif
|
||||||
|
//
|
||||||
|
this.buttonCreateModif.Location = new System.Drawing.Point(93, 393);
|
||||||
|
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||||
|
this.buttonCreateModif.Size = new System.Drawing.Size(104, 23);
|
||||||
|
this.buttonCreateModif.TabIndex = 7;
|
||||||
|
this.buttonCreateModif.Text = "Модификация";
|
||||||
|
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||||
|
//
|
||||||
// FormBus
|
// FormBus
|
||||||
//
|
//
|
||||||
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(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
@ -174,5 +186,6 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
private Button buttonCreateModif;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,6 +14,20 @@ namespace DoubleDeckerBus
|
|||||||
_bus?.DrawTransport(gr);
|
_bus?.DrawTransport(gr);
|
||||||
pictureBoxBus.Image = bmp;
|
pictureBoxBus.Image = bmp;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void SetData()
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_bus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBus.Width, pictureBoxBus.Height);
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_bus.Bus.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_bus.Bus.Weight}";
|
||||||
|
toolStripStatusLabelBodyColor.Text = $"Öâåò:{_bus.Bus.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -28,9 +42,7 @@ namespace DoubleDeckerBus
|
|||||||
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)));
|
||||||
_bus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
|
_bus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
|
||||||
pictureBoxBus.Width, pictureBoxBus.Height);
|
pictureBoxBus.Width, pictureBoxBus.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_bus.Bus.Speed}";
|
SetData();
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_bus.Bus.Weight}";
|
|
||||||
toolStripStatusLabelBodyColor.Text = $"Öâåò:{ _bus.Bus.BodyColor.Name}";
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -69,5 +81,21 @@ namespace DoubleDeckerBus
|
|||||||
_bus?.ChangeBorders(pictureBoxBus.Width, pictureBoxBus.Height);
|
_bus?.ChangeBorders(pictureBoxBus.Width, pictureBoxBus.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_bus = new DrawningDoubleDeckerBus(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,1)), Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0, 1)));
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user