Продвинутый объект
This commit is contained in:
parent
f9ff52e57b
commit
227307519b
@ -14,15 +14,15 @@ namespace WarmlyLocomotive
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityLocomotive Locomotive { get; private set; }
|
||||
public EntityLocomotive Locomotive { get; protected set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки локомотива
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки локомотива
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -49,6 +49,11 @@ namespace WarmlyLocomotive
|
||||
{
|
||||
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawningLocomotive(int speed, float weight, Color bodyColor, int locomotiveWidth, int locomotiveHeight) : this(speed, weight, bodyColor)
|
||||
{
|
||||
_locomotiveWidth = locomotiveWidth;
|
||||
_locomotiveHeight = locomotiveHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции локомотива
|
||||
/// </summary>
|
||||
@ -112,7 +117,7 @@ namespace WarmlyLocomotive
|
||||
/// Отрисовка локомотива
|
||||
/// </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)
|
||||
|
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class DrawningWarmlyLocomotive : DrawningLocomotive
|
||||
{
|
||||
public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool pipe, bool fuelCompartment, bool warmlyLines): base(speed, weight, bodyColor, 210, 120)
|
||||
{
|
||||
Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, dopColor, pipe, fuelCompartment, warmlyLines);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if(Locomotive is not EntityWarmlyLocomotive warmlyLocomotive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(warmlyLocomotive.DopColor);
|
||||
if (warmlyLocomotive.Pipe)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 125, _startPosY + 5, 35, 10);
|
||||
g.FillRectangle(dopBrush, _startPosX + 130, _startPosY, 25, 5);
|
||||
g.DrawRectangle(pen, _startPosX + 125, _startPosY + 5, 35, 10);
|
||||
g.DrawRectangle(pen, _startPosX + 130, _startPosY, 25, 5);
|
||||
}
|
||||
if (warmlyLocomotive.FuelCompartment)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 85, 50, 25);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 85, 50, 25);
|
||||
g.FillEllipse(new SolidBrush(Color.Black), _startPosX + 115, _startPosY + 100, 5, 5);
|
||||
}
|
||||
_startPosY += 15;
|
||||
base.DrawTransport(g);
|
||||
_startPosY -= 15;
|
||||
if (warmlyLocomotive.WarmlyLines)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 180, _startPosY + 60, 30, 5);
|
||||
g.FillRectangle(dopBrush, _startPosX + 180, _startPosY + 80, 30, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
37
WarmlyLocomotive/WarmlyLocomotive/EntityWarmlyLocomotive.cs
Normal file
37
WarmlyLocomotive/WarmlyLocomotive/EntityWarmlyLocomotive.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class EntityWarmlyLocomotive : EntityLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия трубы
|
||||
/// </summary>
|
||||
public bool Pipe { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия отсека под топливо
|
||||
/// </summary>
|
||||
public bool FuelCompartment { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия полос на кузове
|
||||
/// </summary>
|
||||
public bool WarmlyLines { get; private set; }
|
||||
public EntityWarmlyLocomotive(int speed, float weight, Color bodyColor, Color dopColor, bool pipe, bool fuelCompartment, bool warmlyLines) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Pipe = pipe;
|
||||
FuelCompartment = fuelCompartment;
|
||||
WarmlyLines = warmlyLines;
|
||||
}
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -141,11 +142,23 @@
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.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(105, 418);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(110, 23);
|
||||
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(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(837, 483);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
@ -176,5 +189,6 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -17,6 +17,17 @@ namespace WarmlyLocomotive
|
||||
_locomotive?.DrawTransport(gr);
|
||||
pictureBoxLocomotive.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_locomotive.Locomotive.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_locomotive.Locomotive.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_locomotive.Locomotive.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
@ -26,10 +37,7 @@ namespace WarmlyLocomotive
|
||||
{
|
||||
Random rnd = new();
|
||||
_locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_locomotive.Locomotive.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_locomotive.Locomotive.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_locomotive.Locomotive.BodyColor.Name}";
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
private void ButtonMove_click(object sender, EventArgs e)
|
||||
@ -57,5 +65,15 @@ namespace WarmlyLocomotive
|
||||
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_locomotive = new DrawningWarmlyLocomotive(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)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user