From 15200db2d15db18b3cca25f9fe4355a661dc30af Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 13:50:55 +0400 Subject: [PATCH 01/11] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20La?= =?UTF-8?q?b3.=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20SetGen?= =?UTF-8?q?eric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/SetGeneric.cs | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 AirBomber/AirBomber/SetGeneric.cs diff --git a/AirBomber/AirBomber/SetGeneric.cs b/AirBomber/AirBomber/SetGeneric.cs new file mode 100644 index 0000000..b182f0c --- /dev/null +++ b/AirBomber/AirBomber/SetGeneric.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class SetGeneric + where T : class + { + private readonly T?[] _places; + public int Count => _places.Length; + public SetGeneric(int count) + { + _places = new T?[count]; + } + public int Insert(T plane) + { + return Insert(plane, 0); + } + public int Insert(T plane, int position) + { + int NoEmpty = 0, temp = 0; + for (int i = position; i < Count; i++) + { + if (_places[i] != null) NoEmpty++; + } + if (NoEmpty == Count - position) return -1; + + if (position < Count && position >= 0) + { + for (int j = position; j < Count; j++) + { + if (_places[j] == null) + { + temp = j; + break; + } + } + + for (int i = temp; i > position; i--) + { + _places[i] = _places[i - 1]; + } + _places[position] = plane; + return position; + } + return -1; + } + public bool Remove(int position) + { + if (!(position >= 0 && position < Count) || _places[position] == null) + { + return false; + } + _places[position] = null; + return true; + } + public T? Get(int position) + { + if (position < 0 || position >= Count) + { + return null; + } + return _places[position]; + } + } +} -- 2.25.1 From 618d9a5ae7a0173dd1117f0bcad52730b199755c Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 13:55:42 +0400 Subject: [PATCH 02/11] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20PlanesGenericCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/PlanesGenericCollection.cs | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 AirBomber/AirBomber/PlanesGenericCollection.cs diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs new file mode 100644 index 0000000..820ad0c --- /dev/null +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class PlanesGenericCollection + where T : DrawningAirPlane + where U : IMoveableObject + { + private readonly int _pictureWidth; + private readonly int _pictureHeight; + private readonly int _placeSizeWidth = 170; + private readonly int _placeSizeHeight = 120; + private readonly SetGeneric _collection; + public PlanesGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + public static int operator +(PlanesGenericCollection collect, T? obj) + { + if (obj == null) + { + return -1; + } + return collect?._collection.Insert(obj) ?? -1; + } + public static bool operator -(PlanesGenericCollection collect, int pos) + { + T? obj = collect._collection.Get(pos); + if (obj != null) + { + collect._collection.Remove(pos); + return true; + } + return false; + } + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + public Bitmap ShowPlanes() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth, j * + _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * + _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * + _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + private void DrawObjects(Graphics g) + { + int widthObjCount = _pictureWidth / _placeSizeWidth; + for (int i = 0; i < _collection.Count; i++) + { + T? type = _collection.Get(i); + if (type != null) + { + int row = i / widthObjCount; + int col = widthObjCount - 1 - (i % widthObjCount); + + type.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight); + type?.DrawPlane(g); + } + } + } + } +} -- 2.25.1 From 18bee6af6400ffa252874fea890866dc145aba57 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 13:57:10 +0400 Subject: [PATCH 03/11] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?=20DrawningAirPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index b28b224..674db8f 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -189,5 +189,6 @@ namespace AirBomber break; } } + public IMoveableObject GetMoveableObject => new DrawningObjectAirPlane(this); } } -- 2.25.1 From 8188c6e0cb1abf3a83d1e983b72dda77da2b0f00 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 14:35:13 +0400 Subject: [PATCH 04/11] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20FormPlaneCollection,?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B0=20For?= =?UTF-8?q?mAirBomber=20(=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=B1=D0=B5=D0=B7=20?= =?UTF-8?q?=D0=B4=D0=B2=D0=B8=D0=B3=D0=B0=D1=82=D0=B5=D0=BB=D0=B5=D0=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormAirBomber.Designer.cs | 37 ++++-- AirBomber/AirBomber/FormAirBomber.cs | 62 ++++++--- .../AirBomber/FormPlaneCollection.Designer.cs | 123 ++++++++++++++++++ AirBomber/AirBomber/FormPlaneCollection.cs | 20 +++ AirBomber/AirBomber/FormPlaneCollection.resx | 60 +++++++++ 5 files changed, 271 insertions(+), 31 deletions(-) create mode 100644 AirBomber/AirBomber/FormPlaneCollection.Designer.cs create mode 100644 AirBomber/AirBomber/FormPlaneCollection.cs create mode 100644 AirBomber/AirBomber/FormPlaneCollection.resx diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index a8ba700..fa78fa9 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -36,7 +36,8 @@ pictureBoxAirBomber = new PictureBox(); buttonCreateAirPlane = new Button(); comboBoxStrategy = new ComboBox(); - buttonStep = new Button(); + buttonStrategyStep = new Button(); + buttonSelectPlane = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); SuspendLayout(); // @@ -129,23 +130,34 @@ comboBoxStrategy.Size = new Size(182, 33); comboBoxStrategy.TabIndex = 7; // - // buttonStep + // buttonStrategyStep // - buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonStep.Location = new Point(660, 70); - buttonStep.Name = "buttonStep"; - buttonStep.Size = new Size(112, 34); - buttonStep.TabIndex = 8; - buttonStep.Text = "Шаг"; - buttonStep.UseVisualStyleBackColor = true; - buttonStep.Click += buttonStep_Click; + buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonStrategyStep.Location = new Point(660, 70); + buttonStrategyStep.Name = "buttonStrategyStep"; + buttonStrategyStep.Size = new Size(112, 34); + buttonStrategyStep.TabIndex = 8; + buttonStrategyStep.Text = "Шаг"; + buttonStrategyStep.UseVisualStyleBackColor = true; + buttonStrategyStep.Click += buttonStrategyStep_Click; + // + // buttonSelectPlane + // + buttonSelectPlane.Location = new Point(660, 161); + buttonSelectPlane.Name = "buttonSelectPlane"; + buttonSelectPlane.Size = new Size(112, 63); + buttonSelectPlane.TabIndex = 9; + buttonSelectPlane.Text = "Выбрать самолет"; + buttonSelectPlane.UseVisualStyleBackColor = true; + buttonSelectPlane.Click += buttonSelectPlane_Click; // // FormAirBomber // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); - Controls.Add(buttonStep); + Controls.Add(buttonSelectPlane); + Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); Controls.Add(buttonCreateAirPlane); Controls.Add(buttonDown); @@ -170,6 +182,7 @@ private PictureBox pictureBoxAirBomber; private Button buttonCreateAirPlane; private ComboBox comboBoxStrategy; - private Button buttonStep; + private Button buttonStrategyStep; + private Button buttonSelectPlane; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 6922714..abf877f 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -1,12 +1,15 @@ -namespace AirBomber +namespace AirBomber { public partial class FormAirBomber : Form { private DrawningAirPlane? _drawningAirPlane; - private AbstractStrategy? _abstractStrategy; + private AbstractStrategy? _strategy; + public DrawningAirPlane? SelectedPlane { get; private set; } public FormAirBomber() { InitializeComponent(); + _strategy = null; + SelectedPlane = null; } private void Draw() { @@ -22,21 +25,37 @@ namespace AirBomber private void buttonCreateAirBomber_Click(object sender, EventArgs e) { Random random = new(); - _drawningAirPlane = new DrawningAirBomber(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)), - pictureBoxAirBomber.Width, pictureBoxAirBomber.Height, random.Next(1, 4) * 2, random.Next(0, 4)); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog colorDialog = new ColorDialog(); + //TODO выбор основного цвета DONE + if (colorDialog.ShowDialog() == DialogResult.OK) + { + color = colorDialog.Color; + } + + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + //TODO выбор дополнительного цвета DONE + if (colorDialog.ShowDialog() == DialogResult.OK) + { + dopColor = colorDialog.Color; + } + + _drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); - } private void buttonCreateAirPlane_Click(object sender, EventArgs e) { Random random = new(); - _drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - pictureBoxAirBomber.Width, pictureBoxAirBomber.Height, random.Next(1, 4) * 2, random.Next(0, 4)); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); @@ -65,7 +84,7 @@ namespace AirBomber } Draw(); } - private void buttonStep_Click(object sender, EventArgs e) + private void buttonStrategyStep_Click(object sender, EventArgs e) { if (_drawningAirPlane == null) { @@ -73,32 +92,37 @@ namespace AirBomber } if (comboBoxStrategy.Enabled) { - _abstractStrategy = comboBoxStrategy.SelectedIndex + _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.SetData(new DrawningObjectAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width, - pictureBoxAirBomber.Height); + _strategy.SetData(new DrawningObjectAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); comboBoxStrategy.Enabled = false; } - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.MakeStep(); + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); Draw(); - if (_abstractStrategy.GetStatus() == Status.Finish) + if (_strategy.GetStatus() == Status.Finish) { comboBoxStrategy.Enabled = true; - _abstractStrategy = null; + _strategy = null; } } + private void buttonSelectPlane_Click(object sender, EventArgs e) + { + SelectedPlane = _drawningAirPlane; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs new file mode 100644 index 0000000..7f7ef81 --- /dev/null +++ b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs @@ -0,0 +1,123 @@ +namespace AirBomber +{ + partial class FormPlaneCollection + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBoxTools = new GroupBox(); + pictureBoxCollection = new PictureBox(); + buttonAddPlane = new Button(); + maskedTextBoxNumber = new MaskedTextBox(); + buttonRemovePlane = new Button(); + buttonRefreshCollection = new Button(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefreshCollection); + groupBoxTools.Controls.Add(buttonRemovePlane); + groupBoxTools.Controls.Add(maskedTextBoxNumber); + groupBoxTools.Controls.Add(buttonAddPlane); + groupBoxTools.Location = new Point(758, 1); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(325, 655); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // pictureBoxCollection + // + pictureBoxCollection.Dock = DockStyle.Left; + pictureBoxCollection.Location = new Point(0, 0); + pictureBoxCollection.Name = "pictureBoxCollection"; + pictureBoxCollection.Size = new Size(752, 668); + pictureBoxCollection.TabIndex = 1; + pictureBoxCollection.TabStop = false; + // + // buttonAddPlane + // + buttonAddPlane.Location = new Point(17, 53); + buttonAddPlane.Name = "buttonAddPlane"; + buttonAddPlane.Size = new Size(290, 59); + buttonAddPlane.TabIndex = 0; + buttonAddPlane.Text = "Добавить самолет"; + buttonAddPlane.UseVisualStyleBackColor = true; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Location = new Point(79, 166); + maskedTextBoxNumber.Mask = "00"; + maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + maskedTextBoxNumber.Size = new Size(171, 31); + maskedTextBoxNumber.TabIndex = 1; + maskedTextBoxNumber.ValidatingType = typeof(int); + // + // buttonRemovePlane + // + buttonRemovePlane.Location = new Point(17, 213); + buttonRemovePlane.Name = "buttonRemovePlane"; + buttonRemovePlane.Size = new Size(290, 59); + buttonRemovePlane.TabIndex = 2; + buttonRemovePlane.Text = "Удалить самолет"; + buttonRemovePlane.UseVisualStyleBackColor = true; + // + // buttonRefreshCollection + // + buttonRefreshCollection.Location = new Point(17, 357); + buttonRefreshCollection.Name = "buttonRefreshCollection"; + buttonRefreshCollection.Size = new Size(290, 59); + buttonRefreshCollection.TabIndex = 3; + buttonRefreshCollection.Text = "Обновить коллекцию"; + buttonRefreshCollection.UseVisualStyleBackColor = true; + // + // FormPlaneCollection + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1095, 668); + Controls.Add(pictureBoxCollection); + Controls.Add(groupBoxTools); + Name = "FormPlaneCollection"; + Text = "Набор самолетов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonRefreshCollection; + private Button buttonRemovePlane; + private MaskedTextBox maskedTextBoxNumber; + private Button buttonAddPlane; + private PictureBox pictureBoxCollection; + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/FormPlaneCollection.cs b/AirBomber/AirBomber/FormPlaneCollection.cs new file mode 100644 index 0000000..28a9d7e --- /dev/null +++ b/AirBomber/AirBomber/FormPlaneCollection.cs @@ -0,0 +1,20 @@ +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 AirBomber +{ + public partial class FormPlaneCollection : Form + { + public FormPlaneCollection() + { + InitializeComponent(); + } + } +} diff --git a/AirBomber/AirBomber/FormPlaneCollection.resx b/AirBomber/AirBomber/FormPlaneCollection.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AirBomber/AirBomber/FormPlaneCollection.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file -- 2.25.1 From e08aabd3df34bfdd85d9bc1c37cd3b423ce79d68 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 14:39:42 +0400 Subject: [PATCH 05/11] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20Program?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index 9b5f0b9..834692d 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -11,7 +11,7 @@ // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAirBomber()); + Application.Run(new FormPlaneCollection()); } } } \ No newline at end of file -- 2.25.1 From 69a0414756ff35a60810b56f683e989f9b233103 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 14:44:55 +0400 Subject: [PATCH 06/11] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B-=D0=BA=D0=BE=D0=BB=D0=BB=D0=B5?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/FormPlaneCollection.Designer.cs | 67 ++++++++++--------- AirBomber/AirBomber/FormPlaneCollection.cs | 39 +++++++++++ 2 files changed, 74 insertions(+), 32 deletions(-) diff --git a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs index 7f7ef81..90f87b5 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs @@ -29,11 +29,11 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - pictureBoxCollection = new PictureBox(); - buttonAddPlane = new Button(); - maskedTextBoxNumber = new MaskedTextBox(); - buttonRemovePlane = new Button(); buttonRefreshCollection = new Button(); + buttonRemovePlane = new Button(); + maskedTextBoxNumber = new MaskedTextBox(); + buttonAddPlane = new Button(); + pictureBoxCollection = new PictureBox(); groupBoxTools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); SuspendLayout(); @@ -51,23 +51,25 @@ groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // pictureBoxCollection + // buttonRefreshCollection // - pictureBoxCollection.Dock = DockStyle.Left; - pictureBoxCollection.Location = new Point(0, 0); - pictureBoxCollection.Name = "pictureBoxCollection"; - pictureBoxCollection.Size = new Size(752, 668); - pictureBoxCollection.TabIndex = 1; - pictureBoxCollection.TabStop = false; + buttonRefreshCollection.Location = new Point(17, 357); + buttonRefreshCollection.Name = "buttonRefreshCollection"; + buttonRefreshCollection.Size = new Size(290, 59); + buttonRefreshCollection.TabIndex = 3; + buttonRefreshCollection.Text = "Обновить коллекцию"; + buttonRefreshCollection.UseVisualStyleBackColor = true; + buttonRefreshCollection.Click += buttonRefreshCollection_Click; // - // buttonAddPlane + // buttonRemovePlane // - buttonAddPlane.Location = new Point(17, 53); - buttonAddPlane.Name = "buttonAddPlane"; - buttonAddPlane.Size = new Size(290, 59); - buttonAddPlane.TabIndex = 0; - buttonAddPlane.Text = "Добавить самолет"; - buttonAddPlane.UseVisualStyleBackColor = true; + buttonRemovePlane.Location = new Point(17, 213); + buttonRemovePlane.Name = "buttonRemovePlane"; + buttonRemovePlane.Size = new Size(290, 59); + buttonRemovePlane.TabIndex = 2; + buttonRemovePlane.Text = "Удалить самолет"; + buttonRemovePlane.UseVisualStyleBackColor = true; + buttonRemovePlane.Click += buttonRemovePlane_Click; // // maskedTextBoxNumber // @@ -78,23 +80,24 @@ maskedTextBoxNumber.TabIndex = 1; maskedTextBoxNumber.ValidatingType = typeof(int); // - // buttonRemovePlane + // buttonAddPlane // - buttonRemovePlane.Location = new Point(17, 213); - buttonRemovePlane.Name = "buttonRemovePlane"; - buttonRemovePlane.Size = new Size(290, 59); - buttonRemovePlane.TabIndex = 2; - buttonRemovePlane.Text = "Удалить самолет"; - buttonRemovePlane.UseVisualStyleBackColor = true; + buttonAddPlane.Location = new Point(17, 53); + buttonAddPlane.Name = "buttonAddPlane"; + buttonAddPlane.Size = new Size(290, 59); + buttonAddPlane.TabIndex = 0; + buttonAddPlane.Text = "Добавить самолет"; + buttonAddPlane.UseVisualStyleBackColor = true; + buttonAddPlane.Click += buttonAddPlane_Click; // - // buttonRefreshCollection + // pictureBoxCollection // - buttonRefreshCollection.Location = new Point(17, 357); - buttonRefreshCollection.Name = "buttonRefreshCollection"; - buttonRefreshCollection.Size = new Size(290, 59); - buttonRefreshCollection.TabIndex = 3; - buttonRefreshCollection.Text = "Обновить коллекцию"; - buttonRefreshCollection.UseVisualStyleBackColor = true; + pictureBoxCollection.Dock = DockStyle.Left; + pictureBoxCollection.Location = new Point(0, 0); + pictureBoxCollection.Name = "pictureBoxCollection"; + pictureBoxCollection.Size = new Size(752, 668); + pictureBoxCollection.TabIndex = 1; + pictureBoxCollection.TabStop = false; // // FormPlaneCollection // diff --git a/AirBomber/AirBomber/FormPlaneCollection.cs b/AirBomber/AirBomber/FormPlaneCollection.cs index 28a9d7e..d473899 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.cs @@ -12,9 +12,48 @@ namespace AirBomber { public partial class FormPlaneCollection : Form { + private readonly PlanesGenericCollection _planes; public FormPlaneCollection() { InitializeComponent(); + _planes = new PlanesGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + private void buttonAddPlane_Click(object sender, EventArgs e) + { + FormAirBomber form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_planes + form.SelectedPlane != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _planes.ShowPlanes(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + private void buttonRemovePlane_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_planes - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _planes.ShowPlanes(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + private void buttonRefreshCollection_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _planes.ShowPlanes(); } } } -- 2.25.1 From 0f18368d7f2b63f3b678cde007c8ad699bf808bb Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 14:52:55 +0400 Subject: [PATCH 07/11] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D1=81=D0=B5=D0=BD=D0=B0=20=D0=B2=D1=81=D1=8F=20=D0=B1=D0=B0?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0,=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=B2=D0=B8=D0=B3=D0=B0=D1=82=D0=B5=D0=BB=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormAirBomber.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index abf877f..9425262 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -41,7 +41,7 @@ } _drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height, random.Next(1, 4) * 2, random.Next(0, 4)); _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); @@ -55,7 +55,7 @@ { color = dialog.Color; } - _drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + _drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxAirBomber.Width, pictureBoxAirBomber.Height, random.Next(1, 4) * 2, random.Next(0, 4)); _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); -- 2.25.1 From 00b1a7182c46ab4be223ef1cefa53c1bb2a09c6f Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 16:18:45 +0400 Subject: [PATCH 08/11] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AdditionalGeneric.cs | 95 ++++++++++++++ AirBomber/AirBomber/DrawningEnginesCircle.cs | 15 +++ .../AirBomber/DrawningEnginesRectangle.cs | 15 +++ .../AirBomber/DrawningEnginesTriangle.cs | 15 +++ .../FormAdditionalGeneric.Designer.cs | 39 ++++++ AirBomber/AirBomber/FormAdditionalGeneric.cs | 20 +++ .../AirBomber/FormAdditionalGeneric.resx | 120 ++++++++++++++++++ AirBomber/AirBomber/IDrawningEngines.cs | 4 +- 8 files changed, 322 insertions(+), 1 deletion(-) create mode 100644 AirBomber/AirBomber/AdditionalGeneric.cs create mode 100644 AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs create mode 100644 AirBomber/AirBomber/FormAdditionalGeneric.cs create mode 100644 AirBomber/AirBomber/FormAdditionalGeneric.resx diff --git a/AirBomber/AirBomber/AdditionalGeneric.cs b/AirBomber/AirBomber/AdditionalGeneric.cs new file mode 100644 index 0000000..a6f1201 --- /dev/null +++ b/AirBomber/AirBomber/AdditionalGeneric.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public class AdditionalGeneric + where T : EntityAirPlane + where U : IDrawningEngines + { + private T[] planes; + private U[] engines; + + private int planesCount = 0; + private int enginesCount = 0; + + private int _pictureWidth; + private int _pictureHeight; + + private Random random; + + public AdditionalGeneric(int count, int width, int height) + { + planes = new T[count]; + engines = new U[count]; + + _pictureWidth = width; + _pictureHeight = height; + + random = new Random(); + } + public bool Add(T plane) + { + for (int i = 0; i < planes.Length; i++) + { + if (planes[i] == null) + { + planes[i] = plane; + planesCount++; + return true; + } + } + return false; + } + public bool Add(U engine) + { + for (int i = 0; i < planes.Length; i++) + { + if (engines[i] == null) + { + engines[i] = engine; + enginesCount++; + return true; + } + } + return false; + } + public DrawningAirPlane CreateDrawObject() + { + Random rand = new Random(); + EntityAirPlane plane = planes[rand.Next(0, planesCount)]; + IDrawningEngines engine = engines[rand.Next(0, enginesCount)]; + + if (plane is EntityAirBomber airBomber) + { + return new DrawningAirBomber( + plane.Speed, + plane.Weight, + plane.BodyColor, + airBomber.AdditionalColor, + airBomber.Bombs, + airBomber.FuelTanks, + _pictureWidth, + _pictureHeight, + engine.GetAmount(), + engine.GetShape() + ); + } + + return new DrawningAirPlane( + plane.Speed, + plane.Weight, + plane.BodyColor, + _pictureWidth, + _pictureHeight, + engine.GetAmount(), + engine.GetShape() + ); + } + + + } +} diff --git a/AirBomber/AirBomber/DrawningEnginesCircle.cs b/AirBomber/AirBomber/DrawningEnginesCircle.cs index e6ae763..19f5967 100644 --- a/AirBomber/AirBomber/DrawningEnginesCircle.cs +++ b/AirBomber/AirBomber/DrawningEnginesCircle.cs @@ -9,6 +9,21 @@ namespace AirBomber public class DrawningEnginesCircle : IDrawningEngines { private Engines amount; + public int GetShape() + { + return 2; + } + public int GetAmount() + { + int x = 0; + if (amount == Engines.Two) + x = 2; + if (amount == Engines.Four) + x = 4; + if (amount == Engines.Six) + x = 6; + return x; + } public void SetAmount(int a) { if (a <= 2) diff --git a/AirBomber/AirBomber/DrawningEnginesRectangle.cs b/AirBomber/AirBomber/DrawningEnginesRectangle.cs index 8801ec8..a9814cf 100644 --- a/AirBomber/AirBomber/DrawningEnginesRectangle.cs +++ b/AirBomber/AirBomber/DrawningEnginesRectangle.cs @@ -10,6 +10,21 @@ namespace AirBomber public class DrawningEnginesRectangle : IDrawningEngines { private Engines amount; + public int GetShape() + { + return 0; + } + public int GetAmount() + { + int x = 0; + if (amount == Engines.Two) + x = 2; + if (amount == Engines.Four) + x = 4; + if (amount == Engines.Six) + x = 6; + return x; + } public void SetAmount(int a) { if (a <= 2) diff --git a/AirBomber/AirBomber/DrawningEnginesTriangle.cs b/AirBomber/AirBomber/DrawningEnginesTriangle.cs index bd6b48b..0087ea0 100644 --- a/AirBomber/AirBomber/DrawningEnginesTriangle.cs +++ b/AirBomber/AirBomber/DrawningEnginesTriangle.cs @@ -9,6 +9,21 @@ namespace AirBomber public class DrawningEnginesTriangle : IDrawningEngines { private Engines amount; + public int GetShape() + { + return 1; + } + public int GetAmount() + { + int x = 0; + if (amount == Engines.Two) + x = 2; + if (amount == Engines.Four) + x = 4; + if (amount == Engines.Six) + x = 6; + return x; + } public void SetAmount(int a) { if (a <= 2) diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs b/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs new file mode 100644 index 0000000..0a9e5eb --- /dev/null +++ b/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs @@ -0,0 +1,39 @@ +namespace AirBomber +{ + partial class FormAdditionalGeneric + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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 = "FormAdditionalGeneric"; + } + + #endregion + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.cs b/AirBomber/AirBomber/FormAdditionalGeneric.cs new file mode 100644 index 0000000..53ef532 --- /dev/null +++ b/AirBomber/AirBomber/FormAdditionalGeneric.cs @@ -0,0 +1,20 @@ +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 AirBomber +{ + public partial class FormAdditionalGeneric : Form + { + public FormAdditionalGeneric() + { + InitializeComponent(); + } + } +} diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.resx b/AirBomber/AirBomber/FormAdditionalGeneric.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AirBomber/AirBomber/FormAdditionalGeneric.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/AirBomber/AirBomber/IDrawningEngines.cs b/AirBomber/AirBomber/IDrawningEngines.cs index dfeb2c8..04bae50 100644 --- a/AirBomber/AirBomber/IDrawningEngines.cs +++ b/AirBomber/AirBomber/IDrawningEngines.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; namespace AirBomber { - internal interface IDrawningEngines + public interface IDrawningEngines { public void SetAmount(int a); public void DrawEngines(Graphics g, int _startPosX, int _startPosY); + public int GetAmount(); + public int GetShape(); } } -- 2.25.1 From 294c75c51c7803231babd2cb8a27b4f99f0528e3 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 18:12:21 +0400 Subject: [PATCH 09/11] =?UTF-8?q?=D0=A7=D1=82=D0=BE-=D1=82=D0=BE=20=D1=81?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BE=20=D0=B2=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=B5=20AdditionalGeneric,=20=D0=BD=D0=BE=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormAdditionalGeneric.Designer.cs | 42 +++++++++++-- AirBomber/AirBomber/FormAdditionalGeneric.cs | 9 +++ .../AirBomber/FormAdditionalGeneric.resx | 62 +------------------ 3 files changed, 48 insertions(+), 65 deletions(-) diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs b/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs index 0a9e5eb..8d13ede 100644 --- a/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs +++ b/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs @@ -28,12 +28,46 @@ /// 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 = "FormAdditionalGeneric"; + pictureBoxObject = new PictureBox(); + buttonCreate = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // pictureBoxObject + // + pictureBoxObject.Dock = DockStyle.Fill; + pictureBoxObject.Location = new Point(0, 0); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(908, 460); + pictureBoxObject.TabIndex = 0; + pictureBoxObject.TabStop = false; + // + // buttonCreate + // + buttonCreate.Location = new Point(726, 28); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(152, 66); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // FormAdditionalGeneric + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(908, 460); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxObject); + Name = "FormAdditionalGeneric"; + Text = "FormAdditionalGeneric"; + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); } #endregion + + private PictureBox pictureBoxObject; + private Button buttonCreate; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.cs b/AirBomber/AirBomber/FormAdditionalGeneric.cs index 53ef532..804620b 100644 --- a/AirBomber/AirBomber/FormAdditionalGeneric.cs +++ b/AirBomber/AirBomber/FormAdditionalGeneric.cs @@ -12,9 +12,18 @@ namespace AirBomber { public partial class FormAdditionalGeneric : Form { + private DrawningAirPlane _drawningAirPlane; + private AdditionalGeneric additionalGeneric; + private readonly int _pictureWidth = 200; + private readonly int _pictureHeight = 200; public FormAdditionalGeneric() { InitializeComponent(); } + + private void buttonCreate_Click(object sender, EventArgs e) + { + _drawningAirPlane = additionalGeneric.CreateDrawObject(); + } } } diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.resx b/AirBomber/AirBomber/FormAdditionalGeneric.resx index 1af7de1..f298a7b 100644 --- a/AirBomber/AirBomber/FormAdditionalGeneric.resx +++ b/AirBomber/AirBomber/FormAdditionalGeneric.resx @@ -1,64 +1,4 @@ - - - + -- 2.25.1 From d2624a12bbf7e5e62af2b7ec44a322eb6c155749 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 20:22:26 +0400 Subject: [PATCH 10/11] =?UTF-8?q?=D0=92=D1=81=D1=91=20=D1=81=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=BE=20=D0=B4=D0=BB=D1=8F=20=D1=83=D1=81?= =?UTF-8?q?=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5=D0=BD=D0=BA=D0=B8=20=D0=B2=D1=80?= =?UTF-8?q?=D0=BE=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AdditionalGeneric.cs | 2 - AirBomber/AirBomber/FormAdditionalGeneric.cs | 66 +++++++++++++++++-- .../AirBomber/FormPlaneCollection.Designer.cs | 13 ++++ AirBomber/AirBomber/FormPlaneCollection.cs | 5 ++ 4 files changed, 80 insertions(+), 6 deletions(-) diff --git a/AirBomber/AirBomber/AdditionalGeneric.cs b/AirBomber/AirBomber/AdditionalGeneric.cs index a6f1201..4b691f5 100644 --- a/AirBomber/AirBomber/AdditionalGeneric.cs +++ b/AirBomber/AirBomber/AdditionalGeneric.cs @@ -89,7 +89,5 @@ namespace AirBomber engine.GetShape() ); } - - } } diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.cs b/AirBomber/AirBomber/FormAdditionalGeneric.cs index 804620b..326f840 100644 --- a/AirBomber/AirBomber/FormAdditionalGeneric.cs +++ b/AirBomber/AirBomber/FormAdditionalGeneric.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar; namespace AirBomber { @@ -14,16 +15,73 @@ namespace AirBomber { private DrawningAirPlane _drawningAirPlane; private AdditionalGeneric additionalGeneric; - private readonly int _pictureWidth = 200; - private readonly int _pictureHeight = 200; + private readonly int _pictureWidth = 400; + private readonly int _pictureHeight = 400; + Random random = new Random(); public FormAdditionalGeneric() { InitializeComponent(); } - + private void Draw() + { + if (_drawningAirPlane == null) + { + return; + } + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningAirPlane.DrawPlane(gr); + pictureBoxObject.Image = bmp; + } private void buttonCreate_Click(object sender, EventArgs e) { - _drawningAirPlane = additionalGeneric.CreateDrawObject(); + int size = random.Next(1, 10); + additionalGeneric = new AdditionalGeneric(size, _pictureWidth, _pictureHeight); + for (int i = 0; i < size; i++) + { + EntityAirPlane plane = CreateRandomPlane(); + IDrawningEngines engines = CreateRandomEngines(); + additionalGeneric.Add(plane); + additionalGeneric.Add(engines); + _drawningAirPlane = additionalGeneric.CreateDrawObject(); + _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + } + + public EntityAirPlane CreateRandomPlane() + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + EntityAirPlane plane; + switch (random.Next(0, 2)) + { + case 1: + plane = new EntityAirBomber(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(2)), Convert.ToBoolean(random.Next(2))); + break; + default: + plane = new EntityAirPlane(random.Next(100, 300), random.Next(1000, 3000), color); + break; + } + return plane; + } + public IDrawningEngines CreateRandomEngines() + { + IDrawningEngines engines; + switch (random.Next(3)) + { + case 1: + engines = new DrawningEnginesTriangle(); + break; + case 2: + engines = new DrawningEnginesCircle(); + break; + default: + engines = new DrawningEnginesRectangle(); + break; + } + engines.SetAmount((random.Next(1, 4) * 2)); + return engines; } } } diff --git a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs index 90f87b5..063c470 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs @@ -34,12 +34,14 @@ maskedTextBoxNumber = new MaskedTextBox(); buttonAddPlane = new Button(); pictureBoxCollection = new PictureBox(); + buttonToFormAddGeneric = new Button(); groupBoxTools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); SuspendLayout(); // // groupBoxTools // + groupBoxTools.Controls.Add(buttonToFormAddGeneric); groupBoxTools.Controls.Add(buttonRefreshCollection); groupBoxTools.Controls.Add(buttonRemovePlane); groupBoxTools.Controls.Add(maskedTextBoxNumber); @@ -99,6 +101,16 @@ pictureBoxCollection.TabIndex = 1; pictureBoxCollection.TabStop = false; // + // buttonToFormAddGeneric + // + buttonToFormAddGeneric.Location = new Point(17, 545); + buttonToFormAddGeneric.Name = "buttonToFormAddGeneric"; + buttonToFormAddGeneric.Size = new Size(290, 61); + buttonToFormAddGeneric.TabIndex = 4; + buttonToFormAddGeneric.Text = "Перейти к генерации объектов"; + buttonToFormAddGeneric.UseVisualStyleBackColor = true; + buttonToFormAddGeneric.Click += buttonToFormAddGeneric_Click; + // // FormPlaneCollection // AutoScaleDimensions = new SizeF(10F, 25F); @@ -122,5 +134,6 @@ private MaskedTextBox maskedTextBoxNumber; private Button buttonAddPlane; private PictureBox pictureBoxCollection; + private Button buttonToFormAddGeneric; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormPlaneCollection.cs b/AirBomber/AirBomber/FormPlaneCollection.cs index d473899..d7b25d1 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.cs @@ -55,5 +55,10 @@ namespace AirBomber { pictureBoxCollection.Image = _planes.ShowPlanes(); } + private void buttonToFormAddGeneric_Click(object sender, EventArgs e) + { + FormAdditionalGeneric form = new(); + form.ShowDialog(); + } } } -- 2.25.1 From 8aa5bce7bab8164d7c747c27965313650ea7def3 Mon Sep 17 00:00:00 2001 From: malimova Date: Wed, 13 Dec 2023 15:49:33 +0400 Subject: [PATCH 11/11] for pull request --- AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs | 2 +- AirBomber/AirBomber/FormAdditionalGeneric.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs b/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs index 8d13ede..b004dba 100644 --- a/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs +++ b/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs @@ -60,7 +60,7 @@ Controls.Add(buttonCreate); Controls.Add(pictureBoxObject); Name = "FormAdditionalGeneric"; - Text = "FormAdditionalGeneric"; + Text = "Генерация самолетов"; ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); ResumeLayout(false); } diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.cs b/AirBomber/AirBomber/FormAdditionalGeneric.cs index 326f840..6d1d4a2 100644 --- a/AirBomber/AirBomber/FormAdditionalGeneric.cs +++ b/AirBomber/AirBomber/FormAdditionalGeneric.cs @@ -48,7 +48,7 @@ namespace AirBomber Draw(); } } - + public EntityAirPlane CreateRandomPlane() { Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); -- 2.25.1