diff --git a/Stormtrooper/Stormtrooper/Drawning.cs b/Stormtrooper/Stormtrooper/Drawning.cs index b854878..a5673b9 100644 --- a/Stormtrooper/Stormtrooper/Drawning.cs +++ b/Stormtrooper/Stormtrooper/Drawning.cs @@ -14,15 +14,15 @@ namespace Stormtrooper /// internal class Drawning { - public EntityStormtrooper Storm { get; private set; } + public EntityStormtrooper Storm { get; protected set; } /// /// Левая координата отрисовки самолёта /// - private float _startPosX; + protected float _startPosX; /// /// Нижняя кооридната отрисовки самолёта /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -50,6 +50,20 @@ namespace Stormtrooper Storm = new EntityStormtrooper(speed, weight, bodyColor); } /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолёта + /// Цвет кузова + /// Ширина отрисовки самолёта + /// Высота отрисовки самолёта + protected Drawning(int speed, float weight, Color bodyColor, int stormWidth, int stormHeight) : + this(speed, weight, bodyColor) + { + _StormWidth = stormWidth; + _StormHeight = stormHeight; + } + /// /// Установка позиции самолёта /// /// Координата X @@ -116,7 +130,7 @@ namespace Stormtrooper /// Отрисовка штурмовика /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) @@ -194,5 +208,13 @@ namespace Stormtrooper _startPosY = _pictureHeight.Value - _StormHeight; } } + /// + /// Получение текущей позиции объекта + /// + /// + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _StormWidth, _startPosY + _StormHeight); + } } } diff --git a/Stormtrooper/Stormtrooper/DrawningMilitary.cs b/Stormtrooper/Stormtrooper/DrawningMilitary.cs new file mode 100644 index 0000000..da40c2d --- /dev/null +++ b/Stormtrooper/Stormtrooper/DrawningMilitary.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class DrawningMilitary : Drawning + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолёта + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public DrawningMilitary(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool rocket, bool sportLine) : + base(speed, weight, bodyColor, 135, 100) + { + Storm = new EntityMilitaryStormtrooper(speed, weight, bodyColor, dopColor, bodyKit, rocket, sportLine); + } + public override void DrawTransport(Graphics g) + { + if (Storm is not EntityMilitaryStormtrooper militaryTrop) + { + return; + } + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(militaryTrop.DopColor); + + if (militaryTrop.BodyKit) + { + + g.DrawEllipse(pen, _startPosX - 2, _startPosY - 70, 5, 20); + g.DrawEllipse(pen, _startPosX - 2, _startPosY - 50, 5, 20); + + g.FillEllipse(dopBrush, _startPosX - 2, _startPosY - 70, 5, 20); + g.FillEllipse(dopBrush, _startPosX - 2, _startPosY - 50, 5, 20); + } + + _startPosX += 2; + base.DrawTransport(g); + _startPosX -= 2; + + if (militaryTrop.Rocket) + { + g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 70, 40, 3); + g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 90, 40, 3); + g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 30, 40, 3); + g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 10, 40, 3); + } + + if (militaryTrop.SportLine) + { + g.FillRectangle(dopBrush, _startPosX + 30, _startPosY - 60, 8, 20); + g.FillRectangle(dopBrush, _startPosX + 100, _startPosY - 60, 8, 20); + } + + } + } +} diff --git a/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs b/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs new file mode 100644 index 0000000..859af1e --- /dev/null +++ b/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class DrawningObjectStorm : IDrawningObject + { + private Drawning _storm = null; + public DrawningObjectStorm(Drawning storm) + { + _storm = storm; + } + public float Step => _storm?.Storm?.Step ?? 0; + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _storm?.GetCurrentPosition() ?? default; + } + public void MoveObject(Direction direction) + { + _storm?.MoveTransport(direction); + } + public void SetObject(int x, int y, int width, int height) + { + _storm.SetPosition(x, y, width, height); + } + void IDrawningObject.DrawningObject(Graphics g) + { + _storm.DrawTransport(g); + } + + } +} diff --git a/Stormtrooper/Stormtrooper/EntityMilitaryStormtrooper.cs b/Stormtrooper/Stormtrooper/EntityMilitaryStormtrooper.cs new file mode 100644 index 0000000..e41946a --- /dev/null +++ b/Stormtrooper/Stormtrooper/EntityMilitaryStormtrooper.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class EntityMilitaryStormtrooper : EntityStormtrooper + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия обвеса + /// + public bool BodyKit { get; private set; } + /// + /// Признак наличия рокет + /// + public bool Rocket { get; private set; } + /// + /// Признак наличия полосы + /// + public bool SportLine { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолёта + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия рокет + /// Признак наличия гоночной полосы + public EntityMilitaryStormtrooper(int speed, float weight, Color bodyColor, Color + dopColor, bool bodyKit, bool rocket, bool sportLine) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + BodyKit = bodyKit; + Rocket = rocket; + SportLine = sportLine; + } + } +} diff --git a/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs b/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs index 0bc4963..661a1a1 100644 --- a/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs +++ b/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs @@ -38,6 +38,7 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxStormtrooper)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -147,11 +148,23 @@ this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreateModif.Location = new System.Drawing.Point(125, 396); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(120, 29); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // // FormStormtrooper // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(831, 461); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); @@ -181,5 +194,6 @@ private Button buttonLeft; private Button buttonDown; private Button buttonUp; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/FormStormtrooper.cs b/Stormtrooper/Stormtrooper/FormStormtrooper.cs index 0f56a4e..1479266 100644 --- a/Stormtrooper/Stormtrooper/FormStormtrooper.cs +++ b/Stormtrooper/Stormtrooper/FormStormtrooper.cs @@ -3,12 +3,11 @@ namespace Stormtrooper public partial class FormStormtrooper : Form { private Drawning _storm; - + public FormStormtrooper() { InitializeComponent(); } - //private EntityStormtrooper Storm; /// /// /// @@ -19,6 +18,18 @@ namespace Stormtrooper _storm?.DrawTransport(gr); pictureBoxStormtrooper.Image = bmp; } + + /// + /// + /// + private void SetData() + { + Random rnd = new(); + _storm.SetPosition(rnd.Next(0, 150), rnd.Next(0, 300), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); + toolStripStatusLabelSpeed.Text = $": {_storm.Storm.Speed}"; + toolStripStatusLabelWeight.Text = $": {_storm.Storm.Weight}"; + toolStripStatusLabelColor.Text = $": {_storm.Storm.BodyColor.Name}"; + } /// /// "" /// @@ -27,11 +38,8 @@ namespace Stormtrooper private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _storm = new Drawning(rnd.Next(100,300), rnd.Next(1000,2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _storm.SetPosition(rnd.Next(0, 150), rnd.Next(0, 300), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); - toolStripStatusLabelSpeed.Text = $": {_storm.Storm.Speed}"; - toolStripStatusLabelWeight.Text = $": {_storm.Storm.Weight}"; - toolStripStatusLabelColor.Text = $": {_storm.Storm.BodyColor.Name}"; + _storm = new Drawning(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(); Draw(); } /// @@ -70,5 +78,21 @@ namespace Stormtrooper _storm?.ChangeBorders(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); Draw(); } + + /// + /// "" + /// + /// + /// + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _storm = new DrawningMilitary(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(); + } } } \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/IDrawningObject.cs b/Stormtrooper/Stormtrooper/IDrawningObject.cs new file mode 100644 index 0000000..82df051 --- /dev/null +++ b/Stormtrooper/Stormtrooper/IDrawningObject.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + /// + /// Интерфейс для работы с объектом, прорисовываемым на форме + /// + internal interface IDrawningObject + { + /// + /// Шаг перемещения объекта + /// + public float Step { get; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + void SetObject(int x, int y, int width, int height); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + void MoveObject(Direction direction); + /// + /// Отрисовка объекта + /// + /// + void DrawningObject(Graphics g); + /// + /// Получение текущей позиции объекта + /// + /// + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + + } +}