Продвинутый объект
This commit is contained in:
parent
c2213d181e
commit
ac01934875
@ -14,15 +14,15 @@ namespace ProjectMachine
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityMachine Machine { get; private set; }
|
||||
public EntityMachine Machine { get; protected set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки машины
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки машины
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -56,6 +56,13 @@ namespace ProjectMachine
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
protected DrawningMachine(int speed, float weight, Color bodyColor, int machineWidth, int machineHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_machineWidth = machineWidth;
|
||||
_machineHeight = machineHeight;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x < 0 || y < 0 || x + _machineWidth > width || y + _machineHeight > height)
|
||||
@ -113,7 +120,7 @@ namespace ProjectMachine
|
||||
/// Отрисовка машины
|
||||
/// </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)
|
||||
|
54
ProjectMachine/ProjectMachine/DrawningTank.cs
Normal file
54
ProjectMachine/ProjectMachine/DrawningTank.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectMachine
|
||||
{
|
||||
internal class DrawningTank : DrawningMachine
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="turret">Признак наличия башни с орудием</param>
|
||||
/// <param name="gun">Признак наличия зенитного пулемета</param>
|
||||
public DrawningTank(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool turret, bool gun) :
|
||||
base(speed, weight, bodyColor, 110, 60)
|
||||
{
|
||||
Machine = new EntityTank(speed, weight, bodyColor, dopColor, bodyKit, turret, gun);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Machine is not EntityTank tank)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(tank.DopColor);
|
||||
|
||||
if (tank.BodyKit)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 45, _startPosY, 20, 10);
|
||||
g.DrawLine(pen, _startPosX + 65, _startPosY + 2, _startPosX + 85, _startPosY + 2);
|
||||
}
|
||||
|
||||
if (tank.Turret)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 45, _startPosY, 20, 10);
|
||||
}
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
}
|
||||
}
|
||||
}
|
50
ProjectMachine/ProjectMachine/EntityTank.cs
Normal file
50
ProjectMachine/ProjectMachine/EntityTank.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectMachine
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Танк"
|
||||
/// </summary>
|
||||
internal class EntityTank : EntityMachine
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия обвеса
|
||||
/// <summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия башни с орудием
|
||||
/// </summary>
|
||||
public bool Turret { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия зенитного пулемета
|
||||
/// </summary>
|
||||
public bool Gun { 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="turret">Признак наличия башни с орудием</param>
|
||||
/// <param name="gun">Признак наличия зенитного пулемета</param>
|
||||
public EntityTank(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool turret, bool gun) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
BodyKit = bodyKit;
|
||||
Turret = turret;
|
||||
Gun = gun;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxMachine)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -148,11 +149,22 @@
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(124, 385);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(130, 29);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// FormMachine
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(733, 453);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
@ -182,5 +194,6 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -19,6 +19,17 @@ namespace ProjectMachine
|
||||
pictureBoxMachine.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_machine.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxMachine.Width, pictureBoxMachine.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_machine.Machine.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_machine.Machine.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_machine.Machine.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
@ -27,10 +38,7 @@ namespace ProjectMachine
|
||||
{
|
||||
Random rnd = new();
|
||||
_machine = new DrawningMachine(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_machine.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxMachine.Width, pictureBoxMachine.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_machine.Machine.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_machine.Machine.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_machine.Machine.BodyColor.Name}";
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -69,5 +77,17 @@ namespace ProjectMachine
|
||||
_machine?.ChangeBorders(pictureBoxMachine.Width, pictureBoxMachine.Height);
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_machine = new DrawningTank(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…
x
Reference in New Issue
Block a user