From b87e794963aead6d0813f0fee480094425495b39 Mon Sep 17 00:00:00 2001 From: ker73rus Date: Tue, 6 Sep 2022 11:26:35 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=96=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Stormtrooper/Stormtrooper/Direction.cs | 22 ++ .../Stormtrooper/DrawningMilitaryAirplane.cs | 178 ++++++++++++++ .../Stormtrooper/EntityMilitaryAirplane.cs | 27 ++ Stormtrooper/Stormtrooper/Form1.Designer.cs | 41 ---- Stormtrooper/Stormtrooper/Form1.cs | 20 -- .../Stormtrooper/MainForm.Designer.cs | 231 ++++++++++++++++++ Stormtrooper/Stormtrooper/MainForm.cs | 81 ++++++ Stormtrooper/Stormtrooper/MainForm.resx | 123 ++++++++++ Stormtrooper/Stormtrooper/Program.cs | 2 +- Stormtrooper/Stormtrooper/Stormtrooper.csproj | 12 +- 10 files changed, 672 insertions(+), 65 deletions(-) create mode 100644 Stormtrooper/Stormtrooper/Direction.cs create mode 100644 Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs create mode 100644 Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs delete mode 100644 Stormtrooper/Stormtrooper/Form1.Designer.cs delete mode 100644 Stormtrooper/Stormtrooper/Form1.cs create mode 100644 Stormtrooper/Stormtrooper/MainForm.Designer.cs create mode 100644 Stormtrooper/Stormtrooper/MainForm.cs create mode 100644 Stormtrooper/Stormtrooper/MainForm.resx diff --git a/Stormtrooper/Stormtrooper/Direction.cs b/Stormtrooper/Stormtrooper/Direction.cs new file mode 100644 index 0000000..f19b1d9 --- /dev/null +++ b/Stormtrooper/Stormtrooper/Direction.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal enum Direction + + { + Stop, + Up, + Down, + Left, + Right, + RightUp, + LeftUp, + RightDown, + LeftDown + } +} diff --git a/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs b/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs new file mode 100644 index 0000000..43e5610 --- /dev/null +++ b/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs @@ -0,0 +1,178 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class DrawningMilitaryAirplane + { + /// + /// Класс-сущность + /// + public EntityMilitaryAirplane Airplane { get; private set; } + /// + /// Левая координата отрисовки автомобиля + /// + private float _startPosX; + /// + /// Верхняя кооридната отрисовки автомобиля + /// + private float _startPosY; + /// + /// Ширина окна отрисовки + /// + private int? _pictureWidth = null; + /// + /// Высота окна отрисовки + /// + private int? _pictureHeight = null; + /// + /// Ширина отрисовки самолёта + /// + private readonly int _airplaneWidth = 80; + /// + /// Высота отрисовки самолёта + /// + private readonly int _airplaneHeight = 100; + public void Init(int speed, int weight) + { + Airplane = new EntityMilitaryAirplane(); + Airplane.Init(speed, weight); + } + + public void SetPosition(int x, int y, int width, int height) + { + if(width > _airplaneWidth && height > _airplaneHeight) + { + if (x < width - _airplaneWidth) + _startPosX = x < 0 ? 0 : x; + else _startPosX = width - _airplaneWidth; + if (y < height - _airplaneHeight) + _startPosY = y < 0 ? 0 : y; + else _startPosY = height - _airplaneHeight; + _pictureWidth = width; + _pictureHeight = height; + } + + } + + public void MoveAirplane(Direction direction) + { + if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) + { + return; + } + switch (direction) + { + // вправо + case Direction.Right: + if (_startPosX + _airplaneWidth + Airplane.Step < _pictureWidth) + { + _startPosX += Airplane.Step; + } + break; + //влево + case Direction.Left: + if (_startPosX - Airplane.Step > 0) + { + _startPosX -= Airplane.Step; + } + break; + //вверх + case Direction.Up: + if (_startPosY - Airplane.Step > 0) + { + _startPosY -= Airplane.Step; + } + break; + //вниз + case Direction.Down: + if (_startPosY + _airplaneHeight + Airplane.Step < _pictureHeight) + { + _startPosY += Airplane.Step; + } + break; + case Direction.RightUp: + if (_startPosX + _airplaneWidth + Airplane.Step < _pictureWidth && _startPosY - Airplane.Step > 0) + { + _startPosX += Airplane.Step; + _startPosY -= Airplane.Step; + } + break; + case Direction.RightDown: + if (_startPosY + _airplaneHeight + Airplane.Step < _pictureHeight && _startPosX + _airplaneWidth + Airplane.Step < _pictureWidth) + { + _startPosY += Airplane.Step; + _startPosX += Airplane.Step; + } + break; + case Direction.LeftUp: + if (_startPosX - Airplane.Step > 0 && _startPosY - Airplane.Step > 0) + { + _startPosX -= Airplane.Step; + _startPosY -= Airplane.Step; + } + break; + case Direction.LeftDown: + if (_startPosY + _airplaneHeight + Airplane.Step < _pictureHeight && _startPosX - Airplane.Step > 0) + { + _startPosY += Airplane.Step; + _startPosX -= Airplane.Step; + } + break; + } + } + + public void DrawAirplane(Graphics g) + { + if (_startPosX < 0 || _startPosY < 0 + || !_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + Pen pen = new Pen(Color.Black); + + + Brush brush = new SolidBrush(Color.Black); + 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), + 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] { + 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.DrawRectangle(pen, _startPosX + _airplaneWidth * 0.1f, _startPosY + _airplaneHeight * 0.45f, _airplaneWidth * 0.9f, _airplaneHeight * 0.1f); + } + public void ChangeBorders(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth <= _airplaneWidth || _pictureHeight <= _airplaneHeight) + { + _pictureWidth = null; + _pictureHeight = null; + return; + } + if (_startPosX + _airplaneWidth > _pictureWidth) + { + _startPosX = _pictureWidth.Value - _airplaneWidth; + } + if (_startPosY + _airplaneHeight > _pictureHeight) + { + _startPosY = _pictureHeight.Value - _airplaneHeight; + } + } + } +} diff --git a/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs b/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs new file mode 100644 index 0000000..a5cd2f6 --- /dev/null +++ b/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class EntityMilitaryAirplane + { + public int Speed { get; private set; } + public int Weight { get; private set; } + public int Crew { get; private set; } + + public float Step => Speed * 25 / Weight; + + public void Init(int speed, int weight, int crew = 10) + { + Random random = new Random(); + Speed = speed <= 0 ? random.Next(10, 100) : speed; + Weight = weight <= 0 ? random.Next(50, 150) : weight; + Crew = crew; + } + + + } +} diff --git a/Stormtrooper/Stormtrooper/Form1.Designer.cs b/Stormtrooper/Stormtrooper/Form1.Designer.cs deleted file mode 100644 index 18e8788..0000000 --- a/Stormtrooper/Stormtrooper/Form1.Designer.cs +++ /dev/null @@ -1,41 +0,0 @@ - -namespace Stormtrooper -{ - partial class Form1 - { - /// - /// Обязательная переменная конструктора. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Освободить все используемые ресурсы. - /// - /// истинно, если управляемый ресурс должен быть удален; иначе ложно. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Код, автоматически созданный конструктором форм Windows - - /// - /// Требуемый метод для поддержки конструктора — не изменяйте - /// содержимое этого метода с помощью редактора кода. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} - diff --git a/Stormtrooper/Stormtrooper/Form1.cs b/Stormtrooper/Stormtrooper/Form1.cs deleted file mode 100644 index b62cf58..0000000 --- a/Stormtrooper/Stormtrooper/Form1.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Stormtrooper -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/Stormtrooper/Stormtrooper/MainForm.Designer.cs b/Stormtrooper/Stormtrooper/MainForm.Designer.cs new file mode 100644 index 0000000..f81d9d6 --- /dev/null +++ b/Stormtrooper/Stormtrooper/MainForm.Designer.cs @@ -0,0 +1,231 @@ + +namespace Stormtrooper +{ + partial class MainForm + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором форм Windows + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.pictureBoxAirplane = new System.Windows.Forms.PictureBox(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.toolStripStatus = new System.Windows.Forms.ToolStrip(); + this.toolStripLabelSpeed = new System.Windows.Forms.ToolStripLabel(); + this.toolStripLabelWeight = new System.Windows.Forms.ToolStripLabel(); + this.toolStripLabelCrew = new System.Windows.Forms.ToolStripLabel(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeftDown = new System.Windows.Forms.Button(); + this.buttonLeftUp = new System.Windows.Forms.Button(); + this.buttonRightUp = new System.Windows.Forms.Button(); + this.buttonRightDown = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit(); + this.toolStripStatus.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxAirplane + // + this.pictureBoxAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | 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.Name = "pictureBoxAirplane"; + this.pictureBoxAirplane.Size = new System.Drawing.Size(1127, 558); + this.pictureBoxAirplane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxAirplane.TabIndex = 0; + this.pictureBoxAirplane.TabStop = false; + this.pictureBoxAirplane.Resize += new System.EventHandler(this.PictureBox_Resize); + // + // buttonCreate + // + 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.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 1; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // toolStripStatus + // + this.toolStripStatus.Dock = System.Windows.Forms.DockStyle.Bottom; + this.toolStripStatus.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripLabelSpeed, + this.toolStripLabelWeight, + this.toolStripLabelCrew}); + this.toolStripStatus.Location = new System.Drawing.Point(0, 584); + this.toolStripStatus.Name = "toolStripStatus"; + this.toolStripStatus.Size = new System.Drawing.Size(1151, 25); + this.toolStripStatus.TabIndex = 2; + this.toolStripStatus.Text = "toolStrip1"; + // + // toolStripLabelSpeed + // + this.toolStripLabelSpeed.Name = "toolStripLabelSpeed"; + this.toolStripLabelSpeed.Size = new System.Drawing.Size(86, 22); + this.toolStripLabelSpeed.Text = "toolStripLabel1"; + // + // toolStripLabelWeight + // + this.toolStripLabelWeight.Name = "toolStripLabelWeight"; + this.toolStripLabelWeight.Size = new System.Drawing.Size(86, 22); + this.toolStripLabelWeight.Text = "toolStripLabel2"; + // + // toolStripLabelCrew + // + this.toolStripLabelCrew.Name = "toolStripLabelCrew"; + this.toolStripLabelCrew.Size = new System.Drawing.Size(86, 22); + this.toolStripLabelCrew.Text = "toolStripLabel3"; + // + // 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, 447); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 3; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); + // + // 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.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 4; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); + // + // 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, 482); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 5; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click); + // + // 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, 482); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 6; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonLeftDown + // + this.buttonLeftDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeftDown.Location = new System.Drawing.Point(995, 518); + this.buttonLeftDown.Name = "buttonLeftDown"; + this.buttonLeftDown.Size = new System.Drawing.Size(30, 30); + this.buttonLeftDown.TabIndex = 7; + this.buttonLeftDown.UseVisualStyleBackColor = true; + this.buttonLeftDown.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonLeftUp + // + this.buttonLeftUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeftUp.Location = new System.Drawing.Point(995, 447); + this.buttonLeftUp.Name = "buttonLeftUp"; + this.buttonLeftUp.Size = new System.Drawing.Size(30, 30); + this.buttonLeftUp.TabIndex = 8; + this.buttonLeftUp.UseVisualStyleBackColor = true; + this.buttonLeftUp.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonRightUp + // + this.buttonRightUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRightUp.Location = new System.Drawing.Point(1067, 447); + this.buttonRightUp.Name = "buttonRightUp"; + this.buttonRightUp.Size = new System.Drawing.Size(30, 30); + this.buttonRightUp.TabIndex = 9; + this.buttonRightUp.UseVisualStyleBackColor = true; + this.buttonRightUp.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonRightDown + // + this.buttonRightDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRightDown.Location = new System.Drawing.Point(1067, 518); + this.buttonRightDown.Name = "buttonRightDown"; + this.buttonRightDown.Size = new System.Drawing.Size(30, 30); + this.buttonRightDown.TabIndex = 10; + this.buttonRightDown.UseVisualStyleBackColor = true; + this.buttonRightDown.Click += new System.EventHandler(this.buttonMove_Click); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1151, 609); + this.Controls.Add(this.buttonRightDown); + this.Controls.Add(this.buttonRightUp); + this.Controls.Add(this.buttonLeftUp); + this.Controls.Add(this.buttonLeftDown); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.toolStripStatus); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.pictureBoxAirplane); + this.Name = "MainForm"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).EndInit(); + this.toolStripStatus.ResumeLayout(false); + this.toolStripStatus.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.PictureBox pictureBoxAirplane; + private System.Windows.Forms.Button buttonCreate; + private System.Windows.Forms.ToolStrip toolStripStatus; + private System.Windows.Forms.ToolStripLabel toolStripLabelSpeed; + private System.Windows.Forms.ToolStripLabel toolStripLabelWeight; + private System.Windows.Forms.ToolStripLabel toolStripLabelCrew; + private System.Windows.Forms.Button buttonUp; + private System.Windows.Forms.Button buttonDown; + private System.Windows.Forms.Button buttonLeft; + private System.Windows.Forms.Button buttonRight; + private System.Windows.Forms.Button buttonLeftDown; + private System.Windows.Forms.Button buttonLeftUp; + private System.Windows.Forms.Button buttonRightUp; + private System.Windows.Forms.Button buttonRightDown; + } +} + diff --git a/Stormtrooper/Stormtrooper/MainForm.cs b/Stormtrooper/Stormtrooper/MainForm.cs new file mode 100644 index 0000000..370b01d --- /dev/null +++ b/Stormtrooper/Stormtrooper/MainForm.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Stormtrooper +{ + public partial class MainForm : Form + { + DrawningMilitaryAirplane _airplane; + public MainForm() + { + InitializeComponent(); + + Draw(); + } + private void Draw() + { + Bitmap bmp = new Bitmap (pictureBoxAirplane.Width, pictureBoxAirplane.Height); + Graphics gr = Graphics.FromImage(bmp); + _airplane?.DrawAirplane(gr); + pictureBoxAirplane.Image = bmp; + } + private void buttonCreate_Click(object sender, EventArgs e) + { + Random random = new Random(); + _airplane = new DrawningMilitaryAirplane(); + _airplane.Init(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}"; + Draw(); + } + + private void PictureBox_Resize(object sender, EventArgs e) + { + _airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height); + Draw(); + } + + private void buttonMove_Click(object sender,EventArgs e) + { + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _airplane?.MoveAirplane(Direction.Up); + break; + case "buttonDown": + _airplane?.MoveAirplane(Direction.Down); + break; + case "buttonLeft": + _airplane?.MoveAirplane(Direction.Left); + break; + case "buttonRight": + _airplane?.MoveAirplane(Direction.Right); + break; + case "buttonRightUp": + _airplane?.MoveAirplane(Direction.RightUp); + break; + case "buttonRightDown": + _airplane?.MoveAirplane(Direction.RightDown); + break; + case "buttonLeftUp": + _airplane?.MoveAirplane(Direction.LeftUp); + break; + case "buttonLeftDown": + _airplane?.MoveAirplane(Direction.RightDown); + break; + } + Draw(); + } + } +} diff --git a/Stormtrooper/Stormtrooper/MainForm.resx b/Stormtrooper/Stormtrooper/MainForm.resx new file mode 100644 index 0000000..66a7586 --- /dev/null +++ b/Stormtrooper/Stormtrooper/MainForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/Program.cs b/Stormtrooper/Stormtrooper/Program.cs index eb4a256..2637065 100644 --- a/Stormtrooper/Stormtrooper/Program.cs +++ b/Stormtrooper/Stormtrooper/Program.cs @@ -16,7 +16,7 @@ namespace Stormtrooper { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + Application.Run(new MainForm()); } } } diff --git a/Stormtrooper/Stormtrooper/Stormtrooper.csproj b/Stormtrooper/Stormtrooper/Stormtrooper.csproj index 2b9b6d5..b50bcce 100644 --- a/Stormtrooper/Stormtrooper/Stormtrooper.csproj +++ b/Stormtrooper/Stormtrooper/Stormtrooper.csproj @@ -46,14 +46,20 @@ - + + + + Form - - Form1.cs + + MainForm.cs + + MainForm.cs + ResXFileCodeGenerator Resources.Designer.cs From 60fa12ffbfec7ced97880df6e4268f108d4bda35 Mon Sep 17 00:00:00 2001 From: ker73rus Date: Tue, 20 Sep 2022 09:10:37 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BE=D0=BF=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Stormtrooper/Stormtrooper/Direction.cs | 7 +-- .../Stormtrooper/DrawningMilitaryAirplane.cs | 29 +--------- .../Stormtrooper/MainForm.Designer.cs | 58 +------------------ Stormtrooper/Stormtrooper/MainForm.cs | 12 ---- 4 files changed, 5 insertions(+), 101 deletions(-) diff --git a/Stormtrooper/Stormtrooper/Direction.cs b/Stormtrooper/Stormtrooper/Direction.cs index f19b1d9..bc5cbbe 100644 --- a/Stormtrooper/Stormtrooper/Direction.cs +++ b/Stormtrooper/Stormtrooper/Direction.cs @@ -9,14 +9,9 @@ namespace Stormtrooper internal enum Direction { - Stop, Up, Down, Left, - Right, - RightUp, - LeftUp, - RightDown, - LeftDown + Right } } diff --git a/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs b/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs index 43e5610..ae4784f 100644 --- a/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs +++ b/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs @@ -95,34 +95,7 @@ namespace Stormtrooper _startPosY += Airplane.Step; } break; - case Direction.RightUp: - if (_startPosX + _airplaneWidth + Airplane.Step < _pictureWidth && _startPosY - Airplane.Step > 0) - { - _startPosX += Airplane.Step; - _startPosY -= Airplane.Step; - } - break; - case Direction.RightDown: - if (_startPosY + _airplaneHeight + Airplane.Step < _pictureHeight && _startPosX + _airplaneWidth + Airplane.Step < _pictureWidth) - { - _startPosY += Airplane.Step; - _startPosX += Airplane.Step; - } - break; - case Direction.LeftUp: - if (_startPosX - Airplane.Step > 0 && _startPosY - Airplane.Step > 0) - { - _startPosX -= Airplane.Step; - _startPosY -= Airplane.Step; - } - break; - case Direction.LeftDown: - if (_startPosY + _airplaneHeight + Airplane.Step < _pictureHeight && _startPosX - Airplane.Step > 0) - { - _startPosY += Airplane.Step; - _startPosX -= Airplane.Step; - } - break; + } } diff --git a/Stormtrooper/Stormtrooper/MainForm.Designer.cs b/Stormtrooper/Stormtrooper/MainForm.Designer.cs index f81d9d6..f1c0093 100644 --- a/Stormtrooper/Stormtrooper/MainForm.Designer.cs +++ b/Stormtrooper/Stormtrooper/MainForm.Designer.cs @@ -39,10 +39,6 @@ namespace Stormtrooper this.buttonDown = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); - this.buttonLeftDown = new System.Windows.Forms.Button(); - this.buttonLeftUp = new System.Windows.Forms.Button(); - this.buttonRightUp = new System.Windows.Forms.Button(); - this.buttonRightDown = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit(); this.toolStripStatus.SuspendLayout(); this.SuspendLayout(); @@ -107,7 +103,7 @@ 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, 447); + this.buttonUp.Location = new System.Drawing.Point(1031, 482); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 3; @@ -127,7 +123,7 @@ 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, 482); + this.buttonLeft.Location = new System.Drawing.Point(995, 517); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 5; @@ -137,62 +133,18 @@ 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, 482); + this.buttonRight.Location = new System.Drawing.Point(1067, 517); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 6; this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); // - // buttonLeftDown - // - this.buttonLeftDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeftDown.Location = new System.Drawing.Point(995, 518); - this.buttonLeftDown.Name = "buttonLeftDown"; - this.buttonLeftDown.Size = new System.Drawing.Size(30, 30); - this.buttonLeftDown.TabIndex = 7; - this.buttonLeftDown.UseVisualStyleBackColor = true; - this.buttonLeftDown.Click += new System.EventHandler(this.buttonMove_Click); - // - // buttonLeftUp - // - this.buttonLeftUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeftUp.Location = new System.Drawing.Point(995, 447); - this.buttonLeftUp.Name = "buttonLeftUp"; - this.buttonLeftUp.Size = new System.Drawing.Size(30, 30); - this.buttonLeftUp.TabIndex = 8; - this.buttonLeftUp.UseVisualStyleBackColor = true; - this.buttonLeftUp.Click += new System.EventHandler(this.buttonMove_Click); - // - // buttonRightUp - // - this.buttonRightUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRightUp.Location = new System.Drawing.Point(1067, 447); - this.buttonRightUp.Name = "buttonRightUp"; - this.buttonRightUp.Size = new System.Drawing.Size(30, 30); - this.buttonRightUp.TabIndex = 9; - this.buttonRightUp.UseVisualStyleBackColor = true; - this.buttonRightUp.Click += new System.EventHandler(this.buttonMove_Click); - // - // buttonRightDown - // - this.buttonRightDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRightDown.Location = new System.Drawing.Point(1067, 518); - this.buttonRightDown.Name = "buttonRightDown"; - this.buttonRightDown.Size = new System.Drawing.Size(30, 30); - this.buttonRightDown.TabIndex = 10; - this.buttonRightDown.UseVisualStyleBackColor = true; - this.buttonRightDown.Click += new System.EventHandler(this.buttonMove_Click); - // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1151, 609); - this.Controls.Add(this.buttonRightDown); - this.Controls.Add(this.buttonRightUp); - this.Controls.Add(this.buttonLeftUp); - this.Controls.Add(this.buttonLeftDown); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonDown); @@ -222,10 +174,6 @@ namespace Stormtrooper private System.Windows.Forms.Button buttonDown; private System.Windows.Forms.Button buttonLeft; private System.Windows.Forms.Button buttonRight; - private System.Windows.Forms.Button buttonLeftDown; - private System.Windows.Forms.Button buttonLeftUp; - private System.Windows.Forms.Button buttonRightUp; - private System.Windows.Forms.Button buttonRightDown; } } diff --git a/Stormtrooper/Stormtrooper/MainForm.cs b/Stormtrooper/Stormtrooper/MainForm.cs index 370b01d..2e5d714 100644 --- a/Stormtrooper/Stormtrooper/MainForm.cs +++ b/Stormtrooper/Stormtrooper/MainForm.cs @@ -62,18 +62,6 @@ namespace Stormtrooper case "buttonRight": _airplane?.MoveAirplane(Direction.Right); break; - case "buttonRightUp": - _airplane?.MoveAirplane(Direction.RightUp); - break; - case "buttonRightDown": - _airplane?.MoveAirplane(Direction.RightDown); - break; - case "buttonLeftUp": - _airplane?.MoveAirplane(Direction.LeftUp); - break; - case "buttonLeftDown": - _airplane?.MoveAirplane(Direction.RightDown); - break; } Draw(); }