diff --git a/ProjectAirFighter/ProjectAirFighter/DirectionType.cs b/ProjectAirFighter/ProjectAirFighter/Drawning/DirectionType.cs similarity index 90% rename from ProjectAirFighter/ProjectAirFighter/DirectionType.cs rename to ProjectAirFighter/ProjectAirFighter/Drawning/DirectionType.cs index 871d9d7..6b9ffd1 100644 --- a/ProjectAirFighter/ProjectAirFighter/DirectionType.cs +++ b/ProjectAirFighter/ProjectAirFighter/Drawning/DirectionType.cs @@ -1,4 +1,4 @@ -namespace ProjectAirFighter; +namespace ProjectAirFighter.Drawning; /// /// Направление перемещения /// diff --git a/ProjectAirFighter/ProjectAirFighter/Drawning/DrawningAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/Drawning/DrawningAirFighter.cs new file mode 100644 index 0000000..16e0689 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/Drawning/DrawningAirFighter.cs @@ -0,0 +1,78 @@ +using System.Net.NetworkInformation; +using System.Net.Sockets; +using ProjectAirFighter.Entities; + +namespace ProjectAirFighter.Drawning; + +/// +/// класс отвечающий за прорисовку и перемещение объекта-сущности +/// +public class DrawningAirFighter : DrawningWarPlane +{ + + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия корпуса + /// Признак наличия рокет + /// Признак наличия дополнительных крыльев + //public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing) + public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing) : base(120,140) + { + EntityWarPlane = new EntityAirFighter(speed, weight, bodyColor, additionalColor, rocket, additionalWing); + + + } + + public override void DrawTransport(Graphics g) + { + if (EntityWarPlane == null || EntityWarPlane is not EntityAirFighter warPlane||!_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + Pen pen = new(Color.Black, 3); + Pen pen_rocket = new(Color.Black); + + Brush brAdd = new SolidBrush(warPlane.AdditionalColor); + + //ракеты + if (warPlane.Rocket) + { + Point[] FirstRocket = { new Point(_startPosX.Value + 55, _startPosY.Value + 110), new Point(_startPosX.Value + 95, _startPosY.Value + 110), + new Point(_startPosX.Value + 105, _startPosY.Value + 115),new Point(_startPosX.Value + 95, _startPosY.Value + 120), + new Point(_startPosX.Value + 55, _startPosY.Value + 120) }; + g.DrawPolygon(pen_rocket, FirstRocket); + Point[] SecondRocket = { new Point(_startPosX.Value + 55, _startPosY.Value + 30), new Point(_startPosX.Value + 95, _startPosY.Value + 30), + new Point(_startPosX.Value + 105, _startPosY.Value + 35),new Point(_startPosX.Value + 95, _startPosY.Value + 40), + new Point(_startPosX.Value + 55, _startPosY.Value + 40) }; + g.DrawPolygon(pen_rocket, SecondRocket); + + g.FillPolygon(brAdd, FirstRocket); + g.FillPolygon(brAdd, SecondRocket); + } + base.DrawTransport(g); + if (warPlane.AdditionalWing) + { + Point[] AddWingLower = { new Point(_startPosX.Value + 60, _startPosY.Value + 80), + new Point(_startPosX.Value + 60, _startPosY.Value + 140), new Point(_startPosX.Value + 50, _startPosY.Value + 140), + new Point(_startPosX.Value + 40, _startPosY.Value + 80) }; + g.DrawPolygon(pen, AddWingLower); + + Point[] AddWingUpper = { new Point(_startPosX.Value + 60, _startPosY.Value + 60), new Point(_startPosX.Value + 60, _startPosY.Value), + new Point(_startPosX.Value + 50, _startPosY.Value), new Point(_startPosX.Value + 40, _startPosY.Value + 60) }; + g.DrawPolygon(pen, AddWingUpper); + + g.FillPolygon(brAdd, AddWingUpper); + g.FillPolygon(brAdd, AddWingLower); + } + + } + + + + +} diff --git a/ProjectAirFighter/ProjectAirFighter/DrawningAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/Drawning/DrawningWarPlane.cs similarity index 52% rename from ProjectAirFighter/ProjectAirFighter/DrawningAirFighter.cs rename to ProjectAirFighter/ProjectAirFighter/Drawning/DrawningWarPlane.cs index 073191e..4b81258 100644 --- a/ProjectAirFighter/ProjectAirFighter/DrawningAirFighter.cs +++ b/ProjectAirFighter/ProjectAirFighter/Drawning/DrawningWarPlane.cs @@ -1,17 +1,18 @@ -using System.Net.NetworkInformation; +using ProjectAirFighter.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace ProjectAirFighter; +namespace ProjectAirFighter.Drawning; -/// -/// класс отвечающий за прорисовку и перемещение объекта-сущности -/// -public class DrawningAirFighter +public class DrawningWarPlane { - /// /// Класс-сущность /// - public EntityAirFighter? EntityAirFighter { get; private set; } + public EntityWarPlane? EntityWarPlane { get; protected set; } /// /// Ширина окна @@ -24,46 +25,54 @@ public class DrawningAirFighter private int? _pictureHeight; /// - /// Левая координата прорисовки истребителя + /// Левая координата прорисовки самолета /// - private int? _startPosX; + protected int? _startPosX; /// - /// Верхняя координата прорисовки истребителя + /// Верхняя координата прорисовки самолета /// - private int? _startPosY; + protected int? _startPosY; /// - /// Ширина прорисовки истребителя + /// Ширина прорисовки самолета /// - private int? _drawningAirFlighterWidth = 120; + private int? _drawningWarPlaneWidth = 120; /// - /// Высота прорисовки истребителя + /// Высота прорисовки самолета /// - private int? _drawningAirFlighterHeight = 140; + private int? _drawningWarPlaneHeight = 140; - /// - /// Иницифлизация полей объекта-класса истребителя - /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия корпуса - /// Признак наличия рокет - /// Признак наличия дополнительных крыльев - //public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing) - public void Init(EntityAirFighter entityAirFighter) - { - EntityAirFighter = entityAirFighter; - //EntityAirFighter.Init(speed, weight, bodyColor, additionalColor, rocket, additionalWing); + private DrawningWarPlane() { _pictureHeight = null; _pictureWidth = null; _startPosX = null; _startPosY = null; } - + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + public DrawningWarPlane(int speed, double weight, Color bodyColor) : this() + { + EntityWarPlane = new EntityWarPlane(speed, weight, bodyColor); + + } + /// + /// Конструктор для наслдеников + /// + /// Высота прорисовки самолета + /// Ширина прорисовки самолета + public DrawningWarPlane(int drawningWarPlaneWidth,int drawningWarPlaneHeight) : this() + { + _drawningWarPlaneWidth = drawningWarPlaneWidth; + _drawningWarPlaneHeight = drawningWarPlaneHeight; + + } + /// /// Установка границ поля @@ -73,7 +82,7 @@ public class DrawningAirFighter /// public bool SetPictureSize(int width, int height) { - if (width > _drawningAirFlighterWidth && height > _drawningAirFlighterHeight) + if (width > _drawningWarPlaneWidth && height > _drawningWarPlaneHeight) { _pictureWidth = width; _pictureHeight = height; @@ -87,13 +96,13 @@ public class DrawningAirFighter { _startPosY = 0; } - if (_startPosX.Value + _drawningAirFlighterWidth > _pictureWidth) + if (_startPosX.Value + _drawningWarPlaneWidth > _pictureWidth) { - _startPosX = _pictureWidth - _drawningAirFlighterWidth; + _startPosX = _pictureWidth - _drawningWarPlaneWidth; } - if (_startPosY.Value + _drawningAirFlighterHeight > _pictureHeight) + if (_startPosY.Value + _drawningWarPlaneHeight > _pictureHeight) { - _startPosY = _pictureHeight - _drawningAirFlighterHeight; + _startPosY = _pictureHeight - _drawningWarPlaneHeight; } } @@ -108,7 +117,7 @@ public class DrawningAirFighter /// /// Координата X /// Координата Y - public void SetPosition(int x, int y) + public void SetPosition(int x, int y) { if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) { @@ -126,13 +135,13 @@ public class DrawningAirFighter { _startPosY = 0; } - if (_startPosX + _drawningAirFlighterWidth > _pictureWidth) + if (_startPosX + _drawningWarPlaneWidth > _pictureWidth) { - _startPosX = _pictureWidth - _drawningAirFlighterWidth; + _startPosX = _pictureWidth - _drawningWarPlaneWidth; } - if (_startPosY + _drawningAirFlighterHeight > _pictureHeight) + if (_startPosY + _drawningWarPlaneHeight > _pictureHeight) { - _startPosY = _pictureHeight - _drawningAirFlighterHeight; + _startPosY = _pictureHeight - _drawningWarPlaneHeight; } } @@ -148,7 +157,7 @@ public class DrawningAirFighter /// true - перемещение выполнено, false - перемещение невозможно public bool MoveTransport(DirectionType direction) { - if (EntityAirFighter == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } @@ -156,30 +165,30 @@ public class DrawningAirFighter { //влево case DirectionType.Left: - if (_startPosX.Value - EntityAirFighter.Step > 0) + if (_startPosX.Value - EntityWarPlane.Step > 0) { - _startPosX -= (int)EntityAirFighter.Step; + _startPosX -= (int)EntityWarPlane.Step; } return true; //вверх case DirectionType.Up: - if (_startPosY.Value - EntityAirFighter.Step > 0) + if (_startPosY.Value - EntityWarPlane.Step > 0) { - _startPosY -= (int)EntityAirFighter.Step; + _startPosY -= (int)EntityWarPlane.Step; } return true; //вниз case DirectionType.Down: - if (_startPosY.Value + EntityAirFighter.Step + _drawningAirFlighterHeight < _pictureHeight) + if (_startPosY.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureHeight) { - _startPosY += (int)EntityAirFighter.Step; + _startPosY += (int)EntityWarPlane.Step; } return true; //вправо case DirectionType.Right: - if (_startPosX.Value + EntityAirFighter.Step + _drawningAirFlighterWidth < _pictureWidth) + if (_startPosX.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureWidth) { - _startPosX += (int)EntityAirFighter.Step; + _startPosX += (int)EntityWarPlane.Step; } return true; default: @@ -187,37 +196,19 @@ public class DrawningAirFighter } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { - if (EntityAirFighter == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } - Pen pen = new(Color.Black,3); + Pen pen = new(Color.Black, 3); Pen pen_rocket = new(Color.Black); - - Brush brAdd = new SolidBrush(EntityAirFighter.AdditionalColor); - - //ракеты - if (EntityAirFighter.Rocket) - { - Point[] FirstRocket = { new Point(_startPosX.Value + 55, _startPosY.Value + 110), new Point(_startPosX.Value + 95, _startPosY.Value + 110), - new Point(_startPosX.Value + 105, _startPosY.Value + 115),new Point(_startPosX.Value + 95, _startPosY.Value + 120), - new Point(_startPosX.Value + 55, _startPosY.Value + 120) }; - g.DrawPolygon(pen_rocket, FirstRocket); - Point[] SecondRocket = { new Point(_startPosX.Value + 55, _startPosY.Value + 30), new Point(_startPosX.Value + 95, _startPosY.Value + 30), - new Point(_startPosX.Value + 105, _startPosY.Value + 35),new Point(_startPosX.Value + 95, _startPosY.Value + 40), - new Point(_startPosX.Value + 55, _startPosY.Value + 40) }; - g.DrawPolygon(pen_rocket, SecondRocket); - - g.FillPolygon(brAdd, FirstRocket); - g.FillPolygon(brAdd, SecondRocket); - } //корпус g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 60, 100, 20); - Point[] body = { new Point(_startPosX.Value + 100, _startPosY.Value + 80), + Point[] body = { new Point(_startPosX.Value + 100, _startPosY.Value + 80), new Point(_startPosX.Value + 120, _startPosY.Value + 70), new Point(_startPosX.Value + 100, _startPosY.Value + 60) }; g.DrawPolygon(pen, body); //нижнее крыло @@ -226,7 +217,7 @@ public class DrawningAirFighter new Point(_startPosX.Value + 60, _startPosY.Value + 80) }; g.DrawPolygon(pen, wingUpper); //верхнее крыло - Point[] wingLower = { new Point(_startPosX.Value + 80, _startPosY.Value + 60), new Point(_startPosX.Value + 80, _startPosY.Value), + Point[] wingLower = { new Point(_startPosX.Value + 80, _startPosY.Value + 60), new Point(_startPosX.Value + 80, _startPosY.Value), new Point(_startPosX.Value + 70, _startPosY.Value), new Point(_startPosX.Value + 60, _startPosY.Value + 60) }; g.DrawPolygon(pen, wingLower); //задние крылья @@ -239,33 +230,20 @@ public class DrawningAirFighter new Point(_startPosX.Value, _startPosY.Value + 110),new Point(_startPosX.Value + 25, _startPosY.Value + 90), new Point(_startPosX.Value + 25, _startPosY.Value + 80) }; g.DrawPolygon(pen, rearWingLower); - + //залив носа Brush brBlack = new SolidBrush(Color.Black); g.FillPolygon(brBlack, body); //залив корпуса - Brush br = new SolidBrush(EntityAirFighter.BodyColor); + Brush br = new SolidBrush(EntityWarPlane.BodyColor); g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 60, 100, 20); - + g.FillPolygon(br, wingLower); g.FillPolygon(br, wingUpper); g.FillPolygon(br, rearWingUpper); g.FillPolygon(br, rearWingLower); - if (EntityAirFighter.AdditionalWing) - { - Point[] AddWingLower = { new Point(_startPosX.Value + 60, _startPosY.Value + 80), - new Point(_startPosX.Value + 60, _startPosY.Value + 140), new Point(_startPosX.Value + 50, _startPosY.Value + 140), - new Point(_startPosX.Value + 40, _startPosY.Value + 80) }; - g.DrawPolygon(pen, AddWingLower); - - Point[] AddWingUpper = { new Point(_startPosX.Value + 60, _startPosY.Value + 60), new Point(_startPosX.Value + 60, _startPosY.Value), - new Point(_startPosX.Value + 50, _startPosY.Value), new Point(_startPosX.Value + 40, _startPosY.Value + 60) }; - g.DrawPolygon(pen, AddWingUpper); - - g.FillPolygon(brAdd, AddWingUpper); - g.FillPolygon(brAdd, AddWingLower); - } - } + + } } diff --git a/ProjectAirFighter/ProjectAirFighter/EntityAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/Entities/EntityAirFighter.cs similarity index 86% rename from ProjectAirFighter/ProjectAirFighter/EntityAirFighter.cs rename to ProjectAirFighter/ProjectAirFighter/Entities/EntityAirFighter.cs index 4869273..c6984d2 100644 --- a/ProjectAirFighter/ProjectAirFighter/EntityAirFighter.cs +++ b/ProjectAirFighter/ProjectAirFighter/Entities/EntityAirFighter.cs @@ -1,8 +1,8 @@ -namespace ProjectAirFighter; +namespace ProjectAirFighter.Entities; /// /// Класс-сущность "Истребитель" /// -public class EntityAirFighter +public class EntityAirFighter : EntityWarPlane { /// /// Скорость @@ -48,11 +48,9 @@ public class EntityAirFighter /// Дополнительный цвет /// Признак наличия рокет /// Признак наличия дополнительных крыльев - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing) + public EntityAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing) :base(speed, weight, bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; + AdditionalColor = additionalColor; Rocket = rocket; AdditionalWing = additionalWing; @@ -60,4 +58,4 @@ public class EntityAirFighter } } - + diff --git a/ProjectAirFighter/ProjectAirFighter/Entities/EntityWarPlane.cs b/ProjectAirFighter/ProjectAirFighter/Entities/EntityWarPlane.cs new file mode 100644 index 0000000..d62fb0d --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/Entities/EntityWarPlane.cs @@ -0,0 +1,43 @@ +namespace ProjectAirFighter.Entities; +/// +/// Класс-сущность "Военный самолет" +/// + +public class EntityWarPlane +{ + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weight { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Шаг + /// + public double Step => Speed * 100 / Weight; + + /// + /// Конструктор сущности + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия рокет + /// Признак наличия дополнительных крыльев + public EntityWarPlane(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } +} diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs index 4b6b0f1..302d5af 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.Designer.cs @@ -34,6 +34,7 @@ buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); + buttonCreateWarPlane = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).BeginInit(); SuspendLayout(); // @@ -41,22 +42,19 @@ // pictureBoxAirFighter.Dock = DockStyle.Fill; pictureBoxAirFighter.Location = new Point(0, 0); - pictureBoxAirFighter.Margin = new Padding(3, 4, 3, 4); pictureBoxAirFighter.Name = "pictureBoxAirFighter"; - pictureBoxAirFighter.Size = new Size(1056, 743); + pictureBoxAirFighter.Size = new Size(924, 557); pictureBoxAirFighter.TabIndex = 0; pictureBoxAirFighter.TabStop = false; - // // buttonCreate // buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(14, 635); - buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Location = new Point(0, 522); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(86, 31); + buttonCreate.Size = new Size(232, 23); buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать"; + buttonCreate.Text = "Создать истребитель"; buttonCreate.UseVisualStyleBackColor = true; buttonCreate.Click += ButtonCreate_Click; // @@ -65,10 +63,9 @@ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.left; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; - buttonLeft.Location = new Point(897, 680); - buttonLeft.Margin = new Padding(3, 4, 3, 4); + buttonLeft.Location = new Point(785, 510); buttonLeft.Name = "buttonLeft"; - buttonLeft.Size = new Size(40, 47); + buttonLeft.Size = new Size(35, 35); buttonLeft.TabIndex = 2; buttonLeft.UseVisualStyleBackColor = true; buttonLeft.ClientSizeChanged += FormAirFighter_SizeChanged; @@ -79,10 +76,9 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.up; buttonUp.BackgroundImageLayout = ImageLayout.Stretch; - buttonUp.Location = new Point(946, 625); - buttonUp.Margin = new Padding(3, 4, 3, 4); + buttonUp.Location = new Point(828, 469); buttonUp.Name = "buttonUp"; - buttonUp.Size = new Size(40, 47); + buttonUp.Size = new Size(35, 35); buttonUp.TabIndex = 3; buttonUp.UseVisualStyleBackColor = true; buttonUp.ClientSizeChanged += FormAirFighter_SizeChanged; @@ -93,10 +89,9 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.down; buttonDown.BackgroundImageLayout = ImageLayout.Stretch; - buttonDown.Location = new Point(946, 680); - buttonDown.Margin = new Padding(3, 4, 3, 4); + buttonDown.Location = new Point(828, 510); buttonDown.Name = "buttonDown"; - buttonDown.Size = new Size(40, 47); + buttonDown.Size = new Size(35, 35); buttonDown.TabIndex = 4; buttonDown.UseVisualStyleBackColor = true; buttonDown.ClientSizeChanged += FormAirFighter_SizeChanged; @@ -107,27 +102,37 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.right; buttonRight.BackgroundImageLayout = ImageLayout.Stretch; - buttonRight.Location = new Point(993, 680); - buttonRight.Margin = new Padding(3, 4, 3, 4); + buttonRight.Location = new Point(869, 510); buttonRight.Name = "buttonRight"; - buttonRight.Size = new Size(40, 47); + buttonRight.Size = new Size(35, 35); buttonRight.TabIndex = 5; buttonRight.UseVisualStyleBackColor = true; buttonRight.ClientSizeChanged += FormAirFighter_SizeChanged; buttonRight.Click += ButtonMove_Click; // + // buttonCreateWarPlane + // + buttonCreateWarPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateWarPlane.Location = new Point(238, 522); + buttonCreateWarPlane.Name = "buttonCreateWarPlane"; + buttonCreateWarPlane.Size = new Size(232, 23); + buttonCreateWarPlane.TabIndex = 6; + buttonCreateWarPlane.Text = "Создать военный самолет"; + buttonCreateWarPlane.UseVisualStyleBackColor = true; + buttonCreateWarPlane.Click += buttonCreateWarPlane_Click; + // // FormAirFighter // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1056, 743); + ClientSize = new Size(924, 557); + Controls.Add(buttonCreateWarPlane); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonLeft); Controls.Add(buttonCreate); Controls.Add(pictureBoxAirFighter); - Margin = new Padding(3, 4, 3, 4); Name = "FormAirFighter"; Text = "Истребитель"; SizeChanged += FormAirFighter_SizeChanged; @@ -143,5 +148,6 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; + private Button buttonCreateWarPlane; } } \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs index 6b7188e..100e08b 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormAirFighter.cs @@ -7,6 +7,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ProjectAirFighter.Drawning; +using ProjectAirFighter.Entities; namespace ProjectAirFighter { @@ -14,43 +16,74 @@ namespace ProjectAirFighter { - private DrawningAirFighter? _drawningAirFighter; + private DrawningWarPlane? _drawningWarPlane; - private EntityAirFighter? _entityAirFighter; + + /// + /// Стратегия перемещения + /// + //private AbstractStrategy? _strategy; + /// + /// Конструктор формы + /// public FormAirFighter() { InitializeComponent(); + //_strategy = null; } - + /// + /// Метод прорисовки + /// private void Draw() { - if (_drawningAirFighter == null) return; + if (_drawningWarPlane == null) return; Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningAirFighter.DrawTransport(gr); + _drawningWarPlane.DrawTransport(gr); pictureBoxAirFighter.Image = bmp; } + private void CreateObject(string type) + { + Random random = new(); + switch (type) + { + case nameof(DrawningWarPlane): + _drawningWarPlane = new DrawningWarPlane(random.Next(100, 300), + random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256))); + break; + case nameof(DrawningAirFighter): + _drawningWarPlane = new DrawningAirFighter(random.Next(100, + 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)), + 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))); + break; + default: + return; + } + _drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width, + pictureBoxAirFighter.Height); + _drawningWarPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } private void ButtonCreate_Click(object sender, EventArgs e) { - Random random = new(); - _drawningAirFighter = new DrawningAirFighter(); - _entityAirFighter = new EntityAirFighter(); - - _entityAirFighter.Init(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - 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))); - _drawningAirFighter.Init(_entityAirFighter); - _drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); - _drawningAirFighter.SetPosition(random.Next(40, 100), random.Next(40, 100)); - - Draw(); + CreateObject(nameof(DrawningAirFighter)); + } + private void buttonCreateWarPlane_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningWarPlane)); } private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawningAirFighter == null) + if (_drawningWarPlane == null) { return; } @@ -60,16 +93,16 @@ namespace ProjectAirFighter switch (name) { case "buttonUp": - result = _drawningAirFighter.MoveTransport(DirectionType.Up); + result = _drawningWarPlane.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawningAirFighter.MoveTransport(DirectionType.Down); + result = _drawningWarPlane.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawningAirFighter.MoveTransport(DirectionType.Left); + result = _drawningWarPlane.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawningAirFighter.MoveTransport(DirectionType.Right); + result = _drawningWarPlane.MoveTransport(DirectionType.Right); break; } if (result) @@ -81,13 +114,13 @@ namespace ProjectAirFighter } private void FormAirFighter_SizeChanged(object sender, EventArgs e) { - if (_drawningAirFighter == null) return; + if (_drawningWarPlane == null) return; - _drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); + _drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); - if (_drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height)) + if (_drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height)) { Draw(); }