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

This commit is contained in:
ityurner02@mail.ru 2022-09-17 21:00:14 +04:00
parent 001cdd770b
commit eb0dcce570
6 changed files with 157 additions and 13 deletions

View File

@ -14,15 +14,15 @@ namespace AntiAircraftGun
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность
/// </summary> /// </summary>
public EntityAntiAircraftGun AntiAircraftGun { private set; get; } public EntityAntiAircraftGun AntiAircraftGun { 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>
@ -50,6 +50,20 @@ namespace AntiAircraftGun
AntiAircraftGun = new EntityAntiAircraftGun(speed, weight, bodyColor); AntiAircraftGun = new EntityAntiAircraftGun(speed, weight, bodyColor);
} }
/// <summary> /// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес зенитного орудия</param>
/// <param name="bodyColor">Цвет корпуса</param>
/// <param name="carWidth">Ширина отрисовки зенитного орудия</param>
/// <param name="carHeight">Высота отрисовки зенитного орудия</param>
protected DrawingAntiAircraftGun(int speed, float weight, Color bodyColor, int antiAircrafGunWidth, int antiAircrafGunHeight) :
this(speed, weight, bodyColor)
{
_antiAircrafGunWidth = antiAircrafGunWidth;
_antiAircrafGunHeight = antiAircrafGunHeight;
}
/// <summary>
/// Установка позиции зенитного орудия /// Установка позиции зенитного орудия
/// </summary> /// </summary>
/// <param name="x">Координата X</param> /// <param name="x">Координата X</param>
@ -112,7 +126,7 @@ namespace AntiAircraftGun
/// Отрисовка зенитного орудия /// Отрисовка зенитного орудия
/// </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)

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun
{
internal class DrawingUpdateAntiAircraftGun : DrawingAntiAircraftGun
{
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес зенитного орудия</param>
/// <param name="bodyColor">Цвет корпуса</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="gun">Признак наличия башни с орудием</param>
/// <param name="radar">Признак наличия радара</param>
public DrawingUpdateAntiAircraftGun(int speed, float weight, Color bodyColor, Color dopColor, bool gun, bool radar) :
base(speed, weight, bodyColor, 110, 75)
{
AntiAircraftGun = new EntityUpdateAntiAircraftGun(speed, weight, bodyColor, dopColor, gun, radar);
}
public override void DrawTransport(Graphics g)
{
if (AntiAircraftGun is not EntityUpdateAntiAircraftGun updateAntiAircraftGun)
{
return;
}
Pen dopPen = new(updateAntiAircraftGun.DopColor, 4);
Brush dopBrush = new SolidBrush(updateAntiAircraftGun.DopColor);
_startPosY += 35;
base.DrawTransport(g);
_startPosY -= 35;
if (updateAntiAircraftGun.Gun)
{
g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 20, 25, 15);
g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 25, 50, 5);
g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 30, 20, 5);
}
if (updateAntiAircraftGun.Radar)
{
g.DrawLine(dopPen, _startPosX + 27, _startPosY + 35, _startPosX + 27, _startPosY + 20);
g.FillPie(dopBrush, _startPosX + 3, _startPosY, 30, 30, -45, 180);
g.DrawLine(dopPen, _startPosX + 20, _startPosY + 15, _startPosX + 15, _startPosY + 10);
g.FillEllipse(dopBrush, _startPosX + 10, _startPosY + 5, 10, 10);
}
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun
{
internal class EntityUpdateAntiAircraftGun : EntityAntiAircraftGun
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; private set; }
/// <summary>
/// Признак наличия башни с орудием
/// </summary>
public bool Gun { get; private set; }
/// <summary>
/// Признак наличия радара
/// </summary>
public bool Radar { get; private set; }
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес зенитного орудия</param>
/// <param name="bodyColor">Цвет корпуса</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="gun">Признак наличия башни с орудием</param>
/// <param name="radar">Признак наличия радара</param>
public EntityUpdateAntiAircraftGun(int speed, float weight, Color bodyColor, Color dopColor, bool gun, bool radar) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
Gun = gun;
Radar = radar;
}
}
}

View File

@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonCreareModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit();
this.statusStrip.SuspendLayout(); this.statusStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -142,11 +143,23 @@
this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonCreareModif
//
this.buttonCreareModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreareModif.Location = new System.Drawing.Point(111, 381);
this.buttonCreareModif.Name = "buttonCreareModif";
this.buttonCreareModif.Size = new System.Drawing.Size(125, 29);
this.buttonCreareModif.TabIndex = 7;
this.buttonCreareModif.Text = "Модификация";
this.buttonCreareModif.UseVisualStyleBackColor = true;
this.buttonCreareModif.Click += new System.EventHandler(this.ButtonCreareModif_Click);
//
// FormAntiAircraftGun // FormAntiAircraftGun
// //
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(800, 451); this.ClientSize = new System.Drawing.Size(800, 451);
this.Controls.Add(this.buttonCreareModif);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonLeft);
@ -178,5 +191,6 @@
private Button buttonLeft; private Button buttonLeft;
private Button buttonRight; private Button buttonRight;
private Button buttonDown; private Button buttonDown;
private Button buttonCreareModif;
} }
} }

View File

@ -23,6 +23,17 @@ namespace AntiAircraftGun
pictureBoxAntiAircraftGun.Image = bmp; pictureBoxAntiAircraftGun.Image = bmp;
} }
} }
/// <summary>
/// Ìåòîä óñòàíîâêè äàííûõ
/// </summary>
private void SetData()
{
Random rnd = new();
_antiAircrafGun.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_antiAircrafGun.AntiAircraftGun.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_antiAircrafGun.AntiAircraftGun.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_antiAircrafGun.AntiAircraftGun.BodyColor.Name}";
}
/// <summary> /// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü" /// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
@ -31,15 +42,11 @@ namespace AntiAircraftGun
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_antiAircrafGun = new DrawingAntiAircraftGun(rnd.Next(100, 300), rnd.Next(1000, 2000), _antiAircrafGun = new DrawingAntiAircraftGun(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)));
_antiAircrafGun.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), SetData();
pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); Draw();
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_antiAircrafGun.AntiAircraftGun.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_antiAircrafGun.AntiAircraftGun.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_antiAircrafGun.AntiAircraftGun.BodyColor.Name}";
Draw();
} }
/// <summary> /// <summary>
/// Èçìåíåíèå ðàçìåðîâ ôîðìû /// Èçìåíåíèå ðàçìåðîâ ôîðìû
@ -77,5 +84,20 @@ namespace AntiAircraftGun
_antiAircrafGun?.ChangeBorders(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); _antiAircrafGun?.ChangeBorders(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
Draw(); Draw();
} }
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreareModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_antiAircrafGun = new DrawingUpdateAntiAircraftGun(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)));
SetData();
Draw();
}
} }
} }

View File

@ -60,4 +60,7 @@
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>79</value>
</metadata>
</root> </root>