Kargin D.E. Lab Work 2 #2
@ -14,15 +14,15 @@ namespace AirFighter
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirFighter AirFighter { private set; get; }
|
||||
public EntityAirFighter AirFighter { protected set; get; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки самолета
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки самолета
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -49,6 +49,12 @@ namespace AirFighter
|
||||
{
|
||||
AirFighter = new EntityAirFighter(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawningAirFighter(int speed, float weight, Color bodyColor, int airFighterWight, int airFighterHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_airFighterWidth = airFighterWight;
|
||||
_airFighterHeight = airFighterHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции самолета
|
||||
/// </summary>
|
||||
@ -123,7 +129,7 @@ namespace AirFighter
|
||||
/// <summary>
|
||||
/// Отрисовка самолета
|
||||
/// </summary>
|
||||
public void DrawAirFighter(Graphics g)
|
||||
public virtual void DrawAirFighter(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
|
99
AirFighter/AirFighter/DrawningUpgradeAirFighter.cs
Normal file
99
AirFighter/AirFighter/DrawningUpgradeAirFighter.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class DrawningUpgradeAirFighter : DrawningAirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <param name="dopColor"></param>
|
||||
/// <param name="dopWing"></param>
|
||||
/// <param name="rocket"></param>
|
||||
public DrawningUpgradeAirFighter(int speed, float weight, Color bodyColor, Color dopColor, bool dopWing, bool rocket) :
|
||||
base(speed, weight, bodyColor, 85, 80)
|
||||
{
|
||||
AirFighter = new EntityUpgradeAirFighter(speed, weight, bodyColor, dopColor, dopWing, rocket);
|
||||
}
|
||||
public override void DrawAirFighter(Graphics g)
|
||||
{
|
||||
if(AirFighter is not EntityUpgradeAirFighter upgradeAirFighter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(upgradeAirFighter.DopColor);
|
||||
|
||||
_startPosX += 5;
|
||||
_startPosY += 5;
|
||||
base.DrawAirFighter(g);
|
||||
_startPosX -= 5;
|
||||
_startPosY -= 5;
|
||||
|
||||
if (upgradeAirFighter.DopWing)
|
||||
{
|
||||
PointF[] _pointBackWing =
|
||||
{
|
||||
new PointF(_startPosX, _startPosY + 35),
|
||||
new PointF(_startPosX, _startPosY + 45),
|
||||
new PointF(_startPosX + 10, _startPosY + 40)
|
||||
};
|
||||
PointF[] _pointLeftWing =
|
||||
{
|
||||
new PointF(_startPosX + 50, _startPosY + 35),
|
||||
new PointF(_startPosX + 55, _startPosY + 30),
|
||||
new PointF(_startPosX + 65, _startPosY + 35)
|
||||
};
|
||||
PointF[] _pointRightWing =
|
||||
{
|
||||
new PointF(_startPosX + 50, _startPosY + 45),
|
||||
new PointF(_startPosX + 55, _startPosY + 50),
|
||||
new PointF(_startPosX + 65, _startPosY + 45)
|
||||
};
|
||||
|
||||
g.FillPolygon(dopBrush, _pointBackWing);
|
||||
g.FillPolygon(dopBrush, _pointLeftWing);
|
||||
g.FillPolygon(dopBrush, _pointRightWing);
|
||||
|
||||
g.DrawPolygon(pen, _pointBackWing);
|
||||
g.DrawPolygon(pen, _pointLeftWing);
|
||||
g.DrawPolygon(pen, _pointRightWing);
|
||||
}
|
||||
|
||||
if (upgradeAirFighter.Rocket)
|
||||
{
|
||||
PointF[] _pointLeftRocket =
|
||||
{
|
||||
new PointF(_startPosX + 35, _startPosY),
|
||||
new PointF(_startPosX + 45, _startPosY),
|
||||
new PointF(_startPosX + 50, _startPosY + 3),
|
||||
new PointF(_startPosX + 45, _startPosY + 5),
|
||||
new PointF(_startPosX + 35, _startPosY + 5)
|
||||
};
|
||||
PointF[] _pointRightRocket =
|
||||
{
|
||||
new PointF(_startPosX + 35, _startPosY + 75),
|
||||
new PointF(_startPosX + 45, _startPosY + 75),
|
||||
new PointF(_startPosX + 50, _startPosY + 77),
|
||||
new PointF(_startPosX + 45, _startPosY + 80),
|
||||
new PointF(_startPosX + 35, _startPosY + 80)
|
||||
};
|
||||
|
||||
g.FillPolygon(dopBrush, _pointLeftRocket);
|
||||
g.FillPolygon(dopBrush, _pointRightRocket);
|
||||
|
||||
g.DrawPolygon(pen, _pointLeftRocket);
|
||||
g.DrawPolygon(pen, _pointRightRocket);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
43
AirFighter/AirFighter/EntityUpgradeAirFighter.cs
Normal file
43
AirFighter/AirFighter/EntityUpgradeAirFighter.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность самолет разведчик
|
||||
/// </summary>
|
||||
internal class EntityUpgradeAirFighter : EntityAirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия дополнительных крыльев
|
||||
/// </summary>
|
||||
public bool DopWing { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия ракет
|
||||
/// </summary>
|
||||
public bool Rocket { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <param name="dopColor"></param>
|
||||
/// <param name="dopWing"></param>
|
||||
/// <param name="rocket"></param>
|
||||
public EntityUpgradeAirFighter(int speed, float weight, Color bodyColor, Color dopColor, bool dopWing, bool rocket) :
|
||||
base(speed,weight,bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
DopWing = dopWing;
|
||||
Rocket = rocket;
|
||||
}
|
||||
}
|
||||
}
|
14
AirFighter/AirFighter/FormAirFighter.Designer.cs
generated
14
AirFighter/AirFighter/FormAirFighter.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonUpgrade = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -142,11 +143,23 @@
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUpgrade
|
||||
//
|
||||
this.buttonUpgrade.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonUpgrade.Location = new System.Drawing.Point(148, 379);
|
||||
this.buttonUpgrade.Name = "buttonUpgrade";
|
||||
this.buttonUpgrade.Size = new System.Drawing.Size(127, 29);
|
||||
this.buttonUpgrade.TabIndex = 7;
|
||||
this.buttonUpgrade.Text = "Модификация";
|
||||
this.buttonUpgrade.UseVisualStyleBackColor = true;
|
||||
this.buttonUpgrade.Click += new System.EventHandler(this.ButtonUpgrade_Click);
|
||||
//
|
||||
// FormAirFighter
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonUpgrade);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
@ -176,5 +189,6 @@
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonUpgrade;
|
||||
}
|
||||
}
|
@ -18,6 +18,17 @@ namespace AirFighter
|
||||
pictureBoxAirFighter.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter?.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter?.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airFighter.AirFighter?.BodyColor}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
@ -26,10 +37,7 @@ namespace AirFighter
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_airFighter = new DrawningAirFighter(rnd.Next(200, 500), rnd.Next(2000, 5000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter?.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter?.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airFighter.AirFighter?.BodyColor}";
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -67,5 +75,18 @@ namespace AirFighter
|
||||
_airFighter?.ChangeBorders(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonUpgrade_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_airFighter = new DrawningUpgradeAirFighter(rnd.Next(300, 600), rnd.Next(2000, 5000), 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user