Создается модифицированный локомотив, требуется логика отрисовки
This commit is contained in:
parent
da86c334a4
commit
fc639a1deb
@ -10,11 +10,11 @@ namespace Locomotive
|
|||||||
internal class DrawningLocomotive
|
internal class DrawningLocomotive
|
||||||
{
|
{
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
public EntityLocomotive Locomotive { get; private set; }
|
public EntityLocomotive Locomotive { get; protected set; }
|
||||||
/// Левая координата отрисовки локомотива
|
/// Левая координата отрисовки локомотива
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
/// Верхняя координата отрисовки локомотива
|
/// Верхняя координата отрисовки локомотива
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
private int? _pictureWidth = null;
|
private int? _pictureWidth = null;
|
||||||
/// Высота окна отрисовки
|
/// Высота окна отрисовки
|
||||||
@ -29,6 +29,15 @@ namespace Locomotive
|
|||||||
{
|
{
|
||||||
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// Установка позиции локомотива
|
/// Установка позиции локомотива
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
@ -89,7 +98,7 @@ namespace Locomotive
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
44
Locomotive/Locomotive/DrawningWarmlyLocomotive.cs
Normal file
44
Locomotive/Locomotive/DrawningWarmlyLocomotive.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class DrawningWarmlyLocomotive : DrawningLocomotive
|
||||||
|
{
|
||||||
|
public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, Color extraColor, bool pipe, bool storage)
|
||||||
|
: base(speed, weight, bodyColor, locomotiveWidth: 110, locomotiveHeight: 50)
|
||||||
|
{
|
||||||
|
Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Locomotive is not EntityWarmlyLocomotive warmlyLocomotive)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush extraBrush = new SolidBrush(warmlyLocomotive.ExtraColor);
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
if (warmlyLocomotive.Pipe)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warmlyLocomotive.FuelStorage)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
28
Locomotive/Locomotive/EntityElectroLocomotive.cs
Normal file
28
Locomotive/Locomotive/EntityElectroLocomotive.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class EntityWarmlyLocomotive : EntityLocomotive
|
||||||
|
{
|
||||||
|
//доп. цвет
|
||||||
|
public Color ExtraColor { get; private set; }
|
||||||
|
//признак наличия трубы
|
||||||
|
public bool Pipe { get; private set; }
|
||||||
|
//признак наличия отсека под топливо
|
||||||
|
public bool FuelStorage { get; private set; }
|
||||||
|
|
||||||
|
public EntityWarmlyLocomotive (int speed, float weight, Color bodyColor, Color extraColor, bool pipe, bool fuelStorage)
|
||||||
|
: base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
ExtraColor = extraColor;
|
||||||
|
Pipe = pipe;
|
||||||
|
FuelStorage = fuelStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
14
Locomotive/Locomotive/FormLocomotive.Designer.cs
generated
14
Locomotive/Locomotive/FormLocomotive.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.buttonCreateModified = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -51,7 +52,6 @@
|
|||||||
this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
this.pictureBoxLocomotive.TabIndex = 0;
|
this.pictureBoxLocomotive.TabIndex = 0;
|
||||||
this.pictureBoxLocomotive.TabStop = false;
|
this.pictureBoxLocomotive.TabStop = false;
|
||||||
|
|
||||||
this.pictureBoxLocomotive.Resize += new System.EventHandler(this.pictureBoxLocomotive_Resize);
|
this.pictureBoxLocomotive.Resize += new System.EventHandler(this.pictureBoxLocomotive_Resize);
|
||||||
//
|
//
|
||||||
// statusStrip1
|
// statusStrip1
|
||||||
@ -144,11 +144,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);
|
||||||
//
|
//
|
||||||
|
// buttonCreateModified
|
||||||
|
//
|
||||||
|
this.buttonCreateModified.Location = new System.Drawing.Point(112, 377);
|
||||||
|
this.buttonCreateModified.Name = "buttonCreateModified";
|
||||||
|
this.buttonCreateModified.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonCreateModified.TabIndex = 7;
|
||||||
|
this.buttonCreateModified.Text = "Modified";
|
||||||
|
this.buttonCreateModified.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModified.Click += new System.EventHandler(this.buttonCreateModified_Click);
|
||||||
|
//
|
||||||
// FormLocomotive
|
// FormLocomotive
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(778, 442);
|
this.ClientSize = new System.Drawing.Size(778, 442);
|
||||||
|
this.Controls.Add(this.buttonCreateModified);
|
||||||
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);
|
||||||
@ -178,5 +189,6 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
private Button buttonCreateModified;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,14 +18,19 @@ namespace Locomotive
|
|||||||
pictureBoxLocomotive.Image = bmp;
|
pictureBoxLocomotive.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetData()
|
||||||
|
{
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}";
|
||||||
|
toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
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 = 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);
|
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}";
|
SetData();
|
||||||
toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}";
|
|
||||||
toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}";
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,5 +61,19 @@ namespace Locomotive
|
|||||||
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonCreateModified_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,1)),
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 1)));
|
||||||
|
|
||||||
|
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user