Merge pull request 'Khaliullov K.A. Lab Work 2' (#2) from LabWork02 into LabWork01

Reviewed-on: http://student.git.athene.tech/KamilH/ISEbd-21_Khaliullov_K_A_AntiAircraftGun_Base/pulls/2
This commit is contained in:
KamilH 2022-12-23 08:58:34 +04:00
commit 1c8543d016
7 changed files with 177 additions and 51 deletions

View File

@ -14,15 +14,15 @@ namespace AntiAircraftGun
/// <summary>
/// Класс-сущность
/// </summary>
public EntityAntiAircraftGun AntiAircraftGun { private set; get; }
public EntityAntiAircraftGun AntiAircraftGun { protected set; get; }
/// <summary>
/// Левая координата отрисовки зенитного орудия
/// </summary>
private float _startPosX;
protected float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки зенитного орудия
/// </summary>
private float _startPosY;
protected float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -45,10 +45,23 @@ namespace AntiAircraftGun
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес зенитного орудия</param>
/// <param name="bodyColor">Цвет корпуса</param>
public void Init(int speed, float weight, Color bodyColor)
public DrawingAntiAircraftGun(int speed, float weight, Color bodyColor)
{
AntiAircraftGun = new EntityAntiAircraftGun();
AntiAircraftGun.Init(speed, weight, bodyColor);
AntiAircraftGun = new EntityAntiAircraftGun(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 DrawingAntiAircraftGun(int speed, float weight, Color bodyColor, int antiAircrafGunWidth, int antiAircrafGunHeight) :
this(speed, weight, bodyColor)
{
_antiAircrafGunWidth = antiAircrafGunWidth;
_antiAircrafGunHeight = antiAircrafGunHeight;
}
/// <summary>
/// Установка позиции зенитного орудия
@ -113,7 +126,7 @@ namespace AntiAircraftGun
/// Отрисовка зенитного орудия
/// </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)
@ -130,7 +143,7 @@ namespace AntiAircraftGun
g.DrawEllipse(pen, _startPosX + 70, _startPosY + 20, 20, 20);
//катки в гусеницах
Brush brBlack = new SolidBrush(Color.Black);
g.FillEllipse(brBlack, _startPosX +1, _startPosY + 21, 18, 18);
g.FillEllipse(brBlack, _startPosX + 1, _startPosY + 21, 18, 18);
g.FillEllipse(brBlack, _startPosX + 71, _startPosY + 21, 18, 18);
g.FillEllipse(brBlack, _startPosX + 19, _startPosY + 30, 11, 11);
g.FillEllipse(brBlack, _startPosX + 58, _startPosY + 30, 11, 11);

View File

@ -0,0 +1,49 @@
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);
if (updateAntiAircraftGun.Gun)
{
g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 30, 25, 15);
g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 38, 50, 3);
}
if (updateAntiAircraftGun.Radar)
{
g.DrawLine(dopPen, _startPosX + 27, _startPosY + 37, _startPosX + 27, _startPosY + 20);
g.FillPie(dopBrush, _startPosX + 3, _startPosY, 30, 30, -45, 180);
}
_startPosY += 35;
base.DrawTransport(g);
_startPosY -= 35;
}
}
}

View File

@ -31,7 +31,7 @@ namespace AntiAircraftGun
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <returns></returns>
public void Init(int speed, float weight, Color bodyColor)
public EntityAntiAircraftGun(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;

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.buttonRight = 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();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@ -46,13 +47,11 @@
//
this.pictureBoxAntiAircraftGun.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxAntiAircraftGun.Location = new System.Drawing.Point(0, 0);
this.pictureBoxAntiAircraftGun.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pictureBoxAntiAircraftGun.Name = "pictureBoxAntiAircraftGun";
this.pictureBoxAntiAircraftGun.Size = new System.Drawing.Size(700, 316);
this.pictureBoxAntiAircraftGun.Size = new System.Drawing.Size(800, 425);
this.pictureBoxAntiAircraftGun.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxAntiAircraftGun.TabIndex = 0;
this.pictureBoxAntiAircraftGun.TabStop = false;
this.pictureBoxAntiAircraftGun.Click += new System.EventHandler(this.pictureBoxAntiAircraftGun_Click);
this.pictureBoxAntiAircraftGun.Resize += new System.EventHandler(this.PictureBoxAntiAircraftGun_Resize);
//
// statusStrip
@ -62,37 +61,35 @@
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip.Location = new System.Drawing.Point(0, 316);
this.statusStrip.Location = new System.Drawing.Point(0, 425);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0);
this.statusStrip.Size = new System.Drawing.Size(700, 22);
this.statusStrip.Size = new System.Drawing.Size(800, 26);
this.statusStrip.TabIndex = 1;
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(59, 17);
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(73, 20);
this.toolStripStatusLabelSpeed.Text = "Скорость";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(26, 17);
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(33, 20);
this.toolStripStatusLabelWeight.Text = "Вес";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(33, 17);
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(42, 20);
this.toolStripStatusLabelBodyColor.Text = "Цвет";
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(10, 286);
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreate.Location = new System.Drawing.Point(11, 381);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(82, 22);
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
@ -103,10 +100,9 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(634, 256);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUp.Location = new System.Drawing.Point(725, 341);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(26, 26);
this.buttonUp.Size = new System.Drawing.Size(30, 29);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
@ -116,10 +112,9 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(602, 284);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonLeft.Location = new System.Drawing.Point(688, 379);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(26, 26);
this.buttonLeft.Size = new System.Drawing.Size(30, 29);
this.buttonLeft.TabIndex = 4;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
@ -129,10 +124,9 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(665, 284);
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRight.Location = new System.Drawing.Point(760, 379);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(26, 26);
this.buttonRight.Size = new System.Drawing.Size(30, 29);
this.buttonRight.TabIndex = 5;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
@ -142,19 +136,30 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(634, 284);
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDown.Location = new System.Drawing.Point(725, 379);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(26, 26);
this.buttonDown.Size = new System.Drawing.Size(30, 29);
this.buttonDown.TabIndex = 6;
this.buttonDown.UseVisualStyleBackColor = true;
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(700, 338);
this.ClientSize = new System.Drawing.Size(800, 451);
this.Controls.Add(this.buttonCreareModif);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
@ -162,10 +167,9 @@
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxAntiAircraftGun);
this.Controls.Add(this.statusStrip);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.MinimumSize = new System.Drawing.Size(46, 70);
this.MinimumSize = new System.Drawing.Size(50, 80);
this.Name = "FormAntiAircraftGun";
this.Text = "Бронированная машина";
this.Text = "Зенитное орудие";
this.Click += new System.EventHandler(this.ButtonMove_Click);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).EndInit();
this.statusStrip.ResumeLayout(false);
@ -187,5 +191,6 @@
private Button buttonLeft;
private Button buttonRight;
private Button buttonDown;
private Button buttonCreareModif;
}
}

View File

@ -23,6 +23,17 @@ namespace AntiAircraftGun
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>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
@ -32,14 +43,9 @@ namespace AntiAircraftGun
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_antiAircrafGun = new DrawingAntiAircraftGun();
_antiAircrafGun.Init(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)));
_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}";
SetData();
Draw();
}
/// <summary>
@ -78,10 +84,20 @@ namespace AntiAircraftGun
_antiAircrafGun?.ChangeBorders(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
Draw();
}
private void pictureBoxAntiAircraftGun_Click(object sender, EventArgs e)
/// <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">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>79</value>
</metadata>
</root>