From 5687431a0f0c1db5f5027c525f11a490d683bd9d Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Sat, 5 Nov 2022 18:38:37 +0400 Subject: [PATCH 1/2] lab#5 --- .../ContainerShip/EntityContainerShip.cs | 7 +- ContainerShip/ContainerShip/EntityShip.cs | 7 +- .../ContainerShip/FormMapWithSetShip.cs | 31 +- .../ContainerShip/FormShipConfig.Designer.cs | 361 ++++++++++++++++++ ContainerShip/ContainerShip/FormShipConfig.cs | 140 +++++++ .../ContainerShip/FormShipConfig.resx | 60 +++ .../ContainerShip/MapWithSetShipGeneric.cs | 1 - ContainerShip/ContainerShip/MapsCollection.cs | 3 +- ContainerShip/ContainerShip/ShipDelegate.cs | 10 + 9 files changed, 595 insertions(+), 25 deletions(-) create mode 100644 ContainerShip/ContainerShip/FormShipConfig.Designer.cs create mode 100644 ContainerShip/ContainerShip/FormShipConfig.cs create mode 100644 ContainerShip/ContainerShip/FormShipConfig.resx create mode 100644 ContainerShip/ContainerShip/ShipDelegate.cs diff --git a/ContainerShip/ContainerShip/EntityContainerShip.cs b/ContainerShip/ContainerShip/EntityContainerShip.cs index 38f8b88..6015d7d 100644 --- a/ContainerShip/ContainerShip/EntityContainerShip.cs +++ b/ContainerShip/ContainerShip/EntityContainerShip.cs @@ -8,9 +8,9 @@ namespace ContainerShip { internal class EntityContainerShip : EntityShip { - public Color DopColor { get; private set; } - public bool Crane { get; private set; } - public bool Containers { get; private set; } + public Color DopColor { get; set; } + public bool Crane { get; set; } + public bool Containers { get; set; } public EntityContainerShip(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool containers) : @@ -21,5 +21,4 @@ namespace ContainerShip Containers = containers; } } - } diff --git a/ContainerShip/ContainerShip/EntityShip.cs b/ContainerShip/ContainerShip/EntityShip.cs index 6b162ac..ce39abb 100644 --- a/ContainerShip/ContainerShip/EntityShip.cs +++ b/ContainerShip/ContainerShip/EntityShip.cs @@ -8,9 +8,9 @@ namespace ContainerShip { public class EntityShip { - public int Speed { get; private set; } - public float Weight { get; private set; } - public Color BodyColor { get; private set; } + public int Speed { get; set; } + public float Weight { get; set; } + public Color BodyColor { get; set; } public int Step => (int)Speed * 100 / (int)Weight; public EntityShip(int speed, float weight, Color bodyColor) @@ -20,6 +20,5 @@ namespace ContainerShip Weight = weight <= 0 ? random.Next(50, 150) : weight; BodyColor = bodyColor; } - } } diff --git a/ContainerShip/ContainerShip/FormMapWithSetShip.cs b/ContainerShip/ContainerShip/FormMapWithSetShip.cs index 3edbbd1..25e65f9 100644 --- a/ContainerShip/ContainerShip/FormMapWithSetShip.cs +++ b/ContainerShip/ContainerShip/FormMapWithSetShip.cs @@ -103,26 +103,29 @@ namespace ContainerShip } private void ButtonAddShip_Click(object sender, EventArgs e) { - if (_mapShipCollectionGeneric == null) + var formShipConfig = new FormShipConfig(); + formShipConfig.AddEvent(AddShip); + formShipConfig.Show(); + } + + private void AddShip(DrawingShip ship) + { + if (listBoxMaps.SelectedIndex == -1) { return; } - FormShip form = new(); - if (form.ShowDialog() == DialogResult.OK) + DrawingObjectShip objectShip = new(ship); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + objectShip != -1) { - DrawingObjectShip ship = new(form.SelectedShip); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + ship != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Object added"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Failed to add object"); } } - + private void ButtonRemoveShip_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) diff --git a/ContainerShip/ContainerShip/FormShipConfig.Designer.cs b/ContainerShip/ContainerShip/FormShipConfig.Designer.cs new file mode 100644 index 0000000..29b8d51 --- /dev/null +++ b/ContainerShip/ContainerShip/FormShipConfig.Designer.cs @@ -0,0 +1,361 @@ +namespace ContainerShip +{ + partial class FormShipConfig + { + /// + /// 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.groupBoxConfig = new System.Windows.Forms.GroupBox(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColors = new System.Windows.Forms.GroupBox(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxContainers = new System.Windows.Forms.CheckBox(); + this.checkBoxCrane = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.panelObject = new System.Windows.Forms.Panel(); + this.labelDopColor = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.labelBaseColor = new System.Windows.Forms.Label(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxConfig.SuspendLayout(); + this.groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + this.panelObject.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxConfig + // + this.groupBoxConfig.Controls.Add(this.labelModifiedObject); + this.groupBoxConfig.Controls.Add(this.labelSimpleObject); + this.groupBoxConfig.Controls.Add(this.groupBoxColors); + this.groupBoxConfig.Controls.Add(this.checkBoxContainers); + this.groupBoxConfig.Controls.Add(this.checkBoxCrane); + this.groupBoxConfig.Controls.Add(this.numericUpDownWeight); + this.groupBoxConfig.Controls.Add(this.labelWeight); + this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed); + this.groupBoxConfig.Controls.Add(this.labelSpeed); + this.groupBoxConfig.Location = new System.Drawing.Point(12, 12); + this.groupBoxConfig.Name = "groupBoxConfig"; + this.groupBoxConfig.Size = new System.Drawing.Size(406, 195); + this.groupBoxConfig.TabIndex = 0; + this.groupBoxConfig.TabStop = false; + this.groupBoxConfig.Text = "Параметры"; + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(307, 136); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(91, 56); + this.labelModifiedObject.TabIndex = 8; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(209, 136); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(92, 56); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // groupBoxColors + // + this.groupBoxColors.Controls.Add(this.panelGray); + this.groupBoxColors.Controls.Add(this.panelBlack); + this.groupBoxColors.Controls.Add(this.panelGreen); + this.groupBoxColors.Controls.Add(this.panelPurple); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelYellow); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(209, 17); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Size = new System.Drawing.Size(189, 116); + this.groupBoxColors.TabIndex = 6; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Цвета"; + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(52, 68); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(40, 40); + this.panelGray.TabIndex = 3; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(98, 68); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(40, 40); + this.panelBlack.TabIndex = 4; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.Lime; + this.panelGreen.Location = new System.Drawing.Point(52, 22); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(40, 40); + this.panelGreen.TabIndex = 1; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(192))))); + this.panelPurple.Location = new System.Drawing.Point(144, 68); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(40, 40); + this.panelPurple.TabIndex = 5; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(98, 22); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(40, 40); + this.panelBlue.TabIndex = 1; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(6, 68); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(40, 40); + this.panelWhite.TabIndex = 2; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(144, 22); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(40, 40); + this.panelYellow.TabIndex = 1; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(6, 22); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(40, 40); + this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // checkBoxContainers + // + this.checkBoxContainers.AutoSize = true; + this.checkBoxContainers.Location = new System.Drawing.Point(6, 97); + this.checkBoxContainers.Name = "checkBoxContainers"; + this.checkBoxContainers.Size = new System.Drawing.Size(197, 19); + this.checkBoxContainers.TabIndex = 5; + this.checkBoxContainers.Text = "Признак наличия контейнеров"; + this.checkBoxContainers.UseVisualStyleBackColor = true; + // + // checkBoxCrane + // + this.checkBoxCrane.AutoSize = true; + this.checkBoxCrane.Location = new System.Drawing.Point(6, 72); + this.checkBoxCrane.Name = "checkBoxCrane"; + this.checkBoxCrane.Size = new System.Drawing.Size(158, 19); + this.checkBoxCrane.TabIndex = 4; + this.checkBoxCrane.Text = "Признак наличия крана"; + this.checkBoxCrane.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(71, 43); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(53, 23); + this.numericUpDownWeight.TabIndex = 3; + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(6, 45); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(26, 15); + this.labelWeight.TabIndex = 2; + this.labelWeight.Text = "Вес"; + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(71, 17); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(53, 23); + this.numericUpDownSpeed.TabIndex = 1; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(6, 19); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(59, 15); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость"; + // + // panelObject + // + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.labelDopColor); + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Controls.Add(this.labelBaseColor); + this.panelObject.Location = new System.Drawing.Point(424, 29); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(229, 146); + this.panelObject.TabIndex = 1; + this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); + // + // labelDopColor + // + this.labelDopColor.AllowDrop = true; + this.labelDopColor.BackColor = System.Drawing.SystemColors.Control; + this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelDopColor.Location = new System.Drawing.Point(126, 2); + this.labelDopColor.Name = "labelDopColor"; + this.labelDopColor.Size = new System.Drawing.Size(100, 23); + this.labelDopColor.TabIndex = 2; + this.labelDopColor.Text = "Доп. цвет"; + this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop); + this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter); + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(3, 28); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(223, 115); + this.pictureBoxObject.TabIndex = 1; + this.pictureBoxObject.TabStop = false; + // + // labelBaseColor + // + this.labelBaseColor.AllowDrop = true; + this.labelBaseColor.BackColor = System.Drawing.SystemColors.Control; + this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelBaseColor.Location = new System.Drawing.Point(3, 2); + this.labelBaseColor.Name = "labelBaseColor"; + this.labelBaseColor.Size = new System.Drawing.Size(100, 23); + this.labelBaseColor.TabIndex = 0; + this.labelBaseColor.Text = "Цвет"; + this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop); + this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter); + // + // buttonOk + // + this.buttonOk.Location = new System.Drawing.Point(427, 184); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(75, 23); + this.buttonOk.TabIndex = 2; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(575, 184); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormShipConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(662, 219); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOk); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxConfig); + this.Name = "FormShipConfig"; + this.Text = "Создание объекта"; + this.groupBoxConfig.ResumeLayout(false); + this.groupBoxConfig.PerformLayout(); + this.groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + this.panelObject.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxConfig; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelSpeed; + private Label labelModifiedObject; + private Label labelSimpleObject; + private GroupBox groupBoxColors; + private Panel panelGray; + private Panel panelBlack; + private Panel panelGreen; + private Panel panelPurple; + private Panel panelBlue; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelRed; + private CheckBox checkBoxContainers; + private CheckBox checkBoxCrane; + private Panel panelObject; + private Label labelDopColor; + private PictureBox pictureBoxObject; + private Label labelBaseColor; + private Button buttonOk; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ContainerShip/ContainerShip/FormShipConfig.cs b/ContainerShip/ContainerShip/FormShipConfig.cs new file mode 100644 index 0000000..d32c051 --- /dev/null +++ b/ContainerShip/ContainerShip/FormShipConfig.cs @@ -0,0 +1,140 @@ +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 ContainerShip +{ + public partial class FormShipConfig : Form + { + DrawingShip _ship = null; + + private event ShipDelegate EventAddShip; + + public FormShipConfig() + { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + + + buttonCancel.Click += (object sender, EventArgs e) => + { + Close(); + }; + } + + private void DrawShip() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _ship?.SetPosition(5, 5, pictureBoxObject.Width, + pictureBoxObject.Height); + _ship?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + public void AddEvent(ShipDelegate ev) + { + if (EventAddShip == null) + { + EventAddShip = new ShipDelegate(ev); + } + else + { + EventAddShip += ev; + } + } + + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label).DoDragDrop((sender as Label).Name, + DragDropEffects.Move | DragDropEffects.Copy); + } + + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.Text)) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _ship = new DrawingShip((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White); + break; + case "labelModifiedObject": + _ship = new DrawingContainerShip((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, + checkBoxCrane.Checked, checkBoxContainers.Checked); + break; + } + DrawShip(); + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control).DoDragDrop((sender as Control).BackColor, + DragDropEffects.Move | DragDropEffects.Copy); + } + + private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) + { + if (_ship == null) + { + return; + } + _ship.Ship.BodyColor = (Color)e.Data.GetData(typeof(Color)); + DrawShip(); + } + + private void LabelDopColor_DragDrop(object sender, DragEventArgs e) + { + if (_ship == null || _ship.Ship is not EntityContainerShip containerShip) + { + return; + } + containerShip.DopColor = (Color)e.Data.GetData(typeof(Color)); + DrawShip(); + } + + + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddShip?.Invoke(_ship); + Close(); + } + } +} diff --git a/ContainerShip/ContainerShip/FormShipConfig.resx b/ContainerShip/ContainerShip/FormShipConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ContainerShip/ContainerShip/FormShipConfig.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/ContainerShip/ContainerShip/MapWithSetShipGeneric.cs b/ContainerShip/ContainerShip/MapWithSetShipGeneric.cs index 763a50c..afbc8f6 100644 --- a/ContainerShip/ContainerShip/MapWithSetShipGeneric.cs +++ b/ContainerShip/ContainerShip/MapWithSetShipGeneric.cs @@ -159,5 +159,4 @@ namespace ContainerShip } } } - } diff --git a/ContainerShip/ContainerShip/MapsCollection.cs b/ContainerShip/ContainerShip/MapsCollection.cs index 18a3483..a321740 100644 --- a/ContainerShip/ContainerShip/MapsCollection.cs +++ b/ContainerShip/ContainerShip/MapsCollection.cs @@ -8,8 +8,7 @@ namespace ContainerShip { internal class MapsCollection { - readonly Dictionary> _mapStorages; - + readonly Dictionary> _mapStorages; public List Keys => _mapStorages.Keys.ToList(); private readonly int _pictureWidth; diff --git a/ContainerShip/ContainerShip/ShipDelegate.cs b/ContainerShip/ContainerShip/ShipDelegate.cs new file mode 100644 index 0000000..2c322fd --- /dev/null +++ b/ContainerShip/ContainerShip/ShipDelegate.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + public delegate void ShipDelegate(DrawingShip ship); +} -- 2.25.1 From a36cba08959a321be2609c86a38ad230e8051300 Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Fri, 25 Nov 2022 15:34:30 +0400 Subject: [PATCH 2/2] done --- ContainerShip/ContainerShip/DrawingShip.cs | 2 - ContainerShip/ContainerShip/EntityShip.cs | 2 +- .../FormMapWithSetShip.Designer.cs | 3 +- .../ContainerShip/FormMapWithSetShip.cs | 49 +++++-------------- ContainerShip/ContainerShip/FormShipConfig.cs | 11 ++--- ContainerShip/ContainerShip/ShipDelegate.cs | 10 ---- 6 files changed, 17 insertions(+), 60 deletions(-) delete mode 100644 ContainerShip/ContainerShip/ShipDelegate.cs diff --git a/ContainerShip/ContainerShip/DrawingShip.cs b/ContainerShip/ContainerShip/DrawingShip.cs index 6f1f74a..3ee5aea 100644 --- a/ContainerShip/ContainerShip/DrawingShip.cs +++ b/ContainerShip/ContainerShip/DrawingShip.cs @@ -106,8 +106,6 @@ namespace ContainerShip g.FillPolygon(brRed, shipBorder); //Заливка верхней палубы g.FillRectangle(brMain, _startPosX + 21, _startPosY + 1, 59, 29); - - } public void ChangeBorders(int width, int height) { diff --git a/ContainerShip/ContainerShip/EntityShip.cs b/ContainerShip/ContainerShip/EntityShip.cs index ce39abb..38a79ef 100644 --- a/ContainerShip/ContainerShip/EntityShip.cs +++ b/ContainerShip/ContainerShip/EntityShip.cs @@ -17,7 +17,7 @@ namespace ContainerShip { Random random = new Random(); Speed = speed <= 0 ? random.Next(50, 150) : speed; - Weight = weight <= 0 ? random.Next(50, 150) : weight; + Weight = weight <= 0 ? random.Next(1000, 2000) : weight; BodyColor = bodyColor; } } diff --git a/ContainerShip/ContainerShip/FormMapWithSetShip.Designer.cs b/ContainerShip/ContainerShip/FormMapWithSetShip.Designer.cs index 0d0124d..315a49c 100644 --- a/ContainerShip/ContainerShip/FormMapWithSetShip.Designer.cs +++ b/ContainerShip/ContainerShip/FormMapWithSetShip.Designer.cs @@ -132,8 +132,7 @@ this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 51); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(176, 23); - this.comboBoxSelectorMap.TabIndex = 18; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + this.comboBoxSelectorMap.TabIndex = 18; // // maskedTextBoxPosition // diff --git a/ContainerShip/ContainerShip/FormMapWithSetShip.cs b/ContainerShip/ContainerShip/FormMapWithSetShip.cs index 25e65f9..a5af32e 100644 --- a/ContainerShip/ContainerShip/FormMapWithSetShip.cs +++ b/ContainerShip/ContainerShip/FormMapWithSetShip.cs @@ -11,11 +11,7 @@ using System.Windows.Forms; namespace ContainerShip { public partial class FormMapWithSetShip : Form - { - - private MapWithSetShipGeneric _mapShipCollectionGeneric; - - + { private readonly Dictionary _mapsDict = new() { { "Простая карта", new SimpleMap()}, @@ -75,32 +71,6 @@ namespace ContainerShip ReloadMaps(); } - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - AbstractMap map = null; - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - map = new SimpleMap(); - break; - case "Острова": - map = new IslandsMap(); - break; - case "Скалы": - map = new RocksMap(); - break; - } - if (map != null) - { - _mapShipCollectionGeneric = new - MapWithSetShipGeneric( - pictureBox.Width, pictureBox.Height, map); - } - else - { - _mapShipCollectionGeneric = null; - } - } private void ButtonAddShip_Click(object sender, EventArgs e) { var formShipConfig = new FormShipConfig(); @@ -128,20 +98,23 @@ namespace ContainerShip private void ButtonRemoveShip_Click(object sender, EventArgs e) { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapShipCollectionGeneric - pos != null) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -151,12 +124,12 @@ namespace ContainerShip private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapShipCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); - + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } private void ButtonShowOnMap_Click(object sender, EventArgs e) diff --git a/ContainerShip/ContainerShip/FormShipConfig.cs b/ContainerShip/ContainerShip/FormShipConfig.cs index d32c051..479232b 100644 --- a/ContainerShip/ContainerShip/FormShipConfig.cs +++ b/ContainerShip/ContainerShip/FormShipConfig.cs @@ -14,7 +14,7 @@ namespace ContainerShip { DrawingShip _ship = null; - private event ShipDelegate EventAddShip; + private event Action EventAddShip; public FormShipConfig() { @@ -29,10 +29,7 @@ namespace ContainerShip panelBlue.MouseDown += PanelColor_MouseDown; - buttonCancel.Click += (object sender, EventArgs e) => - { - Close(); - }; + buttonCancel.Click += (object sender, EventArgs e) => Close(); } private void DrawShip() @@ -45,11 +42,11 @@ namespace ContainerShip pictureBoxObject.Image = bmp; } - public void AddEvent(ShipDelegate ev) + public void AddEvent(Action ev) { if (EventAddShip == null) { - EventAddShip = new ShipDelegate(ev); + EventAddShip = new Action(ev); } else { diff --git a/ContainerShip/ContainerShip/ShipDelegate.cs b/ContainerShip/ContainerShip/ShipDelegate.cs deleted file mode 100644 index 2c322fd..0000000 --- a/ContainerShip/ContainerShip/ShipDelegate.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ContainerShip -{ - public delegate void ShipDelegate(DrawingShip ship); -} -- 2.25.1