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

This commit is contained in:
Sem730 2022-09-27 10:48:19 +03:00
parent 5669b4e535
commit 9436161a1a
5 changed files with 204 additions and 21 deletions

View File

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLocomotive
{
internal class DrawningElectroLocomotive : DrawningLocomotive
{
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="electroLines">Признак наличия "рогов" для подключения</param>
/// <param name="electroBattery">Признак наличия отсека электро-батарей</param>
public DrawningElectroLocomotive(int speed, float weight, Color bodyColor, Color
dopColor, bool electroLines, bool electroBattery) :
base(speed, weight, bodyColor, 110, 60)
{
Locomotivе = new EntityElectricLocomotive(speed, weight, bodyColor, dopColor, electroLines,
electroBattery);
}
public override void DrawTransport(Graphics g)
{
if (Locomotivе is not EntityElectricLocomotive elLocc)
{
return;
}
Pen pen = new(Color.Black);
Brush dopBrush = new SolidBrush(elLocc.DopColor);
if (elLocc.ElectroLines)
{
g.DrawLine(pen, _startPosX + 20, _startPosY, _startPosX + 5, _startPosY - 12);
g.DrawLine(pen, _startPosX + 20, _startPosY, _startPosX + 35, _startPosY - 12);
g.DrawLine(pen, _startPosX + 70, _startPosY, _startPosX + 55, _startPosY - 12);
g.DrawLine(pen, _startPosX + 70, _startPosY, _startPosX + 85, _startPosY - 12);
// g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20);
// g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20, 20);
// g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10, 20, 40);
// g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, 15);
// g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45, 15, 15);
// g.FillEllipse(dopBrush, _startPosX + 90, _startPosY, 20, 20);
// g.FillEllipse(dopBrush, _startPosX + 90, _startPosY + 40, 20, 20);
// g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 10, 20,
//40);
// g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 1, 15,
//15);
// g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 45, 15,
//15);
// g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20);
// g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20);
// g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20, 40);
// g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14, 15);
// g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45, 14, 15);
// g.FillEllipse(dopBrush, _startPosX, _startPosY, 20, 20);
// g.FillEllipse(dopBrush, _startPosX, _startPosY + 40, 20, 20);
// g.FillRectangle(dopBrush, _startPosX + 1, _startPosY + 10, 25,
//40);
// g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 1, 15, 15);
// g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 45, 15,
//15);
// g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39, 15);
// g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45, 39, 15);
// g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 1, 40,
//15);
// g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 45, 40,
//15);
}
//_startPosX += 10;
//_startPosY += 5;
base.DrawTransport(g);
//_startPosX -= 10;
//_startPosY -= 5;
if (elLocc.ElectroBattery)
{
Brush brblack = new SolidBrush(Color.Black);
g.FillRectangle(brblack, _startPosX + 40, _startPosY + 25, 15, 5);
g.FillRectangle(brblack, _startPosX + 60, _startPosY + 25, 15, 5);
g.FillRectangle(brblack, _startPosX + 5, _startPosY + 25, 15, 5);
//g.FillRectangle(brblack, _startPosX + 70, _startPosY + 3, 5, 10);
//g.FillRectangle(dopBrush, _startPosX, _startPosY + 5, 10, 50);
//g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10, 50);
}
}
}
}

View File

@ -14,15 +14,15 @@ namespace ProjectLocomotive
/// <summary>
/// Класс-сущность
/// </summary>
public EntityLocomotive Locomotivе { private set; get; }
public EntityLocomotive Locomotivе { get; protected set; }
/// <summary>
/// Левая координата отрисовки локомотива
/// </summary>
private float _startPosX;
protected float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки локомотива
/// </summary>
private float _startPosY;
protected float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -50,6 +50,21 @@ namespace ProjectLocomotive
Locomotivе = new EntityLocomotive(speed, weight, bodyColor);
}
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="carWidth">Ширина отрисовки автомобиля</param>
/// <param name="carHeight">Высота отрисовки автомобиля</param>
protected DrawningLocomotive(int speed, float weight, Color bodyColor, int
carWidth, int carHeight) :
this(speed, weight, bodyColor)
{
_LocWidth = carWidth;
_LocHeight = carHeight;
}
/// <summary>
/// Установка позиции автомобиля
/// </summary>
/// <param name="x">Координата X</param>
@ -118,7 +133,7 @@ namespace ProjectLocomotive
/// Отрисовка автомобиля
/// </summary>
/// <param name="g"></param>
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,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLocomotive
{
internal class EntityElectricLocomotive : EntityLocomotive
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; private set; }
/// <summary>
/// Признак наличия "рогов" для подключения
/// </summary>
public bool ElectroLines { get; private set; }
/// <summary>
/// Признак наличия отсека электро-батарей
/// </summary>
public bool ElectroBattery { get; private set; }
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="electroLines">Признак наличия "рогов" для подключения</param>
/// <param name="electroBattery">Признак наличия отсека электро-батарей</param>
public EntityElectricLocomotive(int speed, float weight, Color bodyColor, Color
dopColor, bool electroLines, bool electroBattery) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
ElectroLines = electroLines = true;
ElectroBattery = electroBattery = true;
}
}
}

View File

@ -38,6 +38,7 @@
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@ -88,19 +89,6 @@
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
this.buttonLeft.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectLocomotive.Properties.Resources.right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(711, 375);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
this.buttonRight.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -114,6 +102,19 @@
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
this.buttonDown.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectLocomotive.Properties.Resources.right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(711, 375);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
this.buttonRight.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
@ -144,11 +145,22 @@
this.statusStrip.Size = new System.Drawing.Size(800, 32);
this.statusStrip.TabIndex = 1;
//
// buttonCreateModif
//
this.buttonCreateModif.Location = new System.Drawing.Point(120, 375);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(138, 30);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// FormLocomotive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
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);
@ -178,5 +190,6 @@
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private StatusStrip statusStrip;
private Button buttonCreateModif;
}
}

View File

@ -20,6 +20,17 @@ namespace ProjectLocomotive
pictureBoxLocomotive.Image = bmp;
}
/// <summary>
/// Ìåòîä óñòàíîâêè äàííûõ
/// </summary>
private void SetData()
{
Random rnd = new();
_elloc.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_elloc.Locomotivå.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_elloc.Locomotivå.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_elloc.Locomotivå.BodyColor.Name}";
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
/// </summary>
/// <param name="sender"></param>
@ -29,10 +40,7 @@ namespace ProjectLocomotive
{
Random rnd = new();
_elloc = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_elloc.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_elloc.Locomotivå.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_elloc.Locomotivå.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_elloc.Locomotivå.BodyColor.Name}";
SetData();
Draw();
}
/// <summary>
@ -71,5 +79,20 @@ namespace ProjectLocomotive
_elloc?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
Draw();
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_elloc = new DrawningElectroLocomotive(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(1, 100), rnd.Next(1, 100), rnd.Next(1, 100)),
Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0, 1)));
SetData();
Draw();
}
}
}