From 1516f11c255af2a47a6c50f9579c03ea0a0c7e9e Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Wed, 8 Nov 2023 08:34:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Battleship/Battleship/FormShipCollection.cs | 12 + .../Battleship/FormShipConfig.Designer.cs | 380 ++++++++++++++++++ Battleship/Battleship/FormShipConfig.cs | 139 +++++++ Battleship/Battleship/FormShipConfig.resx | 60 +++ Battleship/Battleship/ShipDelegate.cs | 15 + 5 files changed, 606 insertions(+) create mode 100644 Battleship/Battleship/FormShipConfig.Designer.cs create mode 100644 Battleship/Battleship/FormShipConfig.cs create mode 100644 Battleship/Battleship/FormShipConfig.resx create mode 100644 Battleship/Battleship/ShipDelegate.cs diff --git a/Battleship/Battleship/FormShipCollection.cs b/Battleship/Battleship/FormShipCollection.cs index 404ff0e..962a37b 100644 --- a/Battleship/Battleship/FormShipCollection.cs +++ b/Battleship/Battleship/FormShipCollection.cs @@ -162,6 +162,18 @@ namespace Battleship } pictureBoxCollection.Image = obj.ShowShips(); } + + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAddCar_Click(object sender, EventArgs e) + { + var formCarConfig = new FormShipConfig(); + // TODO Call method AddEvent from formCarConfig + formCarConfig.Show(); + } } } diff --git a/Battleship/Battleship/FormShipConfig.Designer.cs b/Battleship/Battleship/FormShipConfig.Designer.cs new file mode 100644 index 0000000..5abbb75 --- /dev/null +++ b/Battleship/Battleship/FormShipConfig.Designer.cs @@ -0,0 +1,380 @@ +namespace Battleship +{ + 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.groupBoxParameters = new System.Windows.Forms.GroupBox(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColor = new System.Windows.Forms.GroupBox(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxRocket = new System.Windows.Forms.CheckBox(); + this.checkBoxTower = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.panelPicture = new System.Windows.Forms.Panel(); + this.labelAddColor = new System.Windows.Forms.Label(); + this.labelBodyColor = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxParameters.SuspendLayout(); + this.groupBoxColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + this.panelPicture.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxParameters + // + this.groupBoxParameters.Controls.Add(this.labelModifiedObject); + this.groupBoxParameters.Controls.Add(this.labelSimpleObject); + this.groupBoxParameters.Controls.Add(this.groupBoxColor); + this.groupBoxParameters.Controls.Add(this.checkBoxRocket); + this.groupBoxParameters.Controls.Add(this.checkBoxTower); + this.groupBoxParameters.Controls.Add(this.numericUpDownWeight); + this.groupBoxParameters.Controls.Add(this.numericUpDownSpeed); + this.groupBoxParameters.Controls.Add(this.labelWeight); + this.groupBoxParameters.Controls.Add(this.labelSpeed); + this.groupBoxParameters.Location = new System.Drawing.Point(12, 1); + this.groupBoxParameters.Name = "groupBoxParameters"; + this.groupBoxParameters.Size = new System.Drawing.Size(514, 287); + this.groupBoxParameters.TabIndex = 0; + this.groupBoxParameters.TabStop = false; + this.groupBoxParameters.Text = "Параметры"; + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(377, 208); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(109, 38); + 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(229, 208); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(109, 38); + 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); + // + // groupBoxColor + // + this.groupBoxColor.Controls.Add(this.panelPurple); + this.groupBoxColor.Controls.Add(this.panelBlack); + this.groupBoxColor.Controls.Add(this.panelGray); + this.groupBoxColor.Controls.Add(this.panelWhite); + this.groupBoxColor.Controls.Add(this.panelYellow); + this.groupBoxColor.Controls.Add(this.panelBlue); + this.groupBoxColor.Controls.Add(this.panelGreen); + this.groupBoxColor.Controls.Add(this.panelRed); + this.groupBoxColor.Location = new System.Drawing.Point(229, 22); + this.groupBoxColor.Name = "groupBoxColor"; + this.groupBoxColor.Size = new System.Drawing.Size(257, 167); + this.groupBoxColor.TabIndex = 6; + this.groupBoxColor.TabStop = false; + this.groupBoxColor.Text = "Цвета"; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(187, 78); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(50, 50); + this.panelPurple.TabIndex = 0; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(131, 78); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(50, 50); + this.panelBlack.TabIndex = 0; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(75, 78); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(50, 50); + this.panelGray.TabIndex = 7; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(19, 78); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(50, 50); + this.panelWhite.TabIndex = 0; + 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(187, 22); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(50, 50); + this.panelYellow.TabIndex = 0; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192))))); + this.panelBlue.Location = new System.Drawing.Point(131, 22); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(50, 50); + this.panelBlue.TabIndex = 0; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); + this.panelGreen.Location = new System.Drawing.Point(75, 22); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(50, 50); + this.panelGreen.TabIndex = 0; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(19, 22); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(50, 50); + this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // checkBoxRocket + // + this.checkBoxRocket.AutoSize = true; + this.checkBoxRocket.Location = new System.Drawing.Point(10, 208); + this.checkBoxRocket.Name = "checkBoxRocket"; + this.checkBoxRocket.Size = new System.Drawing.Size(180, 19); + this.checkBoxRocket.TabIndex = 5; + this.checkBoxRocket.Text = "Наличие отсеков под ракет "; + this.checkBoxRocket.UseVisualStyleBackColor = true; + // + // checkBoxTower + // + this.checkBoxTower.AutoSize = true; + this.checkBoxTower.Location = new System.Drawing.Point(10, 170); + this.checkBoxTower.Name = "checkBoxTower"; + this.checkBoxTower.Size = new System.Drawing.Size(180, 19); + this.checkBoxTower.TabIndex = 4; + this.checkBoxTower.Text = "Наличие орудийной башни"; + this.checkBoxTower.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(81, 100); + this.numericUpDownWeight.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownWeight.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(120, 23); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(81, 44); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(120, 23); + this.numericUpDownSpeed.TabIndex = 2; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(10, 100); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(32, 15); + this.labelWeight.TabIndex = 1; + this.labelWeight.Text = "Вес :"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(10, 41); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(65, 15); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость :"; + // + // panelPicture + // + this.panelPicture.AllowDrop = true; + this.panelPicture.Controls.Add(this.labelAddColor); + this.panelPicture.Controls.Add(this.labelBodyColor); + this.panelPicture.Controls.Add(this.pictureBoxObject); + this.panelPicture.Location = new System.Drawing.Point(532, 12); + this.panelPicture.Name = "panelPicture"; + this.panelPicture.Size = new System.Drawing.Size(256, 216); + this.panelPicture.TabIndex = 9; + // + // labelAddColor + // + this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAddColor.Location = new System.Drawing.Point(145, 17); + this.labelAddColor.Name = "labelAddColor"; + this.labelAddColor.Size = new System.Drawing.Size(97, 28); + this.labelAddColor.TabIndex = 12; + this.labelAddColor.Text = "Доп. цвет"; + this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // labelBodyColor + // + this.labelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelBodyColor.Location = new System.Drawing.Point(15, 17); + this.labelBodyColor.Name = "labelBodyColor"; + this.labelBodyColor.Size = new System.Drawing.Size(97, 28); + this.labelBodyColor.TabIndex = 11; + this.labelBodyColor.Text = "Цвет"; + this.labelBodyColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(15, 58); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(227, 139); + this.pictureBoxObject.TabIndex = 10; + this.pictureBoxObject.TabStop = false; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(547, 244); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(97, 32); + this.buttonAdd.TabIndex = 13; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(677, 244); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(97, 32); + this.buttonCancel.TabIndex = 14; + 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(800, 288); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.panelPicture); + this.Controls.Add(this.groupBoxParameters); + this.Name = "FormShipConfig"; + this.Text = "FormShipConfig"; + this.groupBoxParameters.ResumeLayout(false); + this.groupBoxParameters.PerformLayout(); + this.groupBoxColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + this.panelPicture.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxParameters; + private Label labelWeight; + private Label labelSpeed; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelModifiedObject; + private Label labelSimpleObject; + private GroupBox groupBoxColor; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private CheckBox checkBoxRocket; + private CheckBox checkBoxTower; + private Panel panelPicture; + private PictureBox pictureBoxObject; + private Label labelAddColor; + private Label labelBodyColor; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Battleship/Battleship/FormShipConfig.cs b/Battleship/Battleship/FormShipConfig.cs new file mode 100644 index 0000000..dc1a6a9 --- /dev/null +++ b/Battleship/Battleship/FormShipConfig.cs @@ -0,0 +1,139 @@ +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 Battleship.DrawningObjects; +using Battleship.Entities; + +namespace Battleship +{ + public partial class FormShipConfig : Form + { + /// + /// Переменная-выбранная машина + /// + DrawningShip? _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; + + // TODO buttonCancel.Click with lambda + } + /// + /// Отрисовать машину + /// + private void DrawCar() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _ship?.SetPosition(5, 5); + _ship?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(ShipDelegate ev) + { + if (EventAddShip == null) + { + EventAddShip = ev; + } + else + { + EventAddShip += ev; + } + } + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + 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) ?? false) + { + 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 DrawningShip((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, pictureBoxObject.Height); + break; + case "labelModifiedObject": + _ship = new DrawningBattleship((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxTower.Checked, + checkBoxRocket.Checked, pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + DrawCar(); + } + // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) + /// + /// Добавление машины + /// + /// + /// + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddShip?.Invoke(_ship); + Close(); + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + + } + } +} + + + + + + + diff --git a/Battleship/Battleship/FormShipConfig.resx b/Battleship/Battleship/FormShipConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Battleship/Battleship/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/Battleship/Battleship/ShipDelegate.cs b/Battleship/Battleship/ShipDelegate.cs new file mode 100644 index 0000000..ed731ea --- /dev/null +++ b/Battleship/Battleship/ShipDelegate.cs @@ -0,0 +1,15 @@ +using Battleship.DrawningObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Battleship +{ + /// + /// Делегат для передачи объекта-автомобиля + /// + /// + public delegate void ShipDelegate(DrawningShip car); +}