From 0f2fc1be544db9620feb43c60bd54b713e42c5fd Mon Sep 17 00:00:00 2001 From: maxim24052002 Date: Mon, 15 Jan 2024 23:05:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BA=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/DrawingBoat.cs | 14 +- Sailboat/Sailboat/DrawingSailboat.cs | 27 +-- .../Sailboat/FormBoatCollection.Designer.cs | 194 +++++++++++------- Sailboat/Sailboat/FormBoatCollection.cs | 101 ++++++++- Sailboat/Sailboat/FormBoatCollection.resx | 62 +----- 5 files changed, 231 insertions(+), 167 deletions(-) diff --git a/Sailboat/Sailboat/DrawingBoat.cs b/Sailboat/Sailboat/DrawingBoat.cs index e160744..a0b5c12 100644 --- a/Sailboat/Sailboat/DrawingBoat.cs +++ b/Sailboat/Sailboat/DrawingBoat.cs @@ -23,7 +23,6 @@ namespace Sailboat.DrawingObjects public int GetWidth => _boatWidth; public int GetHeight => _boatHeight; public IMoveableObject GetMoveableObject => new DrawingObjectBoat(this); - public DrawingBoat(int speed, double weight, Color bodyColor, int width, int height) { if (width < _boatWidth || height < _boatHeight) @@ -76,11 +75,12 @@ namespace Sailboat.DrawingObjects DirectionType.Right => _startPosX + EntityBoat.Step < _pictureWidth, //вниз DirectionType.Down => _startPosY + EntityBoat.Step < _pictureHeight, + _ => false }; } public void MoveTransport(DirectionType direction) { - if (EntityBoat == null) + if (!CanMove(direction) || EntityBoat == null) { return; } @@ -93,7 +93,7 @@ namespace Sailboat.DrawingObjects } break; case DirectionType.Up: - if ((_startPosY - 15) - EntityBoat.Step > 0) + if (_startPosY - EntityBoat.Step > 0) { _startPosY -= (int)EntityBoat.Step; } @@ -122,7 +122,7 @@ namespace Sailboat.DrawingObjects Brush additionalBrush = new SolidBrush(EntityBoat.BodyColor); - //Основной корпус лодки + //основной корпус парусника Brush Brush = new SolidBrush(EntityBoat.BodyColor); @@ -138,14 +138,12 @@ namespace Sailboat.DrawingObjects g.DrawPolygon(pen, hull); Brush addBrush = new - SolidBrush(Color.Aqua); + SolidBrush(Color.Green); - //Каюта лодки g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 90, 40); g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40); } } -} - + } diff --git a/Sailboat/Sailboat/DrawingSailboat.cs b/Sailboat/Sailboat/DrawingSailboat.cs index c25780b..130b9cc 100644 --- a/Sailboat/Sailboat/DrawingSailboat.cs +++ b/Sailboat/Sailboat/DrawingSailboat.cs @@ -30,7 +30,7 @@ namespace Sailboat.DrawingObjects Brush additionalBrush = new SolidBrush(sailboat.AdditionalColor); - //усиленный корпус парусной лодки + //усиленный корпус парусника if (sailboat.Hull) { Point[] hullCooler = new Point[] @@ -43,10 +43,11 @@ namespace Sailboat.DrawingObjects }; g.FillPolygon(additionalBrush, hullCooler); g.DrawPolygon(pen, hullCooler); - } - base.DrawTransport(g); - - //Парус с флагом + } + + base.DrawTransport(g); + + //парус if (sailboat.Sail) { Brush sailBrush = new @@ -60,21 +61,7 @@ namespace Sailboat.DrawingObjects }; g.FillPolygon(sailBrush, sail); g.DrawPolygon(pen, sail); - //Флаг - Brush addBrush = new - SolidBrush(Color.Aqua); - Brush flagBrush = new - SolidBrush(sailboat.AdditionalColor); - Point[] flag = new Point[] - { - new Point(_startPosX + 65, _startPosY - 15), - new Point(_startPosX + 65, _startPosY + 10), - new Point(_startPosX + 20, _startPosY + 10), - new Point(_startPosX + 20, _startPosY - 15), - }; - g.FillPolygon(addBrush, flag); - g.DrawPolygon(pen, flag); - g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 130), new Point(_startPosX + 65, _startPosY - 15)); + g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 120), new Point(_startPosX + 65, _startPosY)); } } } diff --git a/Sailboat/Sailboat/FormBoatCollection.Designer.cs b/Sailboat/Sailboat/FormBoatCollection.Designer.cs index 626d458..a3be7c3 100644 --- a/Sailboat/Sailboat/FormBoatCollection.Designer.cs +++ b/Sailboat/Sailboat/FormBoatCollection.Designer.cs @@ -28,96 +28,147 @@ /// private void InitializeComponent() { - pictureBoxCollection = new PictureBox(); - panelTools = new Panel(); - maskedTextBoxNumber = new MaskedTextBox(); - buttonRefreshCollection = new Button(); - buttonRemoveBoat = new Button(); - buttonAddBoat = new Button(); - ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); - panelTools.SuspendLayout(); - SuspendLayout(); + this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); + this.panelTools = new System.Windows.Forms.Panel(); + this.panelCollection = new System.Windows.Forms.Panel(); + this.buttonDelObject = new System.Windows.Forms.Button(); + this.listBoxStorages = new System.Windows.Forms.ListBox(); + this.buttonAddObject = new System.Windows.Forms.Button(); + this.textBoxStorageName = new System.Windows.Forms.TextBox(); + this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); + this.buttonRefreshCollection = new System.Windows.Forms.Button(); + this.buttonRemoveBoat = new System.Windows.Forms.Button(); + this.buttonAddBoat = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); + this.panelTools.SuspendLayout(); + this.panelCollection.SuspendLayout(); + this.SuspendLayout(); // // pictureBoxCollection // - pictureBoxCollection.Location = new Point(0, 0); - pictureBoxCollection.Margin = new Padding(3, 2, 3, 2); - pictureBoxCollection.Name = "pictureBoxCollection"; - pictureBoxCollection.Size = new Size(750, 450); - pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize; - pictureBoxCollection.TabIndex = 0; - pictureBoxCollection.TabStop = false; - pictureBoxCollection.Click += pictureBoxCollection_Click; + this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); + this.pictureBoxCollection.Name = "pictureBoxCollection"; + this.pictureBoxCollection.Size = new System.Drawing.Size(750, 600); + this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxCollection.TabIndex = 0; + this.pictureBoxCollection.TabStop = false; // // panelTools // - panelTools.BackColor = SystemColors.ScrollBar; - panelTools.Controls.Add(maskedTextBoxNumber); - panelTools.Controls.Add(buttonRefreshCollection); - panelTools.Controls.Add(buttonRemoveBoat); - panelTools.Controls.Add(buttonAddBoat); - panelTools.Location = new Point(662, 9); - panelTools.Margin = new Padding(3, 2, 3, 2); - panelTools.Name = "panelTools"; - panelTools.Size = new Size(183, 320); - panelTools.TabIndex = 1; + this.panelTools.BackColor = System.Drawing.SystemColors.ScrollBar; + this.panelTools.Controls.Add(this.panelCollection); + this.panelTools.Controls.Add(this.maskedTextBoxNumber); + this.panelTools.Controls.Add(this.buttonRefreshCollection); + this.panelTools.Controls.Add(this.buttonRemoveBoat); + this.panelTools.Controls.Add(this.buttonAddBoat); + this.panelTools.Location = new System.Drawing.Point(756, 12); + this.panelTools.Name = "panelTools"; + this.panelTools.Size = new System.Drawing.Size(209, 588); + this.panelTools.TabIndex = 1; + // + // panelCollection + // + this.panelCollection.BackColor = System.Drawing.SystemColors.AppWorkspace; + this.panelCollection.Controls.Add(this.buttonDelObject); + this.panelCollection.Controls.Add(this.listBoxStorages); + this.panelCollection.Controls.Add(this.buttonAddObject); + this.panelCollection.Controls.Add(this.textBoxStorageName); + this.panelCollection.Location = new System.Drawing.Point(16, 15); + this.panelCollection.Name = "panelCollection"; + this.panelCollection.Size = new System.Drawing.Size(181, 287); + this.panelCollection.TabIndex = 4; + // + // buttonDelObject + // + this.buttonDelObject.Location = new System.Drawing.Point(12, 230); + this.buttonDelObject.Name = "buttonDelObject"; + this.buttonDelObject.Size = new System.Drawing.Size(154, 34); + this.buttonDelObject.TabIndex = 5; + this.buttonDelObject.Text = "Удалить набор"; + this.buttonDelObject.UseVisualStyleBackColor = true; + this.buttonDelObject.Click += new System.EventHandler(this.buttonDelObject_Click); + // + // listBoxStorages + // + this.listBoxStorages.FormattingEnabled = true; + this.listBoxStorages.ItemHeight = 20; + this.listBoxStorages.Location = new System.Drawing.Point(12, 102); + this.listBoxStorages.Name = "listBoxStorages"; + this.listBoxStorages.Size = new System.Drawing.Size(154, 104); + this.listBoxStorages.TabIndex = 6; + this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged); + // + // buttonAddObject + // + this.buttonAddObject.Location = new System.Drawing.Point(12, 62); + this.buttonAddObject.Name = "buttonAddObject"; + this.buttonAddObject.Size = new System.Drawing.Size(154, 34); + this.buttonAddObject.TabIndex = 5; + this.buttonAddObject.Text = "Добавить набор"; + this.buttonAddObject.UseVisualStyleBackColor = true; + this.buttonAddObject.Click += new System.EventHandler(this.buttonAddObject_Click); + // + // textBoxStorageName + // + this.textBoxStorageName.Location = new System.Drawing.Point(29, 29); + this.textBoxStorageName.Name = "textBoxStorageName"; + this.textBoxStorageName.Size = new System.Drawing.Size(125, 27); + this.textBoxStorageName.TabIndex = 0; // // maskedTextBoxNumber // - maskedTextBoxNumber.Location = new Point(35, 65); - maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2); - maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - maskedTextBoxNumber.Size = new Size(110, 23); - maskedTextBoxNumber.TabIndex = 3; + this.maskedTextBoxNumber.Location = new System.Drawing.Point(45, 416); + this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27); + this.maskedTextBoxNumber.TabIndex = 3; // // buttonRefreshCollection // - buttonRefreshCollection.Location = new Point(14, 158); - buttonRefreshCollection.Margin = new Padding(3, 2, 3, 2); - buttonRefreshCollection.Name = "buttonRefreshCollection"; - buttonRefreshCollection.Size = new Size(158, 26); - buttonRefreshCollection.TabIndex = 2; - buttonRefreshCollection.Text = "Обновить коллекцию"; - buttonRefreshCollection.UseVisualStyleBackColor = true; - buttonRefreshCollection.Click += buttonRefreshCollection_Click; + this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 531); + this.buttonRefreshCollection.Name = "buttonRefreshCollection"; + this.buttonRefreshCollection.Size = new System.Drawing.Size(180, 34); + this.buttonRefreshCollection.TabIndex = 2; + this.buttonRefreshCollection.Text = "Обновить коллекцию"; + this.buttonRefreshCollection.UseVisualStyleBackColor = true; + this.buttonRefreshCollection.Click += new System.EventHandler(this.buttonRefreshCollection_Click); // // buttonRemoveBoat // - buttonRemoveBoat.Location = new Point(14, 119); - buttonRemoveBoat.Margin = new Padding(3, 2, 3, 2); - buttonRemoveBoat.Name = "buttonRemoveBoat"; - buttonRemoveBoat.Size = new Size(158, 26); - buttonRemoveBoat.TabIndex = 1; - buttonRemoveBoat.Text = "Удалить лодку"; - buttonRemoveBoat.UseVisualStyleBackColor = true; - buttonRemoveBoat.Click += buttonRemoveBoat_Click; + this.buttonRemoveBoat.Location = new System.Drawing.Point(17, 469); + this.buttonRemoveBoat.Name = "buttonRemoveBoat"; + this.buttonRemoveBoat.Size = new System.Drawing.Size(180, 34); + this.buttonRemoveBoat.TabIndex = 1; + this.buttonRemoveBoat.Text = "Удалить лодку"; + this.buttonRemoveBoat.UseVisualStyleBackColor = true; + this.buttonRemoveBoat.Click += new System.EventHandler(this.buttonRemoveBoat_Click); // // buttonAddBoat // - buttonAddBoat.Location = new Point(14, 10); - buttonAddBoat.Margin = new Padding(3, 2, 3, 2); - buttonAddBoat.Name = "buttonAddBoat"; - buttonAddBoat.Size = new Size(158, 26); - buttonAddBoat.TabIndex = 0; - buttonAddBoat.Text = "Добавить лодку"; - buttonAddBoat.UseVisualStyleBackColor = true; - buttonAddBoat.Click += buttonAddBoat_Click; + this.buttonAddBoat.Location = new System.Drawing.Point(16, 339); + this.buttonAddBoat.Name = "buttonAddBoat"; + this.buttonAddBoat.Size = new System.Drawing.Size(180, 34); + this.buttonAddBoat.TabIndex = 0; + this.buttonAddBoat.Text = "Добавить лодку"; + this.buttonAddBoat.UseVisualStyleBackColor = true; + this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click); // // FormBoatCollection // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(848, 338); - Controls.Add(pictureBoxCollection); - Controls.Add(panelTools); - Margin = new Padding(3, 2, 3, 2); - Name = "FormBoatCollection"; - Text = "FormBoatCollection"; - ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); - panelTools.ResumeLayout(false); - panelTools.PerformLayout(); - ResumeLayout(false); - PerformLayout(); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(969, 604); + this.Controls.Add(this.panelTools); + this.Controls.Add(this.pictureBoxCollection); + this.Name = "FormBoatCollection"; + this.Text = "FormBoatCollection"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); + this.panelTools.ResumeLayout(false); + this.panelTools.PerformLayout(); + this.panelCollection.ResumeLayout(false); + this.panelCollection.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion @@ -128,5 +179,10 @@ private Button buttonRemoveBoat; private Button buttonAddBoat; private MaskedTextBox maskedTextBoxNumber; + private Panel panelCollection; + private Button buttonDelObject; + private ListBox listBoxStorages; + private Button buttonAddObject; + private TextBox textBoxStorageName; } } \ No newline at end of file diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs index 5b552d7..5510193 100644 --- a/Sailboat/Sailboat/FormBoatCollection.cs +++ b/Sailboat/Sailboat/FormBoatCollection.cs @@ -17,22 +17,55 @@ namespace Sailboat { public partial class FormBoatCollection : Form { - private readonly BoatsGenericCollection _boats; + private readonly BoatsGenericStorage _storage; public FormBoatCollection() { InitializeComponent(); - _boats = new BoatsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + _storage = new BoatsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); + + } + + private void ReloadObjects() + { + int index = listBoxStorages.SelectedIndex; + listBoxStorages.Items.Clear(); + + for (int i = 0; i < _storage.Keys.Count; i++) + { + listBoxStorages.Items.Add(_storage.Keys[i]); + } + + if (listBoxStorages.Items.Count > 0 && (index == -1 || index + >= listBoxStorages.Items.Count)) + { + listBoxStorages.SelectedIndex = 0; + } + else if (listBoxStorages.Items.Count > 0 && index > -1 && + index < listBoxStorages.Items.Count) + { + listBoxStorages.SelectedIndex = index; + } } private void buttonAddBoat_Click(object sender, EventArgs e) { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } FormSailboat form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_boats + form.SelectedBoat != -1) + if (obj + form.SelectedBoat) { MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = _boats.ShowBoats(); + pictureBoxCollection.Image = obj.ShowBoats(); } else { @@ -43,30 +76,80 @@ namespace Sailboat private void buttonRemoveBoat_Click(object sender, EventArgs e) { - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_boats - pos != null) + if (obj - pos != null) { MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = obj.ShowBoats(); } else { MessageBox.Show("Не удалось удалить объект"); - pictureBoxCollection.Image = _boats.ShowBoats(); } + } private void buttonRefreshCollection_Click(object sender, EventArgs e) { - pictureBoxCollection.Image = _boats.ShowBoats(); + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + pictureBoxCollection.Image = obj.ShowBoats(); + } - private void pictureBoxCollection_Click(object sender, EventArgs e) + private void buttonAddObject_Click(object sender, EventArgs e) { + if (string.IsNullOrEmpty(textBoxStorageName.Text)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _storage.AddSet(textBoxStorageName.Text); + ReloadObjects(); + } + private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBoxCollection.Image = + _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBoats(); + } + + private void buttonDelObject_Click(object sender, EventArgs e) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + if (MessageBox.Show($"Удалить объект { listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + _storage.DelSet(listBoxStorages.SelectedItem.ToString() + ?? string.Empty); + ReloadObjects(); + } } } } diff --git a/Sailboat/Sailboat/FormBoatCollection.resx b/Sailboat/Sailboat/FormBoatCollection.resx index af32865..f298a7b 100644 --- a/Sailboat/Sailboat/FormBoatCollection.resx +++ b/Sailboat/Sailboat/FormBoatCollection.resx @@ -1,64 +1,4 @@ - - - +