diff --git a/Battleship/Battleship/BattleshipDelegate.cs b/Battleship/Battleship/BattleshipDelegate.cs
new file mode 100644
index 0000000..fd52736
--- /dev/null
+++ b/Battleship/Battleship/BattleshipDelegate.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Battleship
+{
+ ///
+ /// Делегат для передачи объекта-корабля
+ ///
+ ///
+ public delegate void BattleshipDelegate(DrawningBattleship battleship);
+}
diff --git a/Battleship/Battleship/DrawningGunBattleship.cs b/Battleship/Battleship/DrawningGunBattleship.cs
index b1a4a02..86ec6a3 100644
--- a/Battleship/Battleship/DrawningGunBattleship.cs
+++ b/Battleship/Battleship/DrawningGunBattleship.cs
@@ -30,6 +30,12 @@ namespace Battleship
return;
}
+ _startPosX += 10;
+ _startPosY += 5;
+ base.DrawTransport(g);
+ _startPosX -= 10;
+ _startPosY -= 5;
+
Pen pen = new(Color.Black);
Brush dopBrush = new SolidBrush(gunBattleship.DopColor);
@@ -40,12 +46,6 @@ namespace Battleship
g.DrawRectangle(pen, _startPosX + 85, _startPosY + 10, 15, 20);
}
- _startPosX += 10;
- _startPosY += 5;
- base.DrawTransport(g);
- _startPosX -= 10;
- _startPosY -= 5;
-
if (gunBattleship.GunTower)
{
g.FillEllipse(dopBrush, _startPosX + 105, _startPosY + 12, 17, 17);
diff --git a/Battleship/Battleship/EntityBattleship.cs b/Battleship/Battleship/EntityBattleship.cs
index d44f3f7..dd661f1 100644
--- a/Battleship/Battleship/EntityBattleship.cs
+++ b/Battleship/Battleship/EntityBattleship.cs
@@ -22,7 +22,7 @@ namespace Battleship
///
/// Цвет кузова
///
- public Color BodyColor { get; set; }
+ public Color BodyColor { get; private set; }
///
/// Шаг перемещения боевого корабля
///
@@ -41,5 +41,10 @@ namespace Battleship
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor;
}
+
+ public void ChangeColor(Color color)
+ {
+ BodyColor = color;
+ }
}
}
diff --git a/Battleship/Battleship/EntityGunBattleship.cs b/Battleship/Battleship/EntityGunBattleship.cs
index e25fc13..dd7d6a7 100644
--- a/Battleship/Battleship/EntityGunBattleship.cs
+++ b/Battleship/Battleship/EntityGunBattleship.cs
@@ -45,5 +45,10 @@ namespace Battleship
GunTower = gunTower;
SternFence = sternFence;
}
+
+ public void ChangeDopColor(Color color)
+ {
+ DopColor = color;
+ }
}
}
diff --git a/Battleship/Battleship/FormBattleshipConfig.Designer.cs b/Battleship/Battleship/FormBattleshipConfig.Designer.cs
index 056484c..36e6b56 100644
--- a/Battleship/Battleship/FormBattleshipConfig.Designer.cs
+++ b/Battleship/Battleship/FormBattleshipConfig.Designer.cs
@@ -188,7 +188,7 @@
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.Size = new System.Drawing.Size(217, 19);
this.CheckBoxCompartmentRocket.TabIndex = 6;
this.CheckBoxCompartmentRocket.Text = "Признак наличия отсека для ракет";
this.CheckBoxCompartmentRocket.UseVisualStyleBackColor = true;
@@ -198,7 +198,7 @@
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.Size = new System.Drawing.Size(228, 19);
this.CheckBoxGunTower.TabIndex = 5;
this.CheckBoxGunTower.Text = "Признак наличия орудийной башни";
this.CheckBoxGunTower.UseVisualStyleBackColor = true;
@@ -208,7 +208,7 @@
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.Size = new System.Drawing.Size(218, 19);
this.CheckBoxSternFence.TabIndex = 4;
this.CheckBoxSternFence.Text = "Признак наличия забора на корме";
this.CheckBoxSternFence.UseVisualStyleBackColor = true;
@@ -220,7 +220,7 @@
this.NumericUpDownWeight.Size = new System.Drawing.Size(120, 23);
this.NumericUpDownWeight.TabIndex = 3;
this.NumericUpDownWeight.Value = new decimal(new int[] {
- 100,
+ 1,
0,
0,
0});
@@ -232,7 +232,7 @@
this.NumericUpDownSpeed.Size = new System.Drawing.Size(120, 23);
this.NumericUpDownSpeed.TabIndex = 2;
this.NumericUpDownSpeed.Value = new decimal(new int[] {
- 100,
+ 1,
0,
0,
0});
diff --git a/Battleship/Battleship/FormBattleshipConfig.cs b/Battleship/Battleship/FormBattleshipConfig.cs
index 6c7d305..db7a078 100644
--- a/Battleship/Battleship/FormBattleshipConfig.cs
+++ b/Battleship/Battleship/FormBattleshipConfig.cs
@@ -1,14 +1,4 @@
-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
+namespace Battleship
{
public partial class FormBattleshipConfig : Form
{
@@ -74,7 +64,8 @@ namespace Battleship
_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);
+ _battleship = new DrawningGunBattleship((int)NumericUpDownSpeed.Value, (int)NumericUpDownWeight.Value, Color.White, Color.Black,
+ CheckBoxCompartmentRocket.Checked, CheckBoxGunTower.Checked, CheckBoxSternFence.Checked);
break;
}
DrawBattleship();
@@ -84,7 +75,6 @@ namespace Battleship
{
(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)))
@@ -113,27 +103,25 @@ namespace Battleship
private void LabelBodyColor_DragDrop(object sender, DragEventArgs e)
{
- if (e.Data.GetDataPresent(typeof(Color)))
+ if (e.Data.GetDataPresent(typeof(Color)) && _battleship != null)
{
- e.Effect = DragDropEffects.Copy;
- }
- else
- {
- e.Effect = DragDropEffects.None;
+ _battleship.Battleship.ChangeColor((Color)e.Data.GetData(typeof(Color)));
+ DrawBattleship();
}
}
private void LabelModifColor_DragDrop(object sender, DragEventArgs e)
{
- var color = e.Data.GetData(typeof(Color));
- if (color != null)
+ if (e.Data.GetDataPresent(typeof(Color)) && _battleship != null)
{
- (sender as Label).BackColor = (Color)color;
- }
- if (_battleship != null)
- {
- _battleship.Battleship.BodyColor = (Color)color;
- DrawBattleship();
+ if (_battleship is DrawningGunBattleship _gunBattleship)
+ {
+ if (_gunBattleship.Battleship is EntityGunBattleship _entityGunBattleship)
+ {
+ _entityGunBattleship.ChangeDopColor((Color)e.Data.GetData(typeof(Color)));
+ DrawBattleship();
+ }
+ }
}
}
diff --git a/Battleship/Battleship/FormMapWithSetBattleship.Designer.cs b/Battleship/Battleship/FormMapWithSetBattleship.Designer.cs
index 7adce49..c0f871b 100644
--- a/Battleship/Battleship/FormMapWithSetBattleship.Designer.cs
+++ b/Battleship/Battleship/FormMapWithSetBattleship.Designer.cs
@@ -252,7 +252,7 @@
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetBattleship";
- this.Text = "FormMapWithSetBattleship";
+ this.Text = "Карта с набором объектов";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
diff --git a/Battleship/Battleship/FormMapWithSetBattleship.cs b/Battleship/Battleship/FormMapWithSetBattleship.cs
index 04ed588..e88efa3 100644
--- a/Battleship/Battleship/FormMapWithSetBattleship.cs
+++ b/Battleship/Battleship/FormMapWithSetBattleship.cs
@@ -50,24 +50,27 @@ namespace Battleship
}
private void ButtonAddBattleship_Click(object sender, EventArgs e)
+ {
+ var formBattleshipConfig = new FormBattleshipConfig();
+ formBattleshipConfig.AddEvent(AddBattleshipOnMap);
+ formBattleshipConfig.Show();
+ }
+
+ private void AddBattleshipOnMap(DrawningBattleship battleship)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
- FormBattleship form = new();
- if (form.ShowDialog() == DialogResult.OK)
+ DrawningObjectBattleship boat = new(battleship);
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat >= 0)
{
- DrawningObjectBattleship battleship = new(form.SelectedBattleship);
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + battleship != -1)
- {
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
}
}