From 5a00ca2c706b2a97e95787f671a862374469ed38 Mon Sep 17 00:00:00 2001 From: urlilpolly Date: Sat, 2 Dec 2023 16:43:36 +0400 Subject: [PATCH] laba3 --- RPP/RPP/Airbus.Designer.cs | 61 ++++----- RPP/RPP/Airbus.cs | 40 ++++-- RPP/RPP/Airbus.resx | 2 +- RPP/RPP/AirbusGenericCollection.cs | 102 ++++++++++++++++ RPP/RPP/{Drawning.cs => DrawningAirbus.cs} | 42 +++---- RPP/RPP/FormAirbusCollection.Designer.cs | 136 +++++++++++++++++++++ RPP/RPP/FormAirbusCollection.cs | 65 ++++++++++ RPP/RPP/FormAirbusCollection.resx | 120 ++++++++++++++++++ RPP/RPP/IMoveableObject.cs | 10 +- RPP/RPP/MoveToBorder.cs | 3 +- RPP/RPP/ObjectParameters.cs | 2 +- RPP/RPP/Program.cs | 3 +- RPP/RPP/SetGeneric.cs | 75 ++++++++++++ 13 files changed, 590 insertions(+), 71 deletions(-) create mode 100644 RPP/RPP/AirbusGenericCollection.cs rename RPP/RPP/{Drawning.cs => DrawningAirbus.cs} (88%) create mode 100644 RPP/RPP/FormAirbusCollection.Designer.cs create mode 100644 RPP/RPP/FormAirbusCollection.cs create mode 100644 RPP/RPP/FormAirbusCollection.resx create mode 100644 RPP/RPP/SetGeneric.cs diff --git a/RPP/RPP/Airbus.Designer.cs b/RPP/RPP/Airbus.Designer.cs index 688ed36..82b812d 100644 --- a/RPP/RPP/Airbus.Designer.cs +++ b/RPP/RPP/Airbus.Designer.cs @@ -37,6 +37,7 @@ comboBoxStrategy = new ComboBox(); buttonCreateFlyAirbus = new Button(); ButtonStep = new Button(); + ButtonSelectAirbus = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirbus).BeginInit(); SuspendLayout(); // @@ -45,9 +46,8 @@ pictureBoxAirbus.BackColor = SystemColors.Window; pictureBoxAirbus.Dock = DockStyle.Fill; pictureBoxAirbus.Location = new Point(0, 0); - pictureBoxAirbus.Margin = new Padding(3, 4, 3, 4); pictureBoxAirbus.Name = "pictureBoxAirbus"; - pictureBoxAirbus.Size = new Size(982, 553); + pictureBoxAirbus.Size = new Size(859, 415); pictureBoxAirbus.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxAirbus.TabIndex = 0; pictureBoxAirbus.TabStop = false; @@ -56,10 +56,9 @@ // buttonCreateAirbus // buttonCreateAirbus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateAirbus.Location = new Point(224, 456); - buttonCreateAirbus.Margin = new Padding(3, 4, 3, 4); + buttonCreateAirbus.Location = new Point(196, 342); buttonCreateAirbus.Name = "buttonCreateAirbus"; - buttonCreateAirbus.Size = new Size(166, 80); + buttonCreateAirbus.Size = new Size(145, 60); buttonCreateAirbus.TabIndex = 1; buttonCreateAirbus.Text = "Создать аэробус"; buttonCreateAirbus.UseVisualStyleBackColor = true; @@ -70,10 +69,9 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.buttonDown; buttonDown.BackgroundImageLayout = ImageLayout.Zoom; - buttonDown.Location = new Point(883, 493); - buttonDown.Margin = new Padding(3, 4, 3, 4); + buttonDown.Location = new Point(773, 370); buttonDown.Name = "buttonDown"; - buttonDown.Size = new Size(30, 29); + buttonDown.Size = new Size(26, 22); buttonDown.TabIndex = 2; buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += buttonMove_Click; @@ -83,10 +81,9 @@ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.buttonLeft; buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; - buttonLeft.Location = new Point(847, 493); - buttonLeft.Margin = new Padding(3, 4, 3, 4); + buttonLeft.Location = new Point(741, 370); buttonLeft.Name = "buttonLeft"; - buttonLeft.Size = new Size(30, 29); + buttonLeft.Size = new Size(26, 22); buttonLeft.TabIndex = 3; buttonLeft.UseVisualStyleBackColor = true; buttonLeft.Click += buttonMove_Click; @@ -96,10 +93,9 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.buttonUp; buttonUp.BackgroundImageLayout = ImageLayout.Zoom; - buttonUp.Location = new Point(883, 456); - buttonUp.Margin = new Padding(3, 4, 3, 4); + buttonUp.Location = new Point(773, 342); buttonUp.Name = "buttonUp"; - buttonUp.Size = new Size(30, 29); + buttonUp.Size = new Size(26, 22); buttonUp.TabIndex = 4; buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += buttonMove_Click; @@ -109,10 +105,9 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.buttonRight; buttonRight.BackgroundImageLayout = ImageLayout.Zoom; - buttonRight.Location = new Point(919, 493); - buttonRight.Margin = new Padding(3, 4, 3, 4); + buttonRight.Location = new Point(804, 370); buttonRight.Name = "buttonRight"; - buttonRight.Size = new Size(30, 29); + buttonRight.Size = new Size(26, 22); buttonRight.TabIndex = 5; buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += buttonMove_Click; @@ -121,19 +116,17 @@ // comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "0", "1" }); - comboBoxStrategy.Location = new Point(830, 28); - comboBoxStrategy.Margin = new Padding(3, 4, 3, 4); + comboBoxStrategy.Location = new Point(726, 21); comboBoxStrategy.Name = "comboBoxStrategy"; - comboBoxStrategy.Size = new Size(138, 28); + comboBoxStrategy.Size = new Size(121, 23); comboBoxStrategy.TabIndex = 6; comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged; // // buttonCreateFlyAirbus // - buttonCreateFlyAirbus.Location = new Point(38, 456); - buttonCreateFlyAirbus.Margin = new Padding(3, 4, 3, 4); + buttonCreateFlyAirbus.Location = new Point(33, 342); buttonCreateFlyAirbus.Name = "buttonCreateFlyAirbus"; - buttonCreateFlyAirbus.Size = new Size(166, 80); + buttonCreateFlyAirbus.Size = new Size(145, 60); buttonCreateFlyAirbus.TabIndex = 7; buttonCreateFlyAirbus.Text = "Создать пассажирский аэробус"; buttonCreateFlyAirbus.UseVisualStyleBackColor = true; @@ -141,20 +134,30 @@ // // ButtonStep // - ButtonStep.Location = new Point(882, 79); - ButtonStep.Margin = new Padding(3, 4, 3, 4); + ButtonStep.Location = new Point(772, 59); ButtonStep.Name = "ButtonStep"; - ButtonStep.Size = new Size(86, 31); + ButtonStep.Size = new Size(75, 23); ButtonStep.TabIndex = 8; ButtonStep.Text = "Шаг"; ButtonStep.UseVisualStyleBackColor = true; ButtonStep.Click += ButtonStep_Click; // + // ButtonSelectAirbus + // + ButtonSelectAirbus.Location = new Point(357, 342); + ButtonSelectAirbus.Name = "ButtonSelectAirbus"; + ButtonSelectAirbus.Size = new Size(145, 61); + ButtonSelectAirbus.TabIndex = 9; + ButtonSelectAirbus.Text = "Смена самолета"; + ButtonSelectAirbus.UseVisualStyleBackColor = true; + ButtonSelectAirbus.Click += ButtonSelectAirbus_Click; + // // FormAirbus // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(982, 553); + ClientSize = new Size(859, 415); + Controls.Add(ButtonSelectAirbus); Controls.Add(ButtonStep); Controls.Add(buttonCreateFlyAirbus); Controls.Add(comboBoxStrategy); @@ -164,7 +167,6 @@ Controls.Add(buttonDown); Controls.Add(buttonCreateAirbus); Controls.Add(pictureBoxAirbus); - Margin = new Padding(3, 4, 3, 4); Name = "FormAirbus"; Text = "Airbus"; Load += FormAirbus_Load; @@ -184,5 +186,6 @@ private ComboBox comboBoxStrategy; private Button buttonCreateFlyAirbus; private Button ButtonStep; + private Button ButtonSelectAirbus; } } \ No newline at end of file diff --git a/RPP/RPP/Airbus.cs b/RPP/RPP/Airbus.cs index c046996..09f6aeb 100644 --- a/RPP/RPP/Airbus.cs +++ b/RPP/RPP/Airbus.cs @@ -8,9 +8,12 @@ namespace RPP { private DrawningAirbus? _drawningAirbus; private AbstractStrategy? _abstractStrategy; + public DrawningAirbus? SelectedAirbus { get; private set; } public FormAirbus() { InitializeComponent(); + _abstractStrategy = null; + SelectedAirbus = null; } private void Draw() @@ -29,28 +32,38 @@ namespace RPP private void buttonCreateFlyAirbus_Click(object sender, EventArgs e) { Random random = new(); + Color MainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + Color AdditionColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + MainColor = dialog.Color; + } + if (dialog.ShowDialog() == DialogResult.OK) + { + AdditionColor = dialog.Color; + } _drawningAirbus = new DrawningFlyAirbus(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)), + MainColor, AdditionColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirbus.Width, pictureBoxAirbus.Height); _drawningAirbus.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); - - } private void ButtonCreateAirbus_Click(object sender, EventArgs e) { Random random = new(); + 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.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), + random.Next(1000, 3000), color, pictureBoxAirbus.Width, pictureBoxAirbus.Height); _drawningAirbus.SetPosition(random.Next(10, 100), random.Next(10, 100)); @@ -105,8 +118,7 @@ namespace RPP { return; } - _abstractStrategy.SetData(new - DrawningObjectAirbus(_drawningAirbus), pictureBoxAirbus.Width, + _abstractStrategy.SetData(_drawningAirbus.GetMoveableObject, pictureBoxAirbus.Width, pictureBoxAirbus.Height); comboBoxStrategy.Enabled = false; } @@ -123,6 +135,12 @@ namespace RPP } } + private void ButtonSelectAirbus_Click(object sender, EventArgs e) + { + SelectedAirbus = _drawningAirbus; + DialogResult = DialogResult.OK; + } + private void pictureBoxAirbus_Click(object sender, EventArgs e) { diff --git a/RPP/RPP/Airbus.resx b/RPP/RPP/Airbus.resx index a395bff..af32865 100644 --- a/RPP/RPP/Airbus.resx +++ b/RPP/RPP/Airbus.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object] diff --git a/RPP/RPP/AirbusGenericCollection.cs b/RPP/RPP/AirbusGenericCollection.cs new file mode 100644 index 0000000..d1d2e86 --- /dev/null +++ b/RPP/RPP/AirbusGenericCollection.cs @@ -0,0 +1,102 @@ + +using RPP.DrawningObjects; +using RPP.MovementStrategy; + +namespace RPP.Generics +{ + public class AirbusGenericCollection + where T : DrawningAirbus + where U : IMoveableObject + { + + private readonly int _pictureWidth; + + private readonly int _pictureHeight; + + private readonly int _placeSizeWidth = 220; + + private readonly int _placeSizeHeight = 120; + + 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 -1; + } + return collect?._collection.Insert(obj); + } + + public static bool operator -(AirbusGenericCollection 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 ShowCars() + { + 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 width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + for (int i = 0; i < _collection.Count; i++) + { + + DrawningAirbus accept = _collection.Get(i); + if (accept == null) { + continue; + } + + accept.SetPosition((width - 1 - (i % width)) * _placeSizeWidth + 12, (height - 1 - (i / width)) * _placeSizeHeight + 10); + + accept.DrawTransport(g); + } + } + } +} \ No newline at end of file diff --git a/RPP/RPP/Drawning.cs b/RPP/RPP/DrawningAirbus.cs similarity index 88% rename from RPP/RPP/Drawning.cs rename to RPP/RPP/DrawningAirbus.cs index 4d25061..ce409ad 100644 --- a/RPP/RPP/Drawning.cs +++ b/RPP/RPP/DrawningAirbus.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RPP.Entities; +using RPP.Entities; +using RPP.MovementStrategy; + namespace RPP.DrawningObjects + { public class DrawningAirbus { @@ -23,6 +21,7 @@ namespace RPP.DrawningObjects private readonly int _AirbusWidth = 200; private readonly int _AirbusHeight = 100; + public int GetPosX => _startPosX; public int GetPosY => _startPosY; @@ -31,7 +30,7 @@ namespace RPP.DrawningObjects public int GetHeight => _AirbusHeight; - public virtual bool CanMove(Direction direction) + public bool CanMove(Direction direction) { if (EntityAirbus == null) { @@ -39,20 +38,19 @@ namespace RPP.DrawningObjects } return direction switch { + //влево Direction.Left => _startPosX - EntityAirbus.Step > 5, + //вверх Direction.Up => _startPosY - EntityAirbus.Step > 0, + // вправо Direction.Right => _startPosX + EntityAirbus.Step + _AirbusWidth < _pictureWidth, - Direction.Down => _startPosY + EntityAirbus.Step + _AirbusHeight < _pictureHeight, - _ => false + Direction.Down => _startPosY + EntityAirbus.Step + _AirbusHeight < _pictureHeight }; } public DrawningAirbus(int speed, double weight, Color bodyColor, int width, int height) { - if (width < _AirbusWidth || height < _AirbusHeight) - { - return; - } + _pictureWidth = width; _pictureHeight = height; EntityAirbus = new EntityAirbus(speed, weight, bodyColor); @@ -71,16 +69,13 @@ namespace RPP.DrawningObjects } + public void SetPosition(int x, int y) { - if (x > _pictureWidth || y > _pictureHeight || x < 0 || y < 0) - { - _startPosX = 0; - _startPosY = 0; - } _startPosX = x; _startPosY = y; } + public IMoveableObject GetMoveableObject => new DrawningObjectAirbus(this); public void MoveTransport(Direction direction) { @@ -120,6 +115,8 @@ namespace RPP.DrawningObjects break; } } + + public virtual void DrawTransport(Graphics g) { @@ -127,8 +124,8 @@ namespace RPP.DrawningObjects { return; } - Pen pen = new(Color.Black, 3); - Brush brush = new SolidBrush(Color.Black); + Pen pen = new(EntityAirbus.BodyColor, 3); + Brush brush = new SolidBrush(EntityAirbus.BodyColor); //Тело g.DrawRectangle(pen, _startPosX + 5, _startPosY + 50, 170, 30); g.DrawPie(pen, _startPosX - 5, _startPosY + 50, 20, 30, 90, 180); @@ -139,7 +136,7 @@ namespace RPP.DrawningObjects g.DrawLine(pen, _startPosX, _startPosY, _startPosX, _startPosY + 52); //Заднее боковые крылья - Pen bigPen = new Pen(Color.Black, 8); + Pen bigPen = new Pen(EntityAirbus.BodyColor, 8); g.DrawPie(pen, _startPosX - 7, _startPosY + 45, 5, 10, 90, 180); g.DrawLine(bigPen, _startPosX - 6, _startPosY + 48, _startPosX + 30, _startPosY + 48); g.DrawLine(bigPen, _startPosX - 6, _startPosY + 52, _startPosX + 30, _startPosY + 52); @@ -155,7 +152,7 @@ namespace RPP.DrawningObjects g.DrawPie(pen, _startPosX + 139, _startPosY + 62, 5, 5, 180, 270); //Задние шасси g.DrawLine(pen, _startPosX + 55, _startPosY + 80, _startPosX + 55, _startPosY + 90); - Pen tallpen = new(Color.Black, 2); + Pen tallpen = new(EntityAirbus.BodyColor, 2); g.DrawEllipse(pen, _startPosX + 47, _startPosY + 90, 5, 5); g.DrawEllipse(pen, _startPosX + 57, _startPosY + 90, 5, 5); //Передние шасси @@ -163,6 +160,7 @@ namespace RPP.DrawningObjects g.DrawEllipse(pen, _startPosX + 163, _startPosY + 91, 5, 5); } + } } diff --git a/RPP/RPP/FormAirbusCollection.Designer.cs b/RPP/RPP/FormAirbusCollection.Designer.cs new file mode 100644 index 0000000..7c7aab6 --- /dev/null +++ b/RPP/RPP/FormAirbusCollection.Designer.cs @@ -0,0 +1,136 @@ +namespace RPP +{ + 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() + { + panel1 = new Panel(); + ButtonRefreshCollection = new Button(); + ButtonRemoveAirbus = new Button(); + maskedTextBoxNumber = new TextBox(); + AddAirbusButton = new Button(); + label = new Label(); + pictureBoxCollection = new PictureBox(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(ButtonRefreshCollection); + panel1.Controls.Add(ButtonRemoveAirbus); + panel1.Controls.Add(maskedTextBoxNumber); + panel1.Controls.Add(AddAirbusButton); + panel1.Controls.Add(label); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(600, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(200, 450); + panel1.TabIndex = 0; + // + // ButtonRefreshCollection + // + ButtonRefreshCollection.Location = new Point(5, 236); + ButtonRefreshCollection.Name = "ButtonRefreshCollection"; + ButtonRefreshCollection.Size = new Size(190, 40); + ButtonRefreshCollection.TabIndex = 4; + ButtonRefreshCollection.Text = "Обновить коллекцию"; + ButtonRefreshCollection.UseVisualStyleBackColor = true; + ButtonRefreshCollection.Click += ButtonRefreshCollection_Click; + // + // ButtonRemoveAirbus + // + ButtonRemoveAirbus.Location = new Point(5, 154); + ButtonRemoveAirbus.Name = "ButtonRemoveAirbus"; + ButtonRemoveAirbus.Size = new Size(190, 40); + ButtonRemoveAirbus.TabIndex = 3; + ButtonRemoveAirbus.Text = "Удалить аэробус"; + ButtonRemoveAirbus.UseVisualStyleBackColor = true; + ButtonRemoveAirbus.Click += ButtonRemoveAirbus_Click; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Location = new Point(45, 125); + maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + maskedTextBoxNumber.Size = new Size(98, 23); + maskedTextBoxNumber.TabIndex = 2; + // + // AddAirbusButton + // + AddAirbusButton.Location = new Point(5, 36); + AddAirbusButton.Name = "AddAirbusButton"; + AddAirbusButton.Size = new Size(190, 40); + AddAirbusButton.TabIndex = 1; + AddAirbusButton.Text = "Добавить аэробус"; + AddAirbusButton.UseVisualStyleBackColor = true; + AddAirbusButton.Click += AddAirbusButton_Click; + // + // label + // + label.AutoSize = true; + label.Location = new Point(5, 0); + label.Name = "label"; + label.Size = new Size(83, 15); + label.TabIndex = 0; + label.Text = "Инструменты"; + // + // pictureBoxCollection + // + pictureBoxCollection.Dock = DockStyle.Fill; + pictureBoxCollection.Location = new Point(0, 0); + pictureBoxCollection.Name = "pictureBoxCollection"; + pictureBoxCollection.Size = new Size(600, 450); + pictureBoxCollection.TabIndex = 1; + pictureBoxCollection.TabStop = false; + // + // FormAirbusCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(pictureBoxCollection); + Controls.Add(panel1); + Name = "FormAirbusCollection"; + Text = "FormFlyAirbus"; + Load += FormFlyAirbus_Load; + panel1.ResumeLayout(false); + panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button AddAirbusButton; + private Label label; + private PictureBox pictureBoxCollection; + private Button ButtonRefreshCollection; + private Button ButtonRemoveAirbus; + private TextBox maskedTextBoxNumber; + } +} \ No newline at end of file diff --git a/RPP/RPP/FormAirbusCollection.cs b/RPP/RPP/FormAirbusCollection.cs new file mode 100644 index 0000000..1e174c1 --- /dev/null +++ b/RPP/RPP/FormAirbusCollection.cs @@ -0,0 +1,65 @@ +using RPP.DrawningObjects; +using RPP.MovementStrategy; +using RPP.Generics; + + +namespace RPP +{ + public partial class FormAirbusCollection : Form + { + private readonly AirbusGenericCollection _Airbus; + + public FormAirbusCollection() + { + InitializeComponent(); + _Airbus = new AirbusGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + + } + + private void FormFlyAirbus_Load(object sender, EventArgs e) + { + + } + + private void AddAirbusButton_Click(object sender, EventArgs e) + { + FormAirbus form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_Airbus + form.SelectedAirbus > -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _Airbus.ShowCars(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + private void ButtonRemoveAirbus_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_Airbus - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _Airbus.ShowCars(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void ButtonRefreshCollection_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _Airbus.ShowCars(); + } + } +} diff --git a/RPP/RPP/FormAirbusCollection.resx b/RPP/RPP/FormAirbusCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RPP/RPP/FormAirbusCollection.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/RPP/RPP/IMoveableObject.cs b/RPP/RPP/IMoveableObject.cs index 132cf5f..1e0cf9c 100644 --- a/RPP/RPP/IMoveableObject.cs +++ b/RPP/RPP/IMoveableObject.cs @@ -6,15 +6,15 @@ using System.Threading.Tasks; namespace RPP.MovementStrategy { - interface IMoveableObject + public interface IMoveableObject { - + ObjectParameters? GetObjectPosition { get; } - + int GetStep { get; } - + bool CheckCanMove(Direction direction); - + void MoveObject(Direction direction); } diff --git a/RPP/RPP/MoveToBorder.cs b/RPP/RPP/MoveToBorder.cs index 30bdea4..2731e41 100644 --- a/RPP/RPP/MoveToBorder.cs +++ b/RPP/RPP/MoveToBorder.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using RPP.MovementStrategy; -namespace RPP.MovementStrategy +namespace RPP { internal class MoveToBorder : AbstractStrategy { diff --git a/RPP/RPP/ObjectParameters.cs b/RPP/RPP/ObjectParameters.cs index 056450c..48eff2c 100644 --- a/RPP/RPP/ObjectParameters.cs +++ b/RPP/RPP/ObjectParameters.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace RPP.MovementStrategy { - internal class ObjectParameters + public class ObjectParameters { private readonly int _x; private readonly int _y; diff --git a/RPP/RPP/Program.cs b/RPP/RPP/Program.cs index 2b88ca7..580378d 100644 --- a/RPP/RPP/Program.cs +++ b/RPP/RPP/Program.cs @@ -1,3 +1,4 @@ + namespace RPP { internal static class Program @@ -11,7 +12,7 @@ namespace RPP // 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 diff --git a/RPP/RPP/SetGeneric.cs b/RPP/RPP/SetGeneric.cs new file mode 100644 index 0000000..ac03965 --- /dev/null +++ b/RPP/RPP/SetGeneric.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; + +namespace RPP.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 airbus) + { + return Insert(airbus, 0); + } + + public int Insert(T airbus, int position) + { + + if(position < 0 && position > Count) { + return -1; + } + if (_places[position] != null) + { + int d = 0; + for (int j = 1; j < Count - position; j++) + { + if (_places[position + j] == null) + { + d = position + j; + break; + } + } + if (d == 0) { + return -1; + } + for(int j = d; j > position; j--) { + _places[j] = _places[j - 1]; + } + } + + _places[position] = airbus; + return position; + } + + public bool Remove(int position) + { + + if (position < 0 && position > Count) + { + return false; + } + _places[position] = null; + return true; + } + + public T? Get(int position) + { + return _places[position]; + } + } +} + + -- 2.25.1