diff --git a/Airbus/Drawnings/DrawningAirbus.cs b/Airbus/Drawnings/DrawningAirbus.cs index 73d7d20..1076fd9 100644 --- a/Airbus/Drawnings/DrawningAirbus.cs +++ b/Airbus/Drawnings/DrawningAirbus.cs @@ -4,10 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using ProjectAirbus.Entities; +using ProjectAirbus.MovementStrategy; namespace ProjectAirbus.Drawnings { - internal class DrawningAirbus + public class DrawningAirbus { public EntityAirbus? EntityAirbus { get; protected set; } private int _pictureWidth; @@ -19,6 +20,9 @@ namespace ProjectAirbus.Drawnings protected readonly int _airbusWidth = 89; protected readonly int _airbusHeight = 34; + // Получение объекта IMoveableObject из объекта DrawningCar + public IMoveableObject GetMoveableObject => new DrawningObjectAirbus(this); + // доработки для интерфейса public int GetPosX => _startPosX; public int GetPosY => _startPosY; @@ -151,6 +155,5 @@ namespace ProjectAirbus.Drawnings g.DrawEllipse(pen, _startPosX, _startPosY + 14, 14, 5); g.FillEllipse(brYellow, _startPosX, _startPosY + 14, 14, 5); } - } } diff --git a/Airbus/Drawnings/DrawningPlane.cs b/Airbus/Drawnings/DrawningPlane.cs index 7cb7fe5..31440b0 100644 --- a/Airbus/Drawnings/DrawningPlane.cs +++ b/Airbus/Drawnings/DrawningPlane.cs @@ -7,7 +7,7 @@ using ProjectAirbus.Entities; namespace ProjectAirbus.Drawnings { - internal class DrawningPlane : DrawningAirbus + public class DrawningPlane : DrawningAirbus { public DrawningPlane(int speed, double weight, Color bodyColor, Color additionalColor,bool isCompartment, bool isAdditionalEngine, int width, int height) : base (speed, weight, bodyColor, width, height, 110, 60) diff --git a/Airbus/Entities/EntityAirbus.cs b/Airbus/Entities/EntityAirbus.cs index a2007f8..16bf834 100644 --- a/Airbus/Entities/EntityAirbus.cs +++ b/Airbus/Entities/EntityAirbus.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace ProjectAirbus.Entities { - internal class EntityAirbus + public class EntityAirbus { public int Speed { get; private set; } public double Weight { get; private set; } diff --git a/Airbus/Entities/EntityPlane.cs b/Airbus/Entities/EntityPlane.cs index 165c56b..3273514 100644 --- a/Airbus/Entities/EntityPlane.cs +++ b/Airbus/Entities/EntityPlane.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ProjectAirbus.Entities { - internal class EntityPlane : EntityAirbus + public class EntityPlane : EntityAirbus { public Color AdditionalColor { get; private set; } public bool IsCompartment { get; private set; } diff --git a/Airbus/FormAirbus.Designer.cs b/Airbus/FormAirbus.Designer.cs deleted file mode 100644 index c97f636..0000000 --- a/Airbus/FormAirbus.Designer.cs +++ /dev/null @@ -1,188 +0,0 @@ -namespace ProjectAirbus -{ - partial class FormAirbus - { - /// - /// 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() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormAirbus)); - pictureAirBus=new PictureBox(); - buttonUp=new Button(); - buttonLeft=new Button(); - buttonDown=new Button(); - buttonRight=new Button(); - buttonCreate=new Button(); - buttonCreateSuperAirbus=new Button(); - buttonStep=new Button(); - comboBoxStrategy=new ComboBox(); - ((System.ComponentModel.ISupportInitialize)pictureAirBus).BeginInit(); - SuspendLayout(); - // - // pictureAirBus - // - pictureAirBus.Dock=DockStyle.Fill; - pictureAirBus.Location=new Point(0, 0); - pictureAirBus.Name="pictureAirBus"; - pictureAirBus.Size=new Size(790, 410); - pictureAirBus.SizeMode=PictureBoxSizeMode.AutoSize; - pictureAirBus.TabIndex=0; - pictureAirBus.TabStop=false; - // - // buttonUp - // - buttonUp.Anchor=AnchorStyles.Bottom|AnchorStyles.Right; - buttonUp.BackgroundImage=(Image)resources.GetObject("buttonUp.BackgroundImage"); - buttonUp.BackgroundImageLayout=ImageLayout.Stretch; - buttonUp.FlatAppearance.BorderColor=Color.Black; - buttonUp.FlatAppearance.BorderSize=7; - buttonUp.Location=new Point(679, 309); - buttonUp.Name="buttonUp"; - buttonUp.Size=new Size(48, 44); - buttonUp.TabIndex=1; - buttonUp.UseVisualStyleBackColor=true; - buttonUp.Click+=buttonMove_Click; - // - // buttonLeft - // - buttonLeft.Anchor=AnchorStyles.Bottom|AnchorStyles.Right; - buttonLeft.BackColor=SystemColors.Control; - buttonLeft.BackgroundImage=(Image)resources.GetObject("buttonLeft.BackgroundImage"); - buttonLeft.BackgroundImageLayout=ImageLayout.Stretch; - buttonLeft.FlatAppearance.BorderColor=Color.Black; - buttonLeft.FlatAppearance.BorderSize=7; - buttonLeft.Location=new Point(630, 354); - buttonLeft.Name="buttonLeft"; - buttonLeft.Size=new Size(48, 44); - buttonLeft.TabIndex=2; - buttonLeft.UseVisualStyleBackColor=false; - buttonLeft.Click+=buttonMove_Click; - // - // buttonDown - // - buttonDown.Anchor=AnchorStyles.Bottom|AnchorStyles.Right; - buttonDown.BackgroundImage=(Image)resources.GetObject("buttonDown.BackgroundImage"); - buttonDown.BackgroundImageLayout=ImageLayout.Stretch; - buttonDown.FlatAppearance.BorderColor=Color.Black; - buttonDown.FlatAppearance.BorderSize=7; - buttonDown.Location=new Point(679, 354); - buttonDown.Name="buttonDown"; - buttonDown.Size=new Size(48, 44); - buttonDown.TabIndex=3; - buttonDown.UseVisualStyleBackColor=true; - buttonDown.Click+=buttonMove_Click; - // - // buttonRight - // - buttonRight.Anchor=AnchorStyles.Bottom|AnchorStyles.Right; - buttonRight.BackgroundImage=(Image)resources.GetObject("buttonRight.BackgroundImage"); - buttonRight.BackgroundImageLayout=ImageLayout.Stretch; - buttonRight.FlatAppearance.BorderColor=Color.Black; - buttonRight.FlatAppearance.BorderSize=7; - buttonRight.Location=new Point(728, 354); - buttonRight.Name="buttonRight"; - buttonRight.Size=new Size(48, 44); - buttonRight.TabIndex=4; - buttonRight.UseVisualStyleBackColor=true; - buttonRight.Click+=buttonMove_Click; - // - // buttonCreate - // - buttonCreate.Anchor=AnchorStyles.Bottom|AnchorStyles.Left; - buttonCreate.Location=new Point(12, 347); - buttonCreate.Name="buttonCreate"; - buttonCreate.Size=new Size(128, 51); - buttonCreate.TabIndex=5; - buttonCreate.Text="Создать самолёт"; - buttonCreate.UseVisualStyleBackColor=true; - buttonCreate.Click+=buttonCreate_Click; - // - // buttonCreateSuperAirbus - // - buttonCreateSuperAirbus.Anchor=AnchorStyles.Bottom|AnchorStyles.Left; - buttonCreateSuperAirbus.Location=new Point(146, 347); - buttonCreateSuperAirbus.Name="buttonCreateSuperAirbus"; - buttonCreateSuperAirbus.Size=new Size(127, 51); - buttonCreateSuperAirbus.TabIndex=6; - buttonCreateSuperAirbus.Text="Создать суперсамолёт"; - buttonCreateSuperAirbus.UseVisualStyleBackColor=true; - buttonCreateSuperAirbus.Click+=buttonCreateSuperAirbus_Click; - // - // buttonStep - // - buttonStep.Anchor=AnchorStyles.Top|AnchorStyles.Right; - buttonStep.Location=new Point(671, 51); - buttonStep.Name="buttonStep"; - buttonStep.Size=new Size(105, 37); - buttonStep.TabIndex=7; - buttonStep.Text="Шаг"; - buttonStep.UseVisualStyleBackColor=true; - buttonStep.Click+=buttonStep_Click; - // - // comboBoxStrategy - // - comboBoxStrategy.Anchor=AnchorStyles.Top|AnchorStyles.Right; - comboBoxStrategy.DropDownStyle=ComboBoxStyle.DropDownList; - comboBoxStrategy.FormattingEnabled=true; - comboBoxStrategy.Items.AddRange(new object[] { "1", "2" }); - comboBoxStrategy.Location=new Point(622, 22); - comboBoxStrategy.Name="comboBoxStrategy"; - comboBoxStrategy.Size=new Size(156, 23); - comboBoxStrategy.TabIndex=8; - // - // Form1 - // - AutoScaleDimensions=new SizeF(7F, 15F); - AutoScaleMode=AutoScaleMode.Font; - ClientSize=new Size(790, 410); - Controls.Add(comboBoxStrategy); - Controls.Add(buttonStep); - Controls.Add(buttonCreateSuperAirbus); - Controls.Add(buttonCreate); - Controls.Add(buttonRight); - Controls.Add(buttonDown); - Controls.Add(buttonLeft); - Controls.Add(buttonUp); - Controls.Add(pictureAirBus); - Name="Form1"; - Text="FormAirbus"; - ((System.ComponentModel.ISupportInitialize)pictureAirBus).EndInit(); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private PictureBox pictureAirBus; - private Button buttonUp; - private Button buttonLeft; - private Button buttonDown; - private Button buttonRight; - private Button buttonCreate; - private Button buttonCreateSuperAirbus; - private Button buttonStep; - private ComboBox comboBoxStrategy; - } -} \ No newline at end of file diff --git a/Airbus/FormAirbusCollection.Designer.cs b/Airbus/FormAirbusCollection.Designer.cs new file mode 100644 index 0000000..7403280 --- /dev/null +++ b/Airbus/FormAirbusCollection.Designer.cs @@ -0,0 +1,128 @@ +namespace ProjectAirbus +{ + partial class FormAirbusCollection + { + /// + /// 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() + { + buttonAdd=new Button(); + pictureBoxCollection=new PictureBox(); + labelInstruments=new Label(); + buttonUpdate=new Button(); + buttonDelete=new Button(); + colorDialog=new ColorDialog(); + maskedTextBoxNumber=new MaskedTextBox(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); + SuspendLayout(); + // + // buttonAdd + // + buttonAdd.Anchor=AnchorStyles.Top|AnchorStyles.Right; + buttonAdd.Location=new Point(457, 34); + buttonAdd.Name="buttonAdd"; + buttonAdd.Size=new Size(137, 28); + buttonAdd.TabIndex=0; + buttonAdd.Text="Добавить самолёт"; + buttonAdd.UseVisualStyleBackColor=true; + buttonAdd.Click+=buttonAdd_Click; + // + // pictureBoxCollection + // + pictureBoxCollection.Location=new Point(0, 0); + pictureBoxCollection.Name="pictureBoxCollection"; + pictureBoxCollection.Size=new Size(424, 453); + pictureBoxCollection.TabIndex=1; + pictureBoxCollection.TabStop=false; + // + // labelInstruments + // + labelInstruments.Anchor=AnchorStyles.Top|AnchorStyles.Right; + labelInstruments.AutoSize=true; + labelInstruments.Location=new Point(449, 9); + labelInstruments.Name="labelInstruments"; + labelInstruments.Size=new Size(83, 15); + labelInstruments.TabIndex=2; + labelInstruments.Text="Инструменты"; + // + // buttonUpdate + // + buttonUpdate.Anchor=AnchorStyles.Top|AnchorStyles.Right; + buttonUpdate.Location=new Point(457, 212); + buttonUpdate.Name="buttonUpdate"; + buttonUpdate.Size=new Size(137, 28); + buttonUpdate.TabIndex=3; + buttonUpdate.Text="Обновить коллекцию"; + buttonUpdate.UseVisualStyleBackColor=true; + buttonUpdate.Click+=buttonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Anchor=AnchorStyles.Top|AnchorStyles.Right; + buttonDelete.Location=new Point(457, 140); + buttonDelete.Name="buttonDelete"; + buttonDelete.Size=new Size(137, 28); + buttonDelete.TabIndex=4; + buttonDelete.Text="Удалить самолёт"; + buttonDelete.UseVisualStyleBackColor=true; + buttonDelete.Click+=buttonDelete_Click; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Anchor=AnchorStyles.Top|AnchorStyles.Right; + maskedTextBoxNumber.Location=new Point(457, 111); + maskedTextBoxNumber.Name="maskedTextBoxNumber"; + maskedTextBoxNumber.Size=new Size(100, 23); + maskedTextBoxNumber.TabIndex=5; + // + // FormAirbusCollection + // + AutoScaleDimensions=new SizeF(7F, 15F); + AutoScaleMode=AutoScaleMode.Font; + ClientSize=new Size(607, 455); + Controls.Add(buttonAdd); + Controls.Add(maskedTextBoxNumber); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(labelInstruments); + Controls.Add(pictureBoxCollection); + Name="FormAirbusCollection"; + Text="Набор самолётов"; + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonAdd; + private PictureBox pictureBoxCollection; + private Label labelInstruments; + private Button buttonUpdate; + private Button buttonDelete; + private ColorDialog colorDialog; + private MaskedTextBox maskedTextBoxNumber; + } +} \ No newline at end of file diff --git a/Airbus/FormAirbusCollection.cs b/Airbus/FormAirbusCollection.cs new file mode 100644 index 0000000..7a2eda3 --- /dev/null +++ b/Airbus/FormAirbusCollection.cs @@ -0,0 +1,79 @@ +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 ProjectAirbus.Generics; +using ProjectAirbus.Drawnings; +using ProjectAirbus.MovementStrategy; + +namespace ProjectAirbus +{ + public partial class FormAirbusCollection : Form + { + // Набор объектов + private readonly AirbusGenericCollection _airbus; + + public FormAirbusCollection() + { + InitializeComponent(); + _airbus = new AirbusGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + + // добавить в набор + private void buttonAdd_Click(object sender, EventArgs e) + { + FormPlane form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_airbus + form.SelectedAirbus != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _airbus.ShowAirbus(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + // удалить + private void buttonDelete_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = 0; + try + { + pos = Convert.ToInt32(maskedTextBoxNumber.Text); + } + catch + { + MessageBox.Show("Ошибка ввода данных"); + return; + } + if (_airbus - pos) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _airbus.ShowAirbus(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + // обновить + private void buttonUpdate_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _airbus.ShowAirbus(); + } + } +} diff --git a/Airbus/FormAirbusCollection.resx b/Airbus/FormAirbusCollection.resx new file mode 100644 index 0000000..d5e7ce7 --- /dev/null +++ b/Airbus/FormAirbusCollection.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 79 + + \ No newline at end of file diff --git a/Airbus/FormPlane.Designer.cs b/Airbus/FormPlane.Designer.cs new file mode 100644 index 0000000..0c30bbb --- /dev/null +++ b/Airbus/FormPlane.Designer.cs @@ -0,0 +1,211 @@ +namespace ProjectAirbus +{ + partial class FormPlane + { + /// + /// 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() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormPlane)); + pictureAirBus = new PictureBox(); + buttonUp = new Button(); + buttonLeft = new Button(); + buttonDown = new Button(); + buttonRight = new Button(); + buttonCreate = new Button(); + buttonCreateSuperAirbus = new Button(); + buttonStep = new Button(); + comboBoxStrategy = new ComboBox(); + buttonSelectedAirbus = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureAirBus).BeginInit(); + SuspendLayout(); + // + // pictureAirBus + // + pictureAirBus.Dock = DockStyle.Fill; + pictureAirBus.Location = new Point(0, 0); + pictureAirBus.Margin = new Padding(3, 4, 3, 4); + pictureAirBus.Name = "pictureAirBus"; + pictureAirBus.Size = new Size(903, 547); + pictureAirBus.SizeMode = PictureBoxSizeMode.AutoSize; + pictureAirBus.TabIndex = 0; + pictureAirBus.TabStop = false; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage"); + buttonUp.BackgroundImageLayout = ImageLayout.Stretch; + buttonUp.FlatAppearance.BorderColor = Color.Black; + buttonUp.FlatAppearance.BorderSize = 7; + buttonUp.Location = new Point(776, 412); + buttonUp.Margin = new Padding(3, 4, 3, 4); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(55, 59); + buttonUp.TabIndex = 1; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += buttonMove_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackColor = SystemColors.Control; + buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage"); + buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; + buttonLeft.FlatAppearance.BorderColor = Color.Black; + buttonLeft.FlatAppearance.BorderSize = 7; + buttonLeft.Location = new Point(720, 472); + buttonLeft.Margin = new Padding(3, 4, 3, 4); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(55, 59); + buttonLeft.TabIndex = 2; + buttonLeft.UseVisualStyleBackColor = false; + buttonLeft.Click += buttonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage"); + buttonDown.BackgroundImageLayout = ImageLayout.Stretch; + buttonDown.FlatAppearance.BorderColor = Color.Black; + buttonDown.FlatAppearance.BorderSize = 7; + buttonDown.Location = new Point(776, 472); + buttonDown.Margin = new Padding(3, 4, 3, 4); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(55, 59); + buttonDown.TabIndex = 3; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += buttonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage"); + buttonRight.BackgroundImageLayout = ImageLayout.Stretch; + buttonRight.FlatAppearance.BorderColor = Color.Black; + buttonRight.FlatAppearance.BorderSize = 7; + buttonRight.Location = new Point(832, 472); + buttonRight.Margin = new Padding(3, 4, 3, 4); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(55, 59); + buttonRight.TabIndex = 4; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += buttonMove_Click; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(14, 481); + buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(146, 50); + buttonCreate.TabIndex = 5; + buttonCreate.Text = "Создать аэробус"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonCreateSuperAirbus + // + buttonCreateSuperAirbus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateSuperAirbus.Location = new Point(166, 481); + buttonCreateSuperAirbus.Margin = new Padding(3, 4, 3, 4); + buttonCreateSuperAirbus.Name = "buttonCreateSuperAirbus"; + buttonCreateSuperAirbus.Size = new Size(145, 50); + buttonCreateSuperAirbus.TabIndex = 6; + buttonCreateSuperAirbus.Text = "Создать самолёт"; + buttonCreateSuperAirbus.UseVisualStyleBackColor = true; + buttonCreateSuperAirbus.Click += buttonCreateSuperAirbus_Click; + // + // buttonStep + // + buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonStep.Location = new Point(767, 68); + buttonStep.Margin = new Padding(3, 4, 3, 4); + buttonStep.Name = "buttonStep"; + buttonStep.Size = new Size(120, 49); + buttonStep.TabIndex = 7; + buttonStep.Text = "Шаг"; + buttonStep.UseVisualStyleBackColor = true; + buttonStep.Click += buttonStep_Click; + // + // comboBoxStrategy + // + comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "1", "2" }); + comboBoxStrategy.Location = new Point(711, 29); + comboBoxStrategy.Margin = new Padding(3, 4, 3, 4); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(178, 28); + comboBoxStrategy.TabIndex = 8; + // + // buttonSelectedAirbus + // + buttonSelectedAirbus.Location = new Point(427, 481); + buttonSelectedAirbus.Name = "buttonSelectedAirbus"; + buttonSelectedAirbus.Size = new Size(137, 50); + buttonSelectedAirbus.TabIndex = 9; + buttonSelectedAirbus.Text = "Выбрать"; + buttonSelectedAirbus.UseVisualStyleBackColor = true; + buttonSelectedAirbus.Click += buttonSelectedAirbus_Click; + // + // FormPlane + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(903, 547); + Controls.Add(buttonSelectedAirbus); + Controls.Add(comboBoxStrategy); + Controls.Add(buttonStep); + Controls.Add(buttonCreateSuperAirbus); + Controls.Add(buttonCreate); + Controls.Add(buttonRight); + Controls.Add(buttonDown); + Controls.Add(buttonLeft); + Controls.Add(buttonUp); + Controls.Add(pictureAirBus); + Margin = new Padding(3, 4, 3, 4); + Name = "FormPlane"; + Text = "FormPlane"; + ((System.ComponentModel.ISupportInitialize)pictureAirBus).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureAirBus; + private Button buttonUp; + private Button buttonLeft; + private Button buttonDown; + private Button buttonRight; + private Button buttonCreate; + private Button buttonCreateSuperAirbus; + private Button buttonStep; + private ComboBox comboBoxStrategy; + private Button buttonSelectedAirbus; + } +} \ No newline at end of file diff --git a/Airbus/FormAirbus.cs b/Airbus/FormPlane.cs similarity index 68% rename from Airbus/FormAirbus.cs rename to Airbus/FormPlane.cs index 01728ac..c236f95 100644 --- a/Airbus/FormAirbus.cs +++ b/Airbus/FormPlane.cs @@ -4,14 +4,19 @@ using ProjectAirbus.Entities; namespace ProjectAirbus { - public partial class FormAirbus : Form + public partial class FormPlane : Form { private DrawningAirbus? _drawningAirbus; private AbstractStrategy? _abstractStrategy; - public FormAirbus() + // Выбранный автомобиль + public DrawningAirbus? SelectedAirbus { get; private set; } + + public FormPlane() { InitializeComponent(); + _abstractStrategy = null; + SelectedAirbus = null; } // прорисовка самолёта @@ -27,33 +32,19 @@ namespace ProjectAirbus pictureAirBus.Image = bmp; } - private void buttonDown_Click(object sender, EventArgs e) - { - buttonMove_Click(sender, e); - } - - private void buttonUp_Click(object sender, EventArgs e) - { - buttonMove_Click(sender, e); - } - - private void buttonRight_Click(object sender, EventArgs e) - { - buttonMove_Click(sender, e); - } - - private void buttonLeft_Click(object sender, EventArgs e) - { - buttonMove_Click(sender, e); - } - // кнопка "Создать самолёт" private void buttonCreate_Click(object sender, EventArgs e) { Random random = new Random(); - _drawningAirbus = new DrawningAirbus(random.Next(200, 400), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - pictureAirBus.Width, pictureAirBus.Height); + 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; + } + + _drawningAirbus = new DrawningAirbus(random.Next(100, 300), random.Next(1000, 3000), + color, pictureAirBus.Width, pictureAirBus.Height); _drawningAirbus.SetPosition(random.Next(10, 200), random.Next(10, 200)); Draw(); @@ -64,10 +55,23 @@ namespace ProjectAirbus private void buttonCreateSuperAirbus_Click(object sender, EventArgs e) { Random random = new Random(); + 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; + } + + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + //TODO дополнительного цвета + if (dialog.ShowDialog() == DialogResult.OK) + { + dopColor = dialog.Color; + } + _drawningAirbus = new DrawningPlane(random.Next(200, 400), 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)), + color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureAirBus.Width, pictureAirBus.Height); _drawningAirbus.SetPosition(random.Next(10, 200), random.Next(10, 200)); @@ -131,5 +135,10 @@ namespace ProjectAirbus } } + private void buttonSelectedAirbus_Click(object sender, EventArgs e) + { + SelectedAirbus = _drawningAirbus; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/Airbus/FormAirbus.resx b/Airbus/FormPlane.resx similarity index 81% rename from Airbus/FormAirbus.resx rename to Airbus/FormPlane.resx index 2d6ab17..9903ab7 100644 --- a/Airbus/FormAirbus.resx +++ b/Airbus/FormPlane.resx @@ -1,4 +1,64 @@ - + + + diff --git a/Airbus/Generics/AirbusGenericCollection.cs b/Airbus/Generics/AirbusGenericCollection.cs new file mode 100644 index 0000000..4523632 --- /dev/null +++ b/Airbus/Generics/AirbusGenericCollection.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectAirbus.Drawnings; +using ProjectAirbus.MovementStrategy; + +namespace ProjectAirbus.Generics +{ + internal class AirbusGenericCollection + where T : DrawningAirbus + where U : IMoveableObject + { + private readonly int _pictureWidth; + private readonly int _pictureHeight; + // Размер занимаемого места + private readonly int _placeSizeWidth = 89; + private readonly int _placeSizeHeight = 34; + // коллекция + private readonly SetGeneric _collection; + + public AirbusGenericCollection(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 +(AirbusGenericCollection collect, T? obj) + { + if (obj != null) + { + return collect._collection.Insert(obj); + } + return -1; + } + public static bool operator -(AirbusGenericCollection collect, int pos) + { + if (collect._collection.Get(pos) == null) + { + return false; + } + return collect?._collection.Remove(pos) ?? false; + } + + // получение объекта IMoveableObjecr + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + + // вывод всего набора + public Bitmap ShowAirbus() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + + // прорисовка фона + private void DrawBackground(Graphics gr) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + { + // линия разметки + gr.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + gr.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + } + + // прорисовка объекта + private void DrawObjects(Graphics g) + { + // координаты + int x = 0; + int y = 0; + + for (int i = 0; i <= _collection.Count; ++i) + { + DrawningAirbus _airbus = _collection.Get(i); + if (_airbus == null) + { + ++x; + if (x >= _pictureWidth / _placeSizeWidth) + { + x = 0; + ++y; + } + continue; + } + _airbus.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y); + _airbus.DrawTransport(g); + ++x; + // новая строка + if (x >= _pictureWidth / _placeSizeWidth) + { + x = 0; + ++y; + } + } + } + } +} \ No newline at end of file diff --git a/Airbus/Generics/SetGeneric.cs b/Airbus/Generics/SetGeneric.cs new file mode 100644 index 0000000..4bb54e2 --- /dev/null +++ b/Airbus/Generics/SetGeneric.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirbus.Generics +{ + internal class SetGeneric + where T : class + { + // список объекторв + private readonly T?[] _places; + // кол-во объектов + public int Count => _places.Length - 1; + public SetGeneric(int count) + { + _places = new T?[count]; + } + + // Добавление объекта в набор + public int Insert(T airbus) + { + // проверка, что элемент массива по этой позиции пустой, если нет, то + int pos = Count - 1; + if (_places[Count] != null) + { + // проверка, что после вставляемого элемента в массиве есть пустой элемент + for (int i = pos; i > 0; --i) + { + if (_places[i] == null) + { + pos = i; + break; + } + } + // сдвиг всех объектов, находящихся слева от позиции до первого пустого элемента + for (int i = pos + 1; i <= Count; ++i) + { + _places[i - 1] = _places[i]; + } + } + _places[Count] = airbus; + return pos; + } + + // Добавление объекта в набор на конкретную позицию + public bool Insert(T airbus, int position) + { + // проверка позиции + if (position < 0 || position > Count) + { + return false; + } + // проверка, что элемент массива по этой позиции пустой, если нет, то + if (_places[Count] != null) + { + // проверка, что после вставляемого элемента в массиве есть пустой элемент + int pos = Count; + for (int i = Count; i > 0; --i) + { + + if (_places[i] == null) + { + pos = i; + break; + } + } + + // сдвиг всех объектов, находящихся слева от позиции до первого пустого элемента + for (int i = Count; i >= pos; --i) + { + _places[i - 1] = _places[i]; + } + } + _places[Count] = airbus; + return true; + } + + // Удаление объекта из набора с конкретной позиции + public bool Remove(int position) + { + // проверка позиции + if (position < 0 || position > Count) + { + return false; + } + // удалить объект из массива, присвоив элементу массива значение null + _places[position] = null; + + return true; + } + + // Получение объекта из набора по позиции + public T? Get(int position) + { + // проверка позиции + if (position < 0 || position > Count) + { + return null; + } + return _places[position]; + } + } +} diff --git a/Airbus/MovementStrategy/IMoveableObject.cs b/Airbus/MovementStrategy/IMoveableObject.cs index 116baca..909ce65 100644 --- a/Airbus/MovementStrategy/IMoveableObject.cs +++ b/Airbus/MovementStrategy/IMoveableObject.cs @@ -3,7 +3,7 @@ using ProjectAirbus.Entities; namespace ProjectAirbus.MovementStrategy { - internal interface IMoveableObject + public interface IMoveableObject { ObjectParameters? GetObjectPosition { get; } diff --git a/Airbus/MovementStrategy/ObjectParameters.cs b/Airbus/MovementStrategy/ObjectParameters.cs index 1e898fc..6e22b31 100644 --- a/Airbus/MovementStrategy/ObjectParameters.cs +++ b/Airbus/MovementStrategy/ObjectParameters.cs @@ -1,7 +1,7 @@ namespace ProjectAirbus.MovementStrategy { - internal class ObjectParameters - { + public class ObjectParameters + { private readonly int _x; private readonly int _y; private readonly int _width; @@ -23,5 +23,5 @@ _width = width; _height = height; } - } + } } diff --git a/Airbus/Program.cs b/Airbus/Program.cs index 9d45ae4..99a94bc 100644 --- a/Airbus/Program.cs +++ b/Airbus/Program.cs @@ -11,7 +11,7 @@ namespace ProjectAirbus // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAirbus()); + Application.Run(new FormAirbusCollection()); } } } \ No newline at end of file