diff --git a/Battleship/Battleship/EntityBattleship.cs b/Battleship/Battleship/EntityBattleship.cs index bb54fa5..d44f3f7 100644 --- a/Battleship/Battleship/EntityBattleship.cs +++ b/Battleship/Battleship/EntityBattleship.cs @@ -22,7 +22,7 @@ namespace Battleship /// /// Цвет кузова /// - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } /// /// Шаг перемещения боевого корабля /// diff --git a/Battleship/Battleship/FormBattleshipConfig.Designer.cs b/Battleship/Battleship/FormBattleshipConfig.Designer.cs new file mode 100644 index 0000000..056484c --- /dev/null +++ b/Battleship/Battleship/FormBattleshipConfig.Designer.cs @@ -0,0 +1,374 @@ +namespace Battleship +{ + partial class FormBattleshipConfig + { + // + /// 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.LabelGunBattleship = new System.Windows.Forms.Label(); + this.LabelBasicBattleship = new System.Windows.Forms.Label(); + this.GroupBoxColors = new System.Windows.Forms.GroupBox(); + this.PanelSilver = new System.Windows.Forms.Panel(); + this.PanelRed = new System.Windows.Forms.Panel(); + this.PanelBlue = new System.Windows.Forms.Panel(); + this.PanelCyan = new System.Windows.Forms.Panel(); + this.PanelLime = new System.Windows.Forms.Panel(); + this.PanelFuchsia = new System.Windows.Forms.Panel(); + this.PanelYellow = new System.Windows.Forms.Panel(); + this.PanelOrange = new System.Windows.Forms.Panel(); + this.CheckBoxCompartmentRocket = new System.Windows.Forms.CheckBox(); + this.CheckBoxGunTower = new System.Windows.Forms.CheckBox(); + this.CheckBoxSternFence = 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.PictureBoxBattleship = new System.Windows.Forms.PictureBox(); + this.PanelBattleship = new System.Windows.Forms.Panel(); + this.LabelModifColor = new System.Windows.Forms.Label(); + this.LabelBodyColor = new System.Windows.Forms.Label(); + this.ButtomAdd = 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(); + ((System.ComponentModel.ISupportInitialize)(this.PictureBoxBattleship)).BeginInit(); + this.PanelBattleship.SuspendLayout(); + this.SuspendLayout(); + // + // GroupBoxConfig + // + this.GroupBoxConfig.Controls.Add(this.LabelGunBattleship); + this.GroupBoxConfig.Controls.Add(this.LabelBasicBattleship); + this.GroupBoxConfig.Controls.Add(this.GroupBoxColors); + this.GroupBoxConfig.Controls.Add(this.CheckBoxCompartmentRocket); + this.GroupBoxConfig.Controls.Add(this.CheckBoxGunTower); + this.GroupBoxConfig.Controls.Add(this.CheckBoxSternFence); + this.GroupBoxConfig.Controls.Add(this.NumericUpDownWeight); + this.GroupBoxConfig.Controls.Add(this.NumericUpDownSpeed); + this.GroupBoxConfig.Controls.Add(this.LabelWeight); + 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(596, 241); + this.GroupBoxConfig.TabIndex = 0; + this.GroupBoxConfig.TabStop = false; + this.GroupBoxConfig.Text = "Параметры: "; + // + // LabelGunBattleship + // + this.LabelGunBattleship.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.LabelGunBattleship.Location = new System.Drawing.Point(452, 183); + this.LabelGunBattleship.Name = "LabelGunBattleship"; + this.LabelGunBattleship.Size = new System.Drawing.Size(123, 41); + this.LabelGunBattleship.TabIndex = 9; + this.LabelGunBattleship.Text = "Продвинутый корабль"; + this.LabelGunBattleship.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.LabelGunBattleship.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelBattleship_MouseDown); + // + // LabelBasicBattleship + // + this.LabelBasicBattleship.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.LabelBasicBattleship.Location = new System.Drawing.Point(321, 183); + this.LabelBasicBattleship.Name = "LabelBasicBattleship"; + this.LabelBasicBattleship.Size = new System.Drawing.Size(125, 41); + this.LabelBasicBattleship.TabIndex = 8; + this.LabelBasicBattleship.Text = "Обычный корабль"; + this.LabelBasicBattleship.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.LabelBasicBattleship.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelBattleship_MouseDown); + // + // GroupBoxColors + // + this.GroupBoxColors.Controls.Add(this.PanelSilver); + this.GroupBoxColors.Controls.Add(this.PanelRed); + this.GroupBoxColors.Controls.Add(this.PanelBlue); + this.GroupBoxColors.Controls.Add(this.PanelCyan); + this.GroupBoxColors.Controls.Add(this.PanelLime); + this.GroupBoxColors.Controls.Add(this.PanelFuchsia); + this.GroupBoxColors.Controls.Add(this.PanelYellow); + this.GroupBoxColors.Controls.Add(this.PanelOrange); + this.GroupBoxColors.Location = new System.Drawing.Point(321, 24); + this.GroupBoxColors.Name = "GroupBoxColors"; + this.GroupBoxColors.Size = new System.Drawing.Size(254, 144); + this.GroupBoxColors.TabIndex = 7; + this.GroupBoxColors.TabStop = false; + this.GroupBoxColors.Text = "Цвета: "; + // + // PanelSilver + // + this.PanelSilver.BackColor = System.Drawing.Color.Silver; + this.PanelSilver.Location = new System.Drawing.Point(191, 78); + this.PanelSilver.Name = "PanelSilver"; + this.PanelSilver.Size = new System.Drawing.Size(44, 45); + this.PanelSilver.TabIndex = 1; + // + // PanelRed + // + this.PanelRed.BackColor = System.Drawing.Color.Red; + this.PanelRed.Location = new System.Drawing.Point(136, 78); + this.PanelRed.Name = "PanelRed"; + this.PanelRed.Size = new System.Drawing.Size(46, 45); + this.PanelRed.TabIndex = 1; + // + // PanelBlue + // + this.PanelBlue.BackColor = System.Drawing.Color.Blue; + this.PanelBlue.Location = new System.Drawing.Point(79, 78); + this.PanelBlue.Name = "PanelBlue"; + this.PanelBlue.Size = new System.Drawing.Size(46, 45); + this.PanelBlue.TabIndex = 1; + // + // PanelCyan + // + this.PanelCyan.BackColor = System.Drawing.Color.Cyan; + this.PanelCyan.Location = new System.Drawing.Point(20, 78); + this.PanelCyan.Name = "PanelCyan"; + this.PanelCyan.Size = new System.Drawing.Size(48, 45); + this.PanelCyan.TabIndex = 1; + // + // PanelLime + // + this.PanelLime.BackColor = System.Drawing.Color.Lime; + this.PanelLime.Location = new System.Drawing.Point(191, 24); + this.PanelLime.Name = "PanelLime"; + this.PanelLime.Size = new System.Drawing.Size(44, 45); + this.PanelLime.TabIndex = 1; + // + // PanelFuchsia + // + this.PanelFuchsia.BackColor = System.Drawing.Color.Fuchsia; + this.PanelFuchsia.Location = new System.Drawing.Point(136, 24); + this.PanelFuchsia.Name = "PanelFuchsia"; + this.PanelFuchsia.Size = new System.Drawing.Size(46, 45); + this.PanelFuchsia.TabIndex = 1; + // + // PanelYellow + // + this.PanelYellow.BackColor = System.Drawing.Color.Yellow; + this.PanelYellow.Location = new System.Drawing.Point(79, 24); + this.PanelYellow.Name = "PanelYellow"; + this.PanelYellow.Size = new System.Drawing.Size(46, 45); + this.PanelYellow.TabIndex = 1; + // + // PanelOrange + // + this.PanelOrange.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); + this.PanelOrange.Location = new System.Drawing.Point(20, 24); + this.PanelOrange.Name = "PanelOrange"; + this.PanelOrange.Size = new System.Drawing.Size(48, 45); + this.PanelOrange.TabIndex = 0; + // + // CheckBoxCompartmentRocket + // + this.CheckBoxCompartmentRocket.AutoSize = true; + this.CheckBoxCompartmentRocket.Location = new System.Drawing.Point(42, 205); + this.CheckBoxCompartmentRocket.Name = "CheckBoxCompartmentRocket"; + this.CheckBoxCompartmentRocket.Size = new System.Drawing.Size(200, 19); + this.CheckBoxCompartmentRocket.TabIndex = 6; + this.CheckBoxCompartmentRocket.Text = "Признак наличия отсека для ракет"; + this.CheckBoxCompartmentRocket.UseVisualStyleBackColor = true; + // + // CheckBoxGunTower + // + this.CheckBoxGunTower.AutoSize = true; + this.CheckBoxGunTower.Location = new System.Drawing.Point(42, 168); + this.CheckBoxGunTower.Name = "CheckBoxGunTower"; + this.CheckBoxGunTower.Size = new System.Drawing.Size(173, 19); + this.CheckBoxGunTower.TabIndex = 5; + this.CheckBoxGunTower.Text = "Признак наличия орудийной башни"; + this.CheckBoxGunTower.UseVisualStyleBackColor = true; + // + // CheckBoxSternFence + // + this.CheckBoxSternFence.AutoSize = true; + this.CheckBoxSternFence.Location = new System.Drawing.Point(42, 129); + this.CheckBoxSternFence.Name = "CheckBoxSternFence"; + this.CheckBoxSternFence.Size = new System.Drawing.Size(256, 19); + this.CheckBoxSternFence.TabIndex = 4; + this.CheckBoxSternFence.Text = "Признак наличия забора на корме"; + this.CheckBoxSternFence.UseVisualStyleBackColor = true; + // + // NumericUpDownWeight + // + this.NumericUpDownWeight.Location = new System.Drawing.Point(113, 78); + 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(113, 41); + 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(42, 80); + 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(42, 43); + this.LabelSpeed.Name = "LabelSpeed"; + this.LabelSpeed.Size = new System.Drawing.Size(65, 15); + this.LabelSpeed.TabIndex = 0; + this.LabelSpeed.Text = "Скорость: "; + // + // PictureBoxBattleship + // + this.PictureBoxBattleship.Location = new System.Drawing.Point(29, 53); + this.PictureBoxBattleship.Name = "PictureBoxBattleship"; + this.PictureBoxBattleship.Size = new System.Drawing.Size(240, 136); + this.PictureBoxBattleship.TabIndex = 1; + this.PictureBoxBattleship.TabStop = false; + // + // PanelBattleship + // + this.PanelBattleship.AllowDrop = true; + this.PanelBattleship.Controls.Add(this.LabelModifColor); + this.PanelBattleship.Controls.Add(this.LabelBodyColor); + this.PanelBattleship.Controls.Add(this.PictureBoxBattleship); + this.PanelBattleship.Location = new System.Drawing.Point(621, 20); + this.PanelBattleship.Name = "PanelBattleship"; + this.PanelBattleship.Size = new System.Drawing.Size(298, 197); + this.PanelBattleship.TabIndex = 2; + this.PanelBattleship.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelBattleship_DragDrop); + this.PanelBattleship.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelBattleship_DragEnter); + // + // LabelModifColor + // + this.LabelModifColor.AllowDrop = true; + this.LabelModifColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.LabelModifColor.Location = new System.Drawing.Point(153, 8); + this.LabelModifColor.Name = "LabelModifColor"; + this.LabelModifColor.Size = new System.Drawing.Size(116, 38); + this.LabelModifColor.TabIndex = 3; + this.LabelModifColor.Text = "Цвет модификаций корабля"; + this.LabelModifColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.LabelModifColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelModifColor_DragDrop); + this.LabelModifColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelModifColor_DragEnter); + // + // LabelBodyColor + // + this.LabelBodyColor.AllowDrop = true; + this.LabelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.LabelBodyColor.Location = new System.Drawing.Point(29, 8); + this.LabelBodyColor.Name = "LabelBodyColor"; + this.LabelBodyColor.Size = new System.Drawing.Size(118, 38); + this.LabelBodyColor.TabIndex = 2; + this.LabelBodyColor.Text = "Цвет корпуса корабля"; + this.LabelBodyColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.LabelBodyColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBodyColor_DragDrop); + this.LabelBodyColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBodyColor_DragEnter); + // + // ButtomAdd + // + this.ButtomAdd.Location = new System.Drawing.Point(685, 227); + this.ButtomAdd.Name = "ButtomAdd"; + this.ButtomAdd.Size = new System.Drawing.Size(83, 27); + this.ButtomAdd.TabIndex = 3; + this.ButtomAdd.Text = "Добавить"; + this.ButtomAdd.UseVisualStyleBackColor = true; + this.ButtomAdd.Click += new System.EventHandler(this.ButtomAdd_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(783, 227); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(79, 27); + this.ButtonCancel.TabIndex = 4; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + // + // FormBattleshipConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(935, 266); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtomAdd); + this.Controls.Add(this.PanelBattleship); + this.Controls.Add(this.GroupBoxConfig); + this.Name = "FormBattleshipConfig"; + 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(); + ((System.ComponentModel.ISupportInitialize)(this.PictureBoxBattleship)).EndInit(); + this.PanelBattleship.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox GroupBoxConfig; + private Label LabelGunBattleship; + private Label LabelBasicBattleship; + private GroupBox GroupBoxColors; + private Panel PanelSilver; + private Panel PanelRed; + private Panel PanelBlue; + private Panel PanelCyan; + private Panel PanelLime; + private Panel PanelFuchsia; + private Panel PanelYellow; + private Panel PanelOrange; + private CheckBox CheckBoxCompartmentRocket; + private CheckBox CheckBoxGunTower; + private CheckBox CheckBoxSternFence; + private NumericUpDown NumericUpDownWeight; + private NumericUpDown NumericUpDownSpeed; + private Label LabelWeight; + private Label LabelSpeed; + private PictureBox PictureBoxBattleship; + private Panel PanelBattleship; + private Label LabelModifColor; + private Label LabelBodyColor; + private Button ButtomAdd; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/Battleship/Battleship/FormBattleshipConfig.cs b/Battleship/Battleship/FormBattleshipConfig.cs new file mode 100644 index 0000000..6c7d305 --- /dev/null +++ b/Battleship/Battleship/FormBattleshipConfig.cs @@ -0,0 +1,146 @@ +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 Battleship +{ + public partial class FormBattleshipConfig : Form + { + DrawningBattleship _battleship = null; + private event Action EventAddBattleship; + public FormBattleshipConfig() + { + InitializeComponent(); + PanelBlue.MouseDown += PanelColor_MouseDown; + PanelCyan.MouseDown += PanelColor_MouseDown; + PanelFuchsia.MouseDown += PanelColor_MouseDown; + PanelLime.MouseDown += PanelColor_MouseDown; + PanelOrange.MouseDown += PanelColor_MouseDown; + PanelRed.MouseDown += PanelColor_MouseDown; + PanelSilver.MouseDown += PanelColor_MouseDown; + PanelYellow.MouseDown += PanelColor_MouseDown; + ButtonCancel.Click += (sender, e) => Close(); + } + + private void DrawBattleship() + { + Bitmap bmp = new(PictureBoxBattleship.Width, PictureBoxBattleship.Height); + Graphics gr = Graphics.FromImage(bmp); + _battleship?.SetPosition(5, 5, PictureBoxBattleship.Width, PictureBoxBattleship.Height); + _battleship?.DrawTransport(gr); + PictureBoxBattleship.Image = bmp; + } + + public void AddEvent(Action ev) + { + if (EventAddBattleship == null) + { + EventAddBattleship = ev; + } + else + { + EventAddBattleship += ev; + } + } + + private void LabelBattleship_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void PanelBattleship_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.Text)) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void PanelBattleship_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data.GetData(DataFormats.Text).ToString()) + { + case "LabelBasicBattleship": + _battleship = new DrawningBattleship((int)NumericUpDownSpeed.Value, (int)NumericUpDownWeight.Value, Color.White); + break; + case "LabelGunBattleship": + _battleship = new DrawningGunBattleship((int)NumericUpDownSpeed.Value, (int)NumericUpDownWeight.Value, Color.White, Color.Black, CheckBoxSternFence.Checked, CheckBoxGunTower.Checked, CheckBoxCompartmentRocket.Checked); + break; + } + DrawBattleship(); + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void LabelBodyColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void LabelModifColor_DragEnter(object sender, DragEventArgs e) + { + if (_battleship is DrawningGunBattleship) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } + + private void LabelBodyColor_DragDrop(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void LabelModifColor_DragDrop(object sender, DragEventArgs e) + { + var color = e.Data.GetData(typeof(Color)); + if (color != null) + { + (sender as Label).BackColor = (Color)color; + } + if (_battleship != null) + { + _battleship.Battleship.BodyColor = (Color)color; + DrawBattleship(); + } + } + + private void ButtomAdd_Click(object sender, EventArgs e) + { + EventAddBattleship?.Invoke(_battleship); + Close(); + } + } +} diff --git a/Battleship/Battleship/FormBattleshipConfig.resx b/Battleship/Battleship/FormBattleshipConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Battleship/Battleship/FormBattleshipConfig.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