From 52117152e00d360fcb323ee41df8465557db5b0f Mon Sep 17 00:00:00 2001 From: goblinrf Date: Sun, 15 Oct 2023 16:11:27 +0300 Subject: [PATCH 1/4] Process --- AirFighter/AirplaneGenericCollection.cs | 93 +++++++++ AirFighter/DrawningAirplane.cs | 2 + AirFighter/FormAirFighter.Designer.cs | 190 ++++++++++-------- AirFighter/FormAirFighter.cs | 90 +++++---- AirFighter/FormAirplaneCollection.Designer.cs | 124 ++++++++++++ AirFighter/FormAirplaneCollection.cs | 69 +++++++ AirFighter/FormAirplaneCollection.resx | 60 ++++++ AirFighter/Program.cs | 2 +- AirFighter/SetGeneric.cs | 60 ++++++ 9 files changed, 571 insertions(+), 119 deletions(-) create mode 100644 AirFighter/AirplaneGenericCollection.cs create mode 100644 AirFighter/FormAirplaneCollection.Designer.cs create mode 100644 AirFighter/FormAirplaneCollection.cs create mode 100644 AirFighter/FormAirplaneCollection.resx create mode 100644 AirFighter/SetGeneric.cs diff --git a/AirFighter/AirplaneGenericCollection.cs b/AirFighter/AirplaneGenericCollection.cs new file mode 100644 index 0000000..06ddda8 --- /dev/null +++ b/AirFighter/AirplaneGenericCollection.cs @@ -0,0 +1,93 @@ +using ProjectAirFighter.MovementStrategy; +using ProjectAirFighter.DrawningObjects; +using System.Drawing; + +namespace ProjectAirFighter.Generics +{ + internal class AirplaneslGenericCollection + where T :DrawningAirplane + where U: IMoveableObject + { + private readonly int _pictureWidth; + + private readonly int _pictureHeight; + + private readonly int _placeSizeWidth = 133; + + private readonly int _placeSizeHeight = 50; + + private readonly SetGeneric _collection; + + public AirplaneslGenericCollection(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 +(AirplaneslGenericCollection collect, T? obj) + { + if (obj == null) + return -1; + return collect?._collection.Insert(obj) ?? -1; + } + + public static bool operator -(AirplaneslGenericCollection collect, int +pos) + { + T? obj = collect._collection.Get(pos); + if (obj != null) + return collect._collection.Remove(pos); + return false; + } + + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + + public Bitmap ShowAirplanes() + { + 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) + { + for (int i = 0; i < _collection.Count; i++) + { + DrawningAirplane airplane = _collection.Get(i); + if (airplane != null) + { + int inRow = _pictureWidth / _placeSizeWidth; + airplane.SetPosition(i % inRow * _placeSizeWidth, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight ); + airplane.DrawTransport(g); + } + } + } + + + } +} diff --git a/AirFighter/DrawningAirplane.cs b/AirFighter/DrawningAirplane.cs index 984c2b3..59d9b6d 100644 --- a/AirFighter/DrawningAirplane.cs +++ b/AirFighter/DrawningAirplane.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using ProjectAirFighter.Entities; +using ProjectAirFighter.MovementStrategy; namespace ProjectAirFighter.DrawningObjects { @@ -24,6 +25,7 @@ namespace ProjectAirFighter.DrawningObjects public int GetPosY => _startPosY; public int GetWidth => _airplaneWidth; public int GetHeight => _airplaneHeight; + public IMoveableObject GetMoveableObject => new DrawningObjectAirplane(this); public DrawningAirplane(int speed, double weight, Color bodyColor,int width, int height) { diff --git a/AirFighter/FormAirFighter.Designer.cs b/AirFighter/FormAirFighter.Designer.cs index 91438ca..24df854 100644 --- a/AirFighter/FormAirFighter.Designer.cs +++ b/AirFighter/FormAirFighter.Designer.cs @@ -1,9 +1,17 @@ -namespace ProjectAirFighter + +namespace ProjectAirFighter { partial class FormAirFighter { + /// + /// 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)) @@ -12,23 +20,25 @@ } 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. + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. /// private void InitializeComponent() { this.pictureBoxAirFighter = new System.Windows.Forms.PictureBox(); - this.ButtonCreateAirFighter = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); + this.buttonAirplane = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); - this.ButtonCreateAirplane = new System.Windows.Forms.Button(); - this.ButtonStep = new System.Windows.Forms.Button(); + this.buttonStep = new System.Windows.Forms.Button(); + this.buttonCreateAirFighter = new System.Windows.Forms.Button(); + this.buttonSelectAirplane = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit(); this.SuspendLayout(); // @@ -42,115 +52,124 @@ this.pictureBoxAirFighter.TabIndex = 0; this.pictureBoxAirFighter.TabStop = false; // - // ButtonCreateAirFighter + // buttonAirplane // - this.ButtonCreateAirFighter.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.ButtonCreateAirFighter.Location = new System.Drawing.Point(0, 405); - this.ButtonCreateAirFighter.Name = "ButtonCreateAirFighter"; - this.ButtonCreateAirFighter.Size = new System.Drawing.Size(144, 48); - this.ButtonCreateAirFighter.TabIndex = 1; - this.ButtonCreateAirFighter.Text = "Создать военный самолёт"; - this.ButtonCreateAirFighter.UseVisualStyleBackColor = true; - this.ButtonCreateAirFighter.Click += new System.EventHandler(this.ButtonCreateAirFighter_Click); - // - // buttonUp - // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.kisspng_up_arrow_computer_icons_arrow_down_clip_art_5af6157c473cb4_0747815015260767962918; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(816, 387); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - this.buttonUp.TabIndex = 2; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); + this.buttonAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonAirplane.Location = new System.Drawing.Point(186, 411); + this.buttonAirplane.Name = "buttonAirplane"; + this.buttonAirplane.Size = new System.Drawing.Size(180, 40); + this.buttonAirplane.TabIndex = 1; + this.buttonAirplane.Text = "Создать"; + this.buttonAirplane.UseVisualStyleBackColor = true; + this.buttonAirplane.Click += new System.EventHandler(this.ButtonCreateAirplane_Click); // // buttonLeft // this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.png_clipart_computer_icons_graphics_arrow_symbol_arrow_angle_desktop_wallpaper; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(780, 424); + this.buttonLeft.Location = new System.Drawing.Point(768, 411); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); - this.buttonLeft.TabIndex = 3; + this.buttonLeft.TabIndex = 2; this.buttonLeft.UseVisualStyleBackColor = true; - this.buttonLeft.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.BackgroundImage = global::AirFighter.Properties.Resources.png_clipart_computer_icons_uma_musume_pretty_derby_fate_grand_order_saber_kemono_friends_three_arrow_game_angle; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(816, 424); - 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); + this.buttonLeft.Click += new System.EventHandler(this.ButtonMoveClick); // // buttonRight // this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.png_transparent_grammatical_person_paper_narration_direzione_didattica_statale_gestione_scuola_elementare_copy_print_right_arrow_miscellaneous_game_angle; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(852, 423); + this.buttonRight.Location = new System.Drawing.Point(840, 411); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 5; + this.buttonRight.TabIndex = 3; this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); + this.buttonRight.Click += new System.EventHandler(this.ButtonMoveClick); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.kisspng_up_arrow_computer_icons_arrow_down_clip_art_5af6157c473cb4_0747815015260767962918; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp.Location = new System.Drawing.Point(804, 375); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 4; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMoveClick); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.png_clipart_computer_icons_uma_musume_pretty_derby_fate_grand_order_saber_kemono_friends_three_arrow_game_angle; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown.Location = new System.Drawing.Point(804, 411); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 5; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMoveClick); // // comboBoxStrategy // this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxStrategy.FormattingEnabled = true; this.comboBoxStrategy.Items.AddRange(new object[] { - "0", - "1"}); - this.comboBoxStrategy.Location = new System.Drawing.Point(731, 0); + "Довести до центра", + "Довести до края"}); + this.comboBoxStrategy.Location = new System.Drawing.Point(719, 12); this.comboBoxStrategy.Name = "comboBoxStrategy"; this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28); this.comboBoxStrategy.TabIndex = 6; // - // ButtonCreateAirplane + // buttonStep // - this.ButtonCreateAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.ButtonCreateAirplane.Location = new System.Drawing.Point(150, 405); - this.ButtonCreateAirplane.Name = "ButtonCreateAirplane"; - this.ButtonCreateAirplane.Size = new System.Drawing.Size(143, 47); - this.ButtonCreateAirplane.TabIndex = 7; - this.ButtonCreateAirplane.Text = "Создать самолёт"; - this.ButtonCreateAirplane.UseVisualStyleBackColor = true; - this.ButtonCreateAirplane.Click += new System.EventHandler(this.ButtonCreateAirplane_Click); + this.buttonStep.Location = new System.Drawing.Point(768, 46); + this.buttonStep.Name = "buttonStep"; + this.buttonStep.Size = new System.Drawing.Size(94, 29); + this.buttonStep.TabIndex = 7; + this.buttonStep.Text = "Шаг"; + this.buttonStep.UseVisualStyleBackColor = true; + this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click); // - // ButtonStep + // buttonCreateAirFighter // - this.ButtonStep.Location = new System.Drawing.Point(788, 34); - this.ButtonStep.Name = "ButtonStep"; - this.ButtonStep.Size = new System.Drawing.Size(94, 29); - this.ButtonStep.TabIndex = 8; - this.ButtonStep.Text = "Шаг"; - this.ButtonStep.UseVisualStyleBackColor = true; - this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click); + this.buttonCreateAirFighter.Location = new System.Drawing.Point(0, 411); + this.buttonCreateAirFighter.Name = "buttonCreateAirFighter"; + this.buttonCreateAirFighter.Size = new System.Drawing.Size(180, 40); + this.buttonCreateAirFighter.TabIndex = 8; + this.buttonCreateAirFighter.Text = "Создать продвинутый"; + this.buttonCreateAirFighter.UseVisualStyleBackColor = true; + this.buttonCreateAirFighter.Click += new System.EventHandler(this.ButtonCreateAirFighter_Click); + // + // buttonSelectAirplane + // + this.buttonSelectAirplane.Location = new System.Drawing.Point(372, 411); + this.buttonSelectAirplane.Name = "buttonSelectAirplane"; + this.buttonSelectAirplane.Size = new System.Drawing.Size(180, 40); + this.buttonSelectAirplane.TabIndex = 9; + this.buttonSelectAirplane.Text = "Выбрать"; + this.buttonSelectAirplane.UseVisualStyleBackColor = true; + this.buttonSelectAirplane.Click += new System.EventHandler(this.buttonSelectAirplane_Click); // // FormAirFighter // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(882, 453); - this.Controls.Add(this.ButtonStep); - this.Controls.Add(this.ButtonCreateAirplane); + this.Controls.Add(this.buttonSelectAirplane); + this.Controls.Add(this.buttonCreateAirFighter); + this.Controls.Add(this.buttonStep); this.Controls.Add(this.comboBoxStrategy); - this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonUp); - this.Controls.Add(this.ButtonCreateAirFighter); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonAirplane); this.Controls.Add(this.pictureBoxAirFighter); this.Name = "FormAirFighter"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "FormAirFighter"; + this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -158,14 +177,17 @@ } #endregion - private PictureBox pictureBoxAirFighter; - private Button ButtonCreateAirFighter; - private Button buttonUp; - private Button buttonLeft; - private Button buttonDown; - private Button buttonRight; - private ComboBox comboBoxStrategy; - private Button ButtonCreateAirplane; - private Button ButtonStep; + + private System.Windows.Forms.PictureBox pictureBoxAirFighter; + private System.Windows.Forms.Button buttonAirplane; + private System.Windows.Forms.Button buttonLeft; + private System.Windows.Forms.Button buttonRight; + private System.Windows.Forms.Button buttonUp; + private System.Windows.Forms.Button buttonDown; + public System.Windows.Forms.ComboBox comboBoxStrategy; + private System.Windows.Forms.Button buttonStep; + private System.Windows.Forms.Button buttonCreateAirFighter; + private System.Windows.Forms.Button buttonSelectAirplane; } -} \ No newline at end of file +} + diff --git a/AirFighter/FormAirFighter.cs b/AirFighter/FormAirFighter.cs index c1d6bfa..ae50fa6 100644 --- a/AirFighter/FormAirFighter.cs +++ b/AirFighter/FormAirFighter.cs @@ -1,26 +1,38 @@ -using ProjectAirFighter.MovementStrategy; +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; using ProjectAirFighter.DrawningObjects; +using ProjectAirFighter.MovementStrategy; namespace ProjectAirFighter { public partial class FormAirFighter : Form { + private DrawningAirplane? _drawningAirplane; + private AbstractStrategy? _abstractStrategy; + public DrawningAirplane? SelectedAirplane { get; private set; } public FormAirFighter() { InitializeComponent(); + _abstractStrategy = null; + SelectedAirplane = null; } private void Draw() { if (_drawningAirplane == null) - { return; - } - Bitmap bmp = new(pictureBoxAirFighter.Width, - pictureBoxAirFighter.Height); + + Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); Graphics gr = Graphics.FromImage(bmp); _drawningAirplane.DrawTransport(gr); pictureBoxAirFighter.Image = bmp; @@ -29,34 +41,24 @@ namespace ProjectAirFighter 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)), - pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); + Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + bodyColor = dialog.Color; + } + _drawningAirplane = new DrawningAirplane(random.Next(100, 300), random.Next(1000, 3000), + bodyColor,pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); _drawningAirplane.SetPosition(random.Next(10, 100), random.Next(70, 100)); - - Draw(); - } - private void ButtonCreateAirFighter_Click(object sender, EventArgs e) - { - Random random = new(); - _drawningAirplane = 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)), - pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); - _drawningAirplane.SetPosition(random.Next(10, 100), random.Next(70, 100)); Draw(); } - private void buttonMove_Click(object sender, EventArgs e) + private void ButtonMoveClick(object sender, EventArgs e) { if (_drawningAirplane == null) - { return; - } + string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { @@ -66,22 +68,38 @@ namespace ProjectAirFighter case "buttonDown": _drawningAirplane.MoveTransport(DirectionType.Down); break; - case "buttonLeft": - _drawningAirplane.MoveTransport(DirectionType.Left); - break; case "buttonRight": _drawningAirplane.MoveTransport(DirectionType.Right); break; + case "buttonLeft": + _drawningAirplane.MoveTransport(DirectionType.Left); + break; } Draw(); } - private void ButtonStep_Click(object sender, EventArgs e) + private void ButtonCreateAirFighter_Click(object sender, EventArgs e) + { + Random random = new(); + Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + bodyColor = dialog.Color; + if (dialog.ShowDialog() == DialogResult.OK) + additionalColor = dialog.Color; + + _drawningAirplane = new DrawningAirFighter(random.Next(100, 300), random.Next(1000, 3000), + bodyColor,additionalColor, Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); + _drawningAirplane.SetPosition(random.Next(10, 100), random.Next(70, 100)); + Draw(); + } + + private void buttonStep_Click(object sender, EventArgs e) { if (_drawningAirplane == null) - { return; - } if (comboBoxStrategy.Enabled) { _abstractStrategy = comboBoxStrategy.SelectedIndex @@ -112,7 +130,11 @@ namespace ProjectAirFighter _abstractStrategy = null; } } + + private void buttonSelectAirplane_Click(object sender, EventArgs e) + { + SelectedAirplane = _drawningAirplane; + DialogResult = DialogResult.OK; + } } } - - diff --git a/AirFighter/FormAirplaneCollection.Designer.cs b/AirFighter/FormAirplaneCollection.Designer.cs new file mode 100644 index 0000000..3fd6fe6 --- /dev/null +++ b/AirFighter/FormAirplaneCollection.Designer.cs @@ -0,0 +1,124 @@ +namespace ProjectAirFighter +{ + partial class FormAirplaneCollection + { + /// + /// 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.toolGroupBox = new System.Windows.Forms.GroupBox(); + this.maskedTextBox = new System.Windows.Forms.MaskedTextBox(); + this.updateCollectionButton = new System.Windows.Forms.Button(); + this.deleteAirplaneButton = new System.Windows.Forms.Button(); + this.addAirplaneButton = new System.Windows.Forms.Button(); + this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); + this.toolGroupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); + this.SuspendLayout(); + // + // toolGroupBox + // + this.toolGroupBox.Controls.Add(this.maskedTextBox); + this.toolGroupBox.Controls.Add(this.updateCollectionButton); + this.toolGroupBox.Controls.Add(this.deleteAirplaneButton); + this.toolGroupBox.Controls.Add(this.addAirplaneButton); + this.toolGroupBox.Location = new System.Drawing.Point(623, 12); + this.toolGroupBox.Name = "toolGroupBox"; + this.toolGroupBox.Size = new System.Drawing.Size(227, 426); + this.toolGroupBox.TabIndex = 0; + this.toolGroupBox.TabStop = false; + this.toolGroupBox.Text = "Инструменты"; + // + // maskedTextBox + // + this.maskedTextBox.Location = new System.Drawing.Point(6, 72); + this.maskedTextBox.Name = "maskedTextBox"; + this.maskedTextBox.Size = new System.Drawing.Size(125, 27); + this.maskedTextBox.TabIndex = 4; + // + // updateCollectionButton + // + this.updateCollectionButton.Location = new System.Drawing.Point(6, 151); + this.updateCollectionButton.Name = "updateCollectionButton"; + this.updateCollectionButton.Size = new System.Drawing.Size(215, 40); + this.updateCollectionButton.TabIndex = 3; + this.updateCollectionButton.Text = "Обновить коллекцию"; + this.updateCollectionButton.UseVisualStyleBackColor = true; + this.updateCollectionButton.Click += new System.EventHandler(this.updateCollectionButton_Click); + // + // deleteAirplaneButton + // + this.deleteAirplaneButton.Location = new System.Drawing.Point(6, 105); + this.deleteAirplaneButton.Name = "deleteAirplaneButton"; + this.deleteAirplaneButton.Size = new System.Drawing.Size(215, 40); + this.deleteAirplaneButton.TabIndex = 2; + this.deleteAirplaneButton.Text = "Удалить"; + this.deleteAirplaneButton.UseVisualStyleBackColor = true; + this.deleteAirplaneButton.Click += new System.EventHandler(this.deleteAirplaneButton_Click); + // + // addAirplaneButton + // + this.addAirplaneButton.Location = new System.Drawing.Point(6, 26); + this.addAirplaneButton.Name = "addAirplaneButton"; + this.addAirplaneButton.Size = new System.Drawing.Size(215, 40); + this.addAirplaneButton.TabIndex = 0; + this.addAirplaneButton.Text = "Добавить"; + this.addAirplaneButton.UseVisualStyleBackColor = true; + this.addAirplaneButton.Click += new System.EventHandler(this.addAirplaneButton_Click); + // + // pictureBoxCollection + // + this.pictureBoxCollection.Location = new System.Drawing.Point(12, 12); + this.pictureBoxCollection.Name = "pictureBoxCollection"; + this.pictureBoxCollection.Size = new System.Drawing.Size(605, 426); + this.pictureBoxCollection.TabIndex = 1; + this.pictureBoxCollection.TabStop = false; + // + // FormAirplaneCollection + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(862, 450); + this.Controls.Add(this.pictureBoxCollection); + this.Controls.Add(this.toolGroupBox); + this.Name = "FormAirplaneCollection"; + this.Text = "FormMonorailCollection"; + this.toolGroupBox.ResumeLayout(false); + this.toolGroupBox.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox toolGroupBox; + private System.Windows.Forms.Button updateCollectionButton; + private System.Windows.Forms.Button deleteAirplaneButton; + private System.Windows.Forms.Button addAirplaneButton; + private System.Windows.Forms.PictureBox pictureBoxCollection; + private System.Windows.Forms.MaskedTextBox maskedTextBox; + } +} \ No newline at end of file diff --git a/AirFighter/FormAirplaneCollection.cs b/AirFighter/FormAirplaneCollection.cs new file mode 100644 index 0000000..e44e628 --- /dev/null +++ b/AirFighter/FormAirplaneCollection.cs @@ -0,0 +1,69 @@ +using ProjectAirFighter.DrawningObjects; +using ProjectAirFighter.Generics; +using ProjectAirFighter.MovementStrategy; +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 ProjectAirFighter +{ + public partial class FormAirplaneCollection : Form + { + private readonly AirplaneslGenericCollection _airplanes; + + public FormAirplaneCollection() + { + InitializeComponent(); + _airplanes = new AirplaneslGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + private void deleteAirplaneButton_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", +MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_airplanes - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _airplanes.ShowAirplanes(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void updateCollectionButton_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _airplanes.ShowAirplanes(); + + } + + private void addAirplaneButton_Click(object sender, EventArgs e) + { + FormAirFighter form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_airplanes + form.SelectedAirplane != null) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _airplanes.ShowAirplanes(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + + } + } + } +} diff --git a/AirFighter/FormAirplaneCollection.resx b/AirFighter/FormAirplaneCollection.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AirFighter/FormAirplaneCollection.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 diff --git a/AirFighter/Program.cs b/AirFighter/Program.cs index e7a24a0..7511a58 100644 --- a/AirFighter/Program.cs +++ b/AirFighter/Program.cs @@ -9,7 +9,7 @@ namespace ProjectAirFighter { ApplicationConfiguration.Initialize(); - Application.Run(new FormAirFighter()); + Application.Run(new FormAirplaneCollection()); } } } \ No newline at end of file diff --git a/AirFighter/SetGeneric.cs b/AirFighter/SetGeneric.cs new file mode 100644 index 0000000..15bf012 --- /dev/null +++ b/AirFighter/SetGeneric.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirFighter.Generics +{ + 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 airplane) + { + if (_places[Count-1] != null) + return -1; + return Insert(airplane, 0); + } + + public int Insert(T airplane, int position) + { + if (!(position >= 0 && position < Count)) + return -1; + if (_places[position] != null) + { + int ind = position; + while (ind < Count && _places[ind] != null) + ind++; + if (ind == Count) + return -1; + for (int i = ind - 1; i >= position; i--) + _places[i + 1] = _places[i]; + } + _places[position] = airplane; + return position; + } + 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 5df793cdbd16d8e80096991886aa5c56dc768fa9 Mon Sep 17 00:00:00 2001 From: goblinrf Date: Sun, 15 Oct 2023 20:41:44 +0300 Subject: [PATCH 2/4] Done --- AirFighter/AirplaneGenericCollection.cs | 16 +++++++++++++--- AirFighter/FormAirplaneCollection.Designer.cs | 16 ++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/AirFighter/AirplaneGenericCollection.cs b/AirFighter/AirplaneGenericCollection.cs index 06ddda8..3b6b40c 100644 --- a/AirFighter/AirplaneGenericCollection.cs +++ b/AirFighter/AirplaneGenericCollection.cs @@ -12,9 +12,9 @@ namespace ProjectAirFighter.Generics private readonly int _pictureHeight; - private readonly int _placeSizeWidth = 133; + private readonly int _placeSizeWidth = 166; - private readonly int _placeSizeHeight = 50; + private readonly int _placeSizeHeight = 160; private readonly SetGeneric _collection; @@ -76,15 +76,25 @@ pos) private void DrawObjects(Graphics g) { + int c = 0,r = _pictureHeight/_placeSizeHeight; + for (int i = 0; i < _collection.Count; i++) { DrawningAirplane airplane = _collection.Get(i); if (airplane != null) { int inRow = _pictureWidth / _placeSizeWidth; - airplane.SetPosition(i % inRow * _placeSizeWidth, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight ); + airplane.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth), (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight + (_placeSizeHeight - _placeSizeHeight * 125 / 1000) / 2); airplane.DrawTransport(g); + + c++; + if (c - 1 == inRow) + { + c = 0; + r--; + } } + } } diff --git a/AirFighter/FormAirplaneCollection.Designer.cs b/AirFighter/FormAirplaneCollection.Designer.cs index 3fd6fe6..610e73c 100644 --- a/AirFighter/FormAirplaneCollection.Designer.cs +++ b/AirFighter/FormAirplaneCollection.Designer.cs @@ -44,23 +44,23 @@ this.toolGroupBox.Controls.Add(this.updateCollectionButton); this.toolGroupBox.Controls.Add(this.deleteAirplaneButton); this.toolGroupBox.Controls.Add(this.addAirplaneButton); - this.toolGroupBox.Location = new System.Drawing.Point(623, 12); + this.toolGroupBox.Location = new System.Drawing.Point(688, 12); this.toolGroupBox.Name = "toolGroupBox"; - this.toolGroupBox.Size = new System.Drawing.Size(227, 426); + this.toolGroupBox.Size = new System.Drawing.Size(251, 426); this.toolGroupBox.TabIndex = 0; this.toolGroupBox.TabStop = false; this.toolGroupBox.Text = "Инструменты"; // // maskedTextBox // - this.maskedTextBox.Location = new System.Drawing.Point(6, 72); + this.maskedTextBox.Location = new System.Drawing.Point(20, 72); this.maskedTextBox.Name = "maskedTextBox"; this.maskedTextBox.Size = new System.Drawing.Size(125, 27); this.maskedTextBox.TabIndex = 4; // // updateCollectionButton // - this.updateCollectionButton.Location = new System.Drawing.Point(6, 151); + this.updateCollectionButton.Location = new System.Drawing.Point(20, 151); this.updateCollectionButton.Name = "updateCollectionButton"; this.updateCollectionButton.Size = new System.Drawing.Size(215, 40); this.updateCollectionButton.TabIndex = 3; @@ -70,7 +70,7 @@ // // deleteAirplaneButton // - this.deleteAirplaneButton.Location = new System.Drawing.Point(6, 105); + this.deleteAirplaneButton.Location = new System.Drawing.Point(20, 105); this.deleteAirplaneButton.Name = "deleteAirplaneButton"; this.deleteAirplaneButton.Size = new System.Drawing.Size(215, 40); this.deleteAirplaneButton.TabIndex = 2; @@ -80,7 +80,7 @@ // // addAirplaneButton // - this.addAirplaneButton.Location = new System.Drawing.Point(6, 26); + this.addAirplaneButton.Location = new System.Drawing.Point(20, 26); this.addAirplaneButton.Name = "addAirplaneButton"; this.addAirplaneButton.Size = new System.Drawing.Size(215, 40); this.addAirplaneButton.TabIndex = 0; @@ -92,7 +92,7 @@ // this.pictureBoxCollection.Location = new System.Drawing.Point(12, 12); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(605, 426); + this.pictureBoxCollection.Size = new System.Drawing.Size(670, 426); this.pictureBoxCollection.TabIndex = 1; this.pictureBoxCollection.TabStop = false; // @@ -100,7 +100,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(862, 450); + this.ClientSize = new System.Drawing.Size(951, 446); this.Controls.Add(this.pictureBoxCollection); this.Controls.Add(this.toolGroupBox); this.Name = "FormAirplaneCollection"; -- 2.25.1 From 3a3f6a02cac4082d367ad955e064dafdeaad417d Mon Sep 17 00:00:00 2001 From: goblinrf Date: Mon, 16 Oct 2023 17:52:57 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/SetGeneric.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/AirFighter/SetGeneric.cs b/AirFighter/SetGeneric.cs index 15bf012..b0b4df6 100644 --- a/AirFighter/SetGeneric.cs +++ b/AirFighter/SetGeneric.cs @@ -20,8 +20,6 @@ namespace ProjectAirFighter.Generics public int Insert(T airplane) { - if (_places[Count-1] != null) - return -1; return Insert(airplane, 0); } -- 2.25.1 From 4db70b6db92887075935821dda79969accba35d2 Mon Sep 17 00:00:00 2001 From: goblinrf Date: Thu, 19 Oct 2023 21:57:34 +0300 Subject: [PATCH 4/4] YES --- AirFighter/AirplaneGenericCollection.cs | 2 +- AirFighter/FormAirplaneCollection.Designer.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/AirFighter/AirplaneGenericCollection.cs b/AirFighter/AirplaneGenericCollection.cs index 3b6b40c..265f7ea 100644 --- a/AirFighter/AirplaneGenericCollection.cs +++ b/AirFighter/AirplaneGenericCollection.cs @@ -84,7 +84,7 @@ pos) if (airplane != null) { int inRow = _pictureWidth / _placeSizeWidth; - airplane.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth), (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight + (_placeSizeHeight - _placeSizeHeight * 125 / 1000) / 2); + airplane.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeWidth /10 * 2 , (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight + (_placeSizeHeight - _placeSizeHeight * 170 / 1000) / 2); airplane.DrawTransport(g); c++; diff --git a/AirFighter/FormAirplaneCollection.Designer.cs b/AirFighter/FormAirplaneCollection.Designer.cs index 610e73c..2d4653f 100644 --- a/AirFighter/FormAirplaneCollection.Designer.cs +++ b/AirFighter/FormAirplaneCollection.Designer.cs @@ -44,23 +44,23 @@ this.toolGroupBox.Controls.Add(this.updateCollectionButton); this.toolGroupBox.Controls.Add(this.deleteAirplaneButton); this.toolGroupBox.Controls.Add(this.addAirplaneButton); - this.toolGroupBox.Location = new System.Drawing.Point(688, 12); + this.toolGroupBox.Location = new System.Drawing.Point(716, 12); this.toolGroupBox.Name = "toolGroupBox"; - this.toolGroupBox.Size = new System.Drawing.Size(251, 426); + this.toolGroupBox.Size = new System.Drawing.Size(223, 426); this.toolGroupBox.TabIndex = 0; this.toolGroupBox.TabStop = false; this.toolGroupBox.Text = "Инструменты"; // // maskedTextBox // - this.maskedTextBox.Location = new System.Drawing.Point(20, 72); + this.maskedTextBox.Location = new System.Drawing.Point(8, 72); this.maskedTextBox.Name = "maskedTextBox"; this.maskedTextBox.Size = new System.Drawing.Size(125, 27); this.maskedTextBox.TabIndex = 4; // // updateCollectionButton // - this.updateCollectionButton.Location = new System.Drawing.Point(20, 151); + this.updateCollectionButton.Location = new System.Drawing.Point(6, 151); this.updateCollectionButton.Name = "updateCollectionButton"; this.updateCollectionButton.Size = new System.Drawing.Size(215, 40); this.updateCollectionButton.TabIndex = 3; @@ -70,7 +70,7 @@ // // deleteAirplaneButton // - this.deleteAirplaneButton.Location = new System.Drawing.Point(20, 105); + this.deleteAirplaneButton.Location = new System.Drawing.Point(6, 105); this.deleteAirplaneButton.Name = "deleteAirplaneButton"; this.deleteAirplaneButton.Size = new System.Drawing.Size(215, 40); this.deleteAirplaneButton.TabIndex = 2; @@ -80,7 +80,7 @@ // // addAirplaneButton // - this.addAirplaneButton.Location = new System.Drawing.Point(20, 26); + this.addAirplaneButton.Location = new System.Drawing.Point(8, 26); this.addAirplaneButton.Name = "addAirplaneButton"; this.addAirplaneButton.Size = new System.Drawing.Size(215, 40); this.addAirplaneButton.TabIndex = 0; @@ -92,7 +92,7 @@ // this.pictureBoxCollection.Location = new System.Drawing.Point(12, 12); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(670, 426); + this.pictureBoxCollection.Size = new System.Drawing.Size(698, 426); this.pictureBoxCollection.TabIndex = 1; this.pictureBoxCollection.TabStop = false; // -- 2.25.1