diff --git a/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs b/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs index ae4784f..13ba0cd 100644 --- a/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs +++ b/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs @@ -12,15 +12,15 @@ namespace Stormtrooper /// /// Класс-сущность /// - public EntityMilitaryAirplane Airplane { get; private set; } + public EntityMilitaryAirplane Airplane { get; protected set; } /// /// Левая координата отрисовки автомобиля /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки автомобиля /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -32,15 +32,16 @@ namespace Stormtrooper /// /// Ширина отрисовки самолёта /// - private readonly int _airplaneWidth = 80; + protected readonly int _airplaneWidth; /// /// Высота отрисовки самолёта /// - private readonly int _airplaneHeight = 100; - public void Init(int speed, int weight) + protected readonly int _airplaneHeight; + public DrawningMilitaryAirplane(int speed, int weight, int wight = 80, int height = 100) { - Airplane = new EntityMilitaryAirplane(); - Airplane.Init(speed, weight); + Airplane = new EntityMilitaryAirplane(speed, weight); + _airplaneWidth = wight; + _airplaneHeight = height; } public void SetPosition(int x, int y, int width, int height) @@ -99,7 +100,7 @@ namespace Stormtrooper } } - public void DrawAirplane(Graphics g) + public virtual void DrawAirplane(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) @@ -109,23 +110,24 @@ namespace Stormtrooper Pen pen = new Pen(Color.Black); - Brush brush = new SolidBrush(Color.Black); + Brush brush = new SolidBrush(Color.DarkGreen); g.FillPolygon(brush, new PointF[3] {new PointF(_startPosX, _startPosY + _airplaneHeight / 2), new PointF(_startPosX + _airplaneWidth * 0.1f, _startPosY + _airplaneHeight * 0.45f), new PointF(_startPosX + _airplaneWidth * 0.1f, _startPosY + _airplaneHeight * 0.55f)}); - g.DrawPolygon(pen, new PointF[6] { new PointF(_startPosX + _airplaneWidth*0.45f,_startPosY), - new PointF(_startPosX + _airplaneWidth*0.50f,_startPosY), + g.FillPolygon(brush, new PointF[6] { new PointF(_startPosX + _airplaneWidth*0.45f,_startPosY), + new PointF(_startPosX + _airplaneWidth * 0.50f,_startPosY), new PointF(_startPosX + _airplaneWidth * 0.60f, _startPosY+_airplaneHeight*0.45f) , new PointF(_startPosX + _airplaneWidth * 0.60f, _startPosY+ _airplaneHeight*0.55f), new PointF(_startPosX + _airplaneWidth * 0.50f,_startPosY + _airplaneHeight), new PointF(_startPosX + _airplaneWidth * 0.45f,_startPosY + _airplaneHeight)}); - g.DrawPolygon(pen, new PointF[4] { + g.FillPolygon(brush, new PointF[4] { new PointF(_startPosX + _airplaneWidth, _startPosY + _airplaneHeight*0.20f), new PointF(_startPosX + _airplaneWidth*0.85f,_startPosY+_airplaneHeight*0.35f), new PointF(_startPosX + _airplaneWidth * 0.85f,_startPosY + _airplaneHeight*0.65f), new PointF(_startPosX + _airplaneWidth, _startPosY + _airplaneHeight*0.80f) }); - g.FillRectangle(new SolidBrush(Color.White), _startPosX + _airplaneWidth * 0.1f, _startPosY + _airplaneHeight * 0.45f, _airplaneWidth * 0.9f, _airplaneHeight * 0.1f); + g.FillRectangle(brush, _startPosX + _airplaneWidth * 0.1f, _startPosY + _airplaneHeight * 0.45f, _airplaneWidth * 0.9f, _airplaneHeight * 0.1f); + g.DrawRectangle(pen, _startPosX + _airplaneWidth * 0.1f, _startPosY + _airplaneHeight * 0.45f, _airplaneWidth * 0.9f, _airplaneHeight * 0.1f); } public void ChangeBorders(int width, int height) diff --git a/Stormtrooper/Stormtrooper/DrawningStormtrooper.cs b/Stormtrooper/Stormtrooper/DrawningStormtrooper.cs new file mode 100644 index 0000000..26f08dd --- /dev/null +++ b/Stormtrooper/Stormtrooper/DrawningStormtrooper.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class DrawningStormtrooper : DrawningMilitaryAirplane + { + public DrawningStormtrooper(int speed, int weight, int crew, Color advColor, bool rockets, bool boosters, bool radar) : base(speed, weight) + { + Airplane = new EntityStormtrooper(speed, weight,crew, advColor, rockets, boosters, radar); + } + public override void DrawAirplane(Graphics g) + { + + if (Airplane is not EntityStormtrooper stormtrooper) + { + return; + } + + Pen pen = new Pen(stormtrooper.AdvColor); + Brush brush = new SolidBrush(stormtrooper.AdvColor); + if (stormtrooper.Rockets) + { + g.FillEllipse(brush,_startPosX + _airplaneWidth * 0.3f,_startPosY + _airplaneHeight * 0.2f,_airplaneWidth * 0.3f,_airplaneHeight * 0.03f); + g.FillEllipse(brush,_startPosX + _airplaneWidth * 0.3f,_startPosY + _airplaneHeight * 0.3f, _airplaneWidth * 0.3f, _airplaneHeight * 0.03f); + g.FillEllipse(brush,_startPosX + _airplaneWidth * 0.3f,_startPosY + _airplaneHeight * 0.7f, _airplaneWidth * 0.3f, _airplaneHeight * 0.03f); + g.FillEllipse(brush,_startPosX + _airplaneWidth * 0.3f,_startPosY + _airplaneHeight * 0.8f, _airplaneWidth * 0.3f, _airplaneHeight * 0.03f); + + } + base.DrawAirplane(g); + + if (stormtrooper.Booster) + { + g.FillRectangle(brush, _startPosX + _airplaneWidth * 0.95f, _startPosY + _airplaneHeight * 0.35f, _airplaneWidth * 0.055f, _airplaneHeight * 0.03f); + g.FillRectangle(brush, _startPosX + _airplaneWidth * 0.95f, _startPosY + _airplaneHeight * 0.63f, _airplaneWidth * 0.055f, _airplaneHeight * 0.03f); + } + + if (stormtrooper.Radar) + { + g.FillEllipse(brush, _startPosX + _airplaneWidth * 0.1f, _startPosY + _airplaneHeight * 0.45f, _airplaneWidth*0.125f, _airplaneHeight * 0.1f); + } + + } + } +} diff --git a/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs b/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs index a5cd2f6..d7aa97e 100644 --- a/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs +++ b/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs @@ -14,7 +14,7 @@ namespace Stormtrooper public float Step => Speed * 25 / Weight; - public void Init(int speed, int weight, int crew = 10) + public EntityMilitaryAirplane(int speed, int weight, int crew = 10) { Random random = new Random(); Speed = speed <= 0 ? random.Next(10, 100) : speed; diff --git a/Stormtrooper/Stormtrooper/EntityStormtrooper.cs b/Stormtrooper/Stormtrooper/EntityStormtrooper.cs new file mode 100644 index 0000000..4907b8b --- /dev/null +++ b/Stormtrooper/Stormtrooper/EntityStormtrooper.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class EntityStormtrooper : EntityMilitaryAirplane + { + /// + /// Доп цвет + /// + public Color AdvColor { get;private set; } + /// + /// Наличие рокет + /// + public bool Rockets { get; private set; } + /// + /// Наличие ускорителей + /// + public bool Booster { get; private set; } + /// + /// Наличие радара + /// + public bool Radar { get; private set; } + + public EntityStormtrooper(int speed, int weight, int crew, Color advColor, bool rockets, bool boosters, bool radar) + : base(speed, weight, crew) + { + Rockets = rockets; + Booster = boosters; + Radar = radar; + AdvColor = advColor; + + } + + } +} diff --git a/Stormtrooper/Stormtrooper/MainForm.Designer.cs b/Stormtrooper/Stormtrooper/MainForm.Designer.cs index f1c0093..e8d1930 100644 --- a/Stormtrooper/Stormtrooper/MainForm.Designer.cs +++ b/Stormtrooper/Stormtrooper/MainForm.Designer.cs @@ -39,6 +39,7 @@ namespace Stormtrooper this.buttonDown = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); + this.buttonCreateMod = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit(); this.toolStripStatus.SuspendLayout(); this.SuspendLayout(); @@ -49,7 +50,8 @@ namespace Stormtrooper | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.pictureBoxAirplane.BackColor = System.Drawing.Color.White; - this.pictureBoxAirplane.Location = new System.Drawing.Point(12, 12); + this.pictureBoxAirplane.Location = new System.Drawing.Point(14, 14); + this.pictureBoxAirplane.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.pictureBoxAirplane.Name = "pictureBoxAirplane"; this.pictureBoxAirplane.Size = new System.Drawing.Size(1127, 558); this.pictureBoxAirplane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; @@ -61,9 +63,10 @@ namespace Stormtrooper // this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonCreate.Cursor = System.Windows.Forms.Cursors.Hand; - this.buttonCreate.Location = new System.Drawing.Point(27, 518); + this.buttonCreate.Location = new System.Drawing.Point(31, 598); + this.buttonCreate.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.Size = new System.Drawing.Size(88, 27); this.buttonCreate.TabIndex = 1; this.buttonCreate.Text = "Создать"; this.buttonCreate.UseVisualStyleBackColor = true; @@ -76,9 +79,9 @@ namespace Stormtrooper this.toolStripLabelSpeed, this.toolStripLabelWeight, this.toolStripLabelCrew}); - this.toolStripStatus.Location = new System.Drawing.Point(0, 584); + this.toolStripStatus.Location = new System.Drawing.Point(0, 678); this.toolStripStatus.Name = "toolStripStatus"; - this.toolStripStatus.Size = new System.Drawing.Size(1151, 25); + this.toolStripStatus.Size = new System.Drawing.Size(1343, 25); this.toolStripStatus.TabIndex = 2; this.toolStripStatus.Text = "toolStrip1"; // @@ -103,9 +106,10 @@ namespace Stormtrooper // buttonUp // this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.Location = new System.Drawing.Point(1031, 482); + this.buttonUp.Location = new System.Drawing.Point(1203, 556); + this.buttonUp.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.Size = new System.Drawing.Size(35, 35); this.buttonUp.TabIndex = 3; this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); @@ -113,9 +117,10 @@ namespace Stormtrooper // buttonDown // this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDown.Location = new System.Drawing.Point(1031, 518); + this.buttonDown.Location = new System.Drawing.Point(1203, 598); + this.buttonDown.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.Size = new System.Drawing.Size(35, 35); this.buttonDown.TabIndex = 4; this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); @@ -123,9 +128,10 @@ namespace Stormtrooper // buttonLeft // this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeft.Location = new System.Drawing.Point(995, 517); + this.buttonLeft.Location = new System.Drawing.Point(1161, 597); + this.buttonLeft.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.Size = new System.Drawing.Size(35, 35); this.buttonLeft.TabIndex = 5; this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click); @@ -133,18 +139,30 @@ namespace Stormtrooper // buttonRight // this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.Location = new System.Drawing.Point(1067, 517); + this.buttonRight.Location = new System.Drawing.Point(1245, 597); + this.buttonRight.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.Size = new System.Drawing.Size(35, 35); this.buttonRight.TabIndex = 6; this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); // + // buttonCreateMod + // + this.buttonCreateMod.Location = new System.Drawing.Point(162, 598); + this.buttonCreateMod.Name = "buttonCreateMod"; + this.buttonCreateMod.Size = new System.Drawing.Size(104, 27); + this.buttonCreateMod.TabIndex = 7; + this.buttonCreateMod.Text = "Модификация"; + this.buttonCreateMod.UseVisualStyleBackColor = true; + this.buttonCreateMod.Click += new System.EventHandler(this.buttonCreateMod_Click); + // // MainForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1151, 609); + this.ClientSize = new System.Drawing.Size(1343, 703); + this.Controls.Add(this.buttonCreateMod); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonDown); @@ -152,6 +170,7 @@ namespace Stormtrooper this.Controls.Add(this.toolStripStatus); this.Controls.Add(this.buttonCreate); this.Controls.Add(this.pictureBoxAirplane); + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.Name = "MainForm"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).EndInit(); @@ -174,6 +193,7 @@ namespace Stormtrooper private System.Windows.Forms.Button buttonDown; private System.Windows.Forms.Button buttonLeft; private System.Windows.Forms.Button buttonRight; + private Button buttonCreateMod; } } diff --git a/Stormtrooper/Stormtrooper/MainForm.cs b/Stormtrooper/Stormtrooper/MainForm.cs index 2e5d714..ee5ad95 100644 --- a/Stormtrooper/Stormtrooper/MainForm.cs +++ b/Stormtrooper/Stormtrooper/MainForm.cs @@ -29,12 +29,9 @@ namespace Stormtrooper private void buttonCreate_Click(object sender, EventArgs e) { Random random = new Random(); - _airplane = new DrawningMilitaryAirplane(); - _airplane.Init(10, 50); + _airplane = new DrawningMilitaryAirplane(10, 50); _airplane.SetPosition(random.Next(100,150), random.Next(100,150), pictureBoxAirplane.Width, pictureBoxAirplane.Height); - toolStripLabelSpeed.Text = $"Скорость: {_airplane.Airplane.Speed}"; - toolStripLabelWeight.Text = $"Вес: {_airplane.Airplane.Weight}"; - toolStripLabelCrew.Text = $"Экипаж: {_airplane.Airplane.Crew}"; + SetData(); Draw(); } @@ -65,5 +62,23 @@ namespace Stormtrooper } Draw(); } + private void SetData() + { + toolStripLabelSpeed.Text = $"Скорость: {_airplane.Airplane.Speed}"; + toolStripLabelWeight.Text = $"Вес: {_airplane.Airplane.Weight}"; + toolStripLabelCrew.Text = $"Экипаж: {_airplane.Airplane.Crew}"; + } + + private void buttonCreateMod_Click(object sender, EventArgs e) + { + + Random random = new Random(); + _airplane = new DrawningStormtrooper(random.Next(10,100),random.Next(50,250),random.Next(1,100), + Color.FromArgb(random.Next(0,256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0,2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + _airplane.SetPosition(random.Next(100, 150), random.Next(100, 150), pictureBoxAirplane.Width, pictureBoxAirplane.Height); + SetData(); + Draw(); + } } } diff --git a/Stormtrooper/Stormtrooper/MainForm.resx b/Stormtrooper/Stormtrooper/MainForm.resx index 66a7586..f799d08 100644 --- a/Stormtrooper/Stormtrooper/MainForm.resx +++ b/Stormtrooper/Stormtrooper/MainForm.resx @@ -1,64 +1,4 @@ - - - +