diff --git a/Catamaran/Catamaran.csproj b/Catamaran/Catamaran.csproj
index 67092f0..4f33ddc 100644
--- a/Catamaran/Catamaran.csproj
+++ b/Catamaran/Catamaran.csproj
@@ -59,22 +59,24 @@
FormBoat.cs
-
+
Form
-
- FormMap.cs
+
+ FormMapWithSetBoats.cs
+
+
FormBoat.cs
-
- FormMap.cs
+
+ FormMapWithSetBoats.cs
ResXFileCodeGenerator
diff --git a/Catamaran/Direction.cs b/Catamaran/Direction.cs
index 93cb90b..f9222e2 100644
--- a/Catamaran/Direction.cs
+++ b/Catamaran/Direction.cs
@@ -9,7 +9,7 @@ namespace Catamaran
///
/// Направление перемещения
///
- internal enum Direction
+ public enum Direction
{
None = 0,
Up = 1,
diff --git a/Catamaran/DrawingBoat.cs b/Catamaran/DrawingBoat.cs
index 8b31e8e..bf31551 100644
--- a/Catamaran/DrawingBoat.cs
+++ b/Catamaran/DrawingBoat.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Catamaran
{
- internal class DrawingBoat
+ public class DrawingBoat
{
///
/// Класс-сущность
diff --git a/Catamaran/EntityBoat.cs b/Catamaran/EntityBoat.cs
index 499bbbe..3cb1c41 100644
--- a/Catamaran/EntityBoat.cs
+++ b/Catamaran/EntityBoat.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Catamaran
{
- internal class EntityBoat
+ public class EntityBoat
{
///
/// Скорость
diff --git a/Catamaran/FormBoat.Designer.cs b/Catamaran/FormBoat.Designer.cs
index 42a6fb2..328c5a3 100644
--- a/Catamaran/FormBoat.Designer.cs
+++ b/Catamaran/FormBoat.Designer.cs
@@ -38,6 +38,8 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
+ this.buttonSelectBoat = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit();
this.SuspendLayout();
@@ -142,12 +144,36 @@
this.buttonCreate.Text = "Cteate";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
+ //
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Location = new System.Drawing.Point(90, 380);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(108, 30);
+ this.buttonCreateModif.TabIndex = 7;
+ this.buttonCreateModif.Text = "CreateModif";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
+
+ //
+ // buttonSelectBoat
+ //
+ this.buttonSelectBoat.Location = new System.Drawing.Point(204, 384);
+ this.buttonSelectBoat.Name = "buttonSelectBoat";
+ this.buttonSelectBoat.Size = new System.Drawing.Size(113, 26);
+ this.buttonSelectBoat.TabIndex = 8;
+ this.buttonSelectBoat.Text = "SelectBoat";
+ this.buttonSelectBoat.UseVisualStyleBackColor = true;
+ this.buttonSelectBoat.Click += new System.EventHandler(this.buttonSelectBoat_Click);
+
//
// CatamaranForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(796, 461);
+ this.Controls.Add(this.buttonSelectBoat);
+ this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
@@ -177,6 +203,8 @@
private System.Windows.Forms.Button buttonLeft;
private System.Windows.Forms.Button buttonRight;
private System.Windows.Forms.Button buttonCreate;
+ private System.Windows.Forms.Button buttonCreateModif;
+ private System.Windows.Forms.Button buttonSelectBoat;
}
}
diff --git a/Catamaran/FormBoat.cs b/Catamaran/FormBoat.cs
index 16c0872..24dfd68 100644
--- a/Catamaran/FormBoat.cs
+++ b/Catamaran/FormBoat.cs
@@ -13,6 +13,8 @@ namespace Catamaran
public partial class FormBoat : Form
{
private DrawingBoat _catamaran;
+ public DrawingBoat SelectedBoat { get; private set; }
+
public FormBoat()
{
InitializeComponent();
@@ -24,17 +26,26 @@ namespace Catamaran
_catamaran?.DrawTransport(gr);
pictureBoxCatamaran.Image = bmp;
}
-
- private void buttonCreate_Click(object sender, EventArgs e)
+ private void SetData()
{
Random rnd = new Random();
- _catamaran = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_catamaran.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_catamaran.Catamaran.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_catamaran.Catamaran.Weight}";
- toolStripStatusLabelColor.Text = $"Цвет:{ _catamaran.Catamaran.BodyColor.Name}";
+ toolStripStatusLabelColor.Text = $"Цвет: { _catamaran.Catamaran.BodyColor.Name}";
+ }
+ private void buttonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new Random();
+ Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialog = new ColorDialog();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ _catamaran = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
+ SetData();
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
@@ -64,5 +75,37 @@ namespace Catamaran
_catamaran?.ChangeBorders(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
Draw();
}
+ private void buttonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new Random();
+ Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialog = new ColorDialog();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
+ rnd.Next(0, 256));
+ ColorDialog dialogDop = new ColorDialog();
+ if (dialogDop.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dialogDop.Color;
+ }
+ _catamaran = new DrawingCatamaran(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ color, dopColor,
+ Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
+ SetData();
+ Draw();
+ }
+ ///
+ /// Обработка нажатия кнопки "Выбрать"
+ ///
+ ///
+ ///
+ private void buttonSelectBoat_Click(object sender, EventArgs e)
+ {
+ SelectedBoat = _catamaran;
+ DialogResult = DialogResult.OK;
+ }
}
}
diff --git a/Catamaran/FormMap.cs b/Catamaran/FormMap.cs
deleted file mode 100644
index 57c3e70..0000000
--- a/Catamaran/FormMap.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-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 Catamaran
-{
- public partial class FormMap : Form
- {
- private AbstractMap _abstractMap;
-
- public FormMap()
- {
- InitializeComponent();
- _abstractMap = new SimpleMap();
-
- }
- ///
- /// Заполнение информации по объекту
- ///
- ///
- private void SetData(DrawingBoat catamaran)
- {
- toolStripStatusLabelSpeed.Text = $"Скорость: {catamaran.Catamaran.Speed}";
- toolStripStatusLabelWeight.Text = $"Вес: {catamaran.Catamaran.Weight}";
- toolStripStatusLabelColor.Text = $"Цвет: { catamaran.Catamaran.BodyColor.Name}";
- pictureBoxCatamaran.Image = _abstractMap.CreateMap(pictureBoxCatamaran.Width,pictureBoxCatamaran.Height,new DrawingObjectBoat(catamaran));
- }
-
- private void buttonCreate_Click(object sender, EventArgs e)
- {
- Random rnd = new Random();
- var _catamaran = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- //_catamaran.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
- //pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
- SetData(_catamaran);
- }
- private void buttonMove_Click(object sender, EventArgs e)
- {
- //получаем имя кнопки
- string name = ((Button)sender)?.Name ?? string.Empty;
- Direction dir = Direction.None;
-
- switch (name)
- {
- case "buttonUp":
- dir = Direction.Up;
- break;
- case "buttonDown":
- dir = Direction.Down;
- break;
- case "buttonLeft":
- dir = Direction.Left;
- break;
- case "buttonRight":
- dir = Direction.Right;
- break;
-
- }
- pictureBoxCatamaran.Image = _abstractMap?.MoveObject(dir);
- }
-
- private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
- {
- switch (comboBoxSelectorMap.Text)
- {
- case "SimpleMap":
- _abstractMap = new SimpleMap();
- break;
- case "SecondMap":
- _abstractMap = new SecondMap();
- break;
- }
-
- }
-
- private void buttonCreateModif_Click(object sender, EventArgs e)
- {
- Random rnd = new Random();
- var catamaran = new DrawingCatamaran(rnd.Next(100, 300), rnd.Next(1000,
- 2000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0,
- 256)),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0,
- 256)),
- Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,
- 2)));
- SetData(catamaran);
- }
- }
-}
diff --git a/Catamaran/FormMap.Designer.cs b/Catamaran/FormMapWithSetBoats.Designer.cs
similarity index 50%
rename from Catamaran/FormMap.Designer.cs
rename to Catamaran/FormMapWithSetBoats.Designer.cs
index d8212bb..4cba060 100644
--- a/Catamaran/FormMap.Designer.cs
+++ b/Catamaran/FormMapWithSetBoats.Designer.cs
@@ -1,6 +1,6 @@
namespace Catamaran
{
- partial class FormMap
+ partial class FormMapWithSetBoats
{
///
/// Required designer variable.
@@ -28,93 +28,108 @@
///
private void InitializeComponent()
{
- this.statusStrip1 = new System.Windows.Forms.StatusStrip();
- this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
- this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
- this.toolStripStatusLabelColor = new System.Windows.Forms.ToolStripStatusLabel();
- this.pictureBoxCatamaran = new System.Windows.Forms.PictureBox();
- this.buttonUp = new System.Windows.Forms.Button();
- this.buttonDown = new System.Windows.Forms.Button();
+ this.groupBoxTools = new System.Windows.Forms.GroupBox();
+ this.buttonShowOnMap = new System.Windows.Forms.Button();
+ this.buttonShowStorage = new System.Windows.Forms.Button();
+ this.buttonRemoveBoat = new System.Windows.Forms.Button();
+ this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
+ this.buttonAddBoat = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
- this.buttonCreate = new System.Windows.Forms.Button();
- this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
- this.buttonCreateModif = new System.Windows.Forms.Button();
- this.statusStrip1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
- // statusStrip1
+ // groupBoxTools
//
- this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
- this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.toolStripStatusLabelSpeed,
- this.toolStripStatusLabelWeight,
- this.toolStripStatusLabelColor});
- this.statusStrip1.Location = new System.Drawing.Point(0, 436);
- this.statusStrip1.Name = "statusStrip1";
- this.statusStrip1.Size = new System.Drawing.Size(826, 32);
- this.statusStrip1.TabIndex = 0;
- this.statusStrip1.Text = "statusStrip1";
+ this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
+ this.groupBoxTools.Controls.Add(this.buttonShowStorage);
+ this.groupBoxTools.Controls.Add(this.buttonRemoveBoat);
+ this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
+ this.groupBoxTools.Controls.Add(this.buttonAddBoat);
+ this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBoxTools.Controls.Add(this.buttonLeft);
+ this.groupBoxTools.Controls.Add(this.buttonRight);
+ this.groupBoxTools.Controls.Add(this.buttonUp);
+ this.groupBoxTools.Controls.Add(this.buttonDown);
+ this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
+ this.groupBoxTools.Location = new System.Drawing.Point(653, 0);
+ this.groupBoxTools.Name = "groupBoxTools";
+ this.groupBoxTools.Size = new System.Drawing.Size(303, 557);
+ this.groupBoxTools.TabIndex = 0;
+ this.groupBoxTools.TabStop = false;
+ this.groupBoxTools.Text = "Tools";
//
- // toolStripStatusLabelSpeed
+ // buttonShowOnMap
//
- this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
- this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 25);
- this.toolStripStatusLabelSpeed.Text = "Speed";
+ this.buttonShowOnMap.Location = new System.Drawing.Point(24, 402);
+ this.buttonShowOnMap.Name = "buttonShowOnMap";
+ this.buttonShowOnMap.Size = new System.Drawing.Size(191, 31);
+ this.buttonShowOnMap.TabIndex = 5;
+ this.buttonShowOnMap.Text = "ShowOnMap";
+ this.buttonShowOnMap.UseVisualStyleBackColor = true;
+ this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
//
- // toolStripStatusLabelWeight
+ // buttonShowStorage
//
- this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
- this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(68, 25);
- this.toolStripStatusLabelWeight.Text = "Weight";
+ this.buttonShowStorage.Location = new System.Drawing.Point(24, 344);
+ this.buttonShowStorage.Name = "buttonShowStorage";
+ this.buttonShowStorage.Size = new System.Drawing.Size(191, 33);
+ this.buttonShowStorage.TabIndex = 4;
+ this.buttonShowStorage.Text = "ShowStorage";
+ this.buttonShowStorage.UseVisualStyleBackColor = true;
+ this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
//
- // toolStripStatusLabelColor
+ // buttonRemoveBoat
//
- this.toolStripStatusLabelColor.Name = "toolStripStatusLabelColor";
- this.toolStripStatusLabelColor.Size = new System.Drawing.Size(55, 25);
- this.toolStripStatusLabelColor.Text = "Color";
+ this.buttonRemoveBoat.Location = new System.Drawing.Point(24, 271);
+ this.buttonRemoveBoat.Name = "buttonRemoveBoat";
+ this.buttonRemoveBoat.Size = new System.Drawing.Size(191, 30);
+ this.buttonRemoveBoat.TabIndex = 3;
+ this.buttonRemoveBoat.Text = "RemoveBoat";
+ this.buttonRemoveBoat.UseVisualStyleBackColor = true;
+ this.buttonRemoveBoat.Click += new System.EventHandler(this.buttonRemoveBoat_Click);
//
- // pictureBoxCatamaran
+ // maskedTextBoxPosition
//
- this.pictureBoxCatamaran.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBoxCatamaran.Location = new System.Drawing.Point(0, 0);
- this.pictureBoxCatamaran.Name = "pictureBoxCatamaran";
- this.pictureBoxCatamaran.Size = new System.Drawing.Size(826, 436);
- this.pictureBoxCatamaran.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
- this.pictureBoxCatamaran.TabIndex = 1;
- this.pictureBoxCatamaran.TabStop = false;
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(24, 201);
+ this.maskedTextBoxPosition.Mask = "00";
+ this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(191, 26);
+ this.maskedTextBoxPosition.TabIndex = 2;
//
- // buttonUp
+ // buttonAddBoat
//
- this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonUp.BackgroundImage = global::Catamaran.Properties.Resources.Up;
- this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonUp.Location = new System.Drawing.Point(683, 344);
- this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(30, 30);
- this.buttonUp.TabIndex = 2;
- this.buttonUp.UseVisualStyleBackColor = true;
- this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
+ this.buttonAddBoat.Location = new System.Drawing.Point(24, 123);
+ this.buttonAddBoat.Name = "buttonAddBoat";
+ this.buttonAddBoat.Size = new System.Drawing.Size(191, 32);
+ this.buttonAddBoat.TabIndex = 1;
+ this.buttonAddBoat.Text = "AddBoat";
+ this.buttonAddBoat.UseVisualStyleBackColor = true;
+ this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click_1);
//
- // buttonDown
+ // comboBoxSelectorMap
//
- this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonDown.BackgroundImage = global::Catamaran.Properties.Resources.Down;
- this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonDown.Location = new System.Drawing.Point(683, 380);
- this.buttonDown.Name = "buttonDown";
- this.buttonDown.Size = new System.Drawing.Size(30, 30);
- this.buttonDown.TabIndex = 3;
- this.buttonDown.UseVisualStyleBackColor = true;
- this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "SimpleMap",
+ "SecondMap"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(24, 51);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(191, 28);
+ this.comboBoxSelectorMap.TabIndex = 0;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Catamaran.Properties.Resources.Left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonLeft.Location = new System.Drawing.Point(647, 372);
+ this.buttonLeft.Location = new System.Drawing.Point(10, 472);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4;
@@ -126,84 +141,75 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Catamaran.Properties.Resources.Right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonRight.Location = new System.Drawing.Point(719, 372);
+ this.buttonRight.Location = new System.Drawing.Point(70, 472);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
//
- // buttonCreate
+ // buttonUp
//
- this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreate.Location = new System.Drawing.Point(14, 380);
- this.buttonCreate.Name = "buttonCreate";
- this.buttonCreate.Size = new System.Drawing.Size(70, 30);
- this.buttonCreate.TabIndex = 6;
- this.buttonCreate.Text = "Cteate";
- this.buttonCreate.UseVisualStyleBackColor = true;
- this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::Catamaran.Properties.Resources.Up;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
+ this.buttonUp.Location = new System.Drawing.Point(40, 450);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 2;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
//
- // comboBoxSelectorMap
+ // buttonDown
//
- this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBoxSelectorMap.FormattingEnabled = true;
- this.comboBoxSelectorMap.Items.AddRange(new object[] {
- "SimpleMap",
- "SecondMap"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
- this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 28);
- this.comboBoxSelectorMap.TabIndex = 7;
- this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged);
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::Catamaran.Properties.Resources.Down;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
+ this.buttonDown.Location = new System.Drawing.Point(40, 480);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 3;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
//
- // buttonCreateModif
+ // pictureBox
//
- this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreateModif.Location = new System.Drawing.Point(117, 380);
- this.buttonCreateModif.Name = "buttonCreateModif";
- this.buttonCreateModif.Size = new System.Drawing.Size(102, 30);
- this.buttonCreateModif.TabIndex = 8;
- this.buttonCreateModif.Text = "Modification";
- this.buttonCreateModif.UseVisualStyleBackColor = true;
- this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
+ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBox.Location = new System.Drawing.Point(0, 0);
+ this.pictureBox.Name = "pictureBox";
+ this.pictureBox.Size = new System.Drawing.Size(653, 557);
+ this.pictureBox.TabIndex = 1;
+ this.pictureBox.TabStop = false;
//
- // FormMap
+ // FormMapWithSetBoats
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(826, 468);
- this.Controls.Add(this.buttonCreateModif);
- this.Controls.Add(this.comboBoxSelectorMap);
- this.Controls.Add(this.buttonCreate);
- this.Controls.Add(this.buttonRight);
- this.Controls.Add(this.buttonLeft);
- this.Controls.Add(this.buttonDown);
- this.Controls.Add(this.buttonUp);
- this.Controls.Add(this.pictureBoxCatamaran);
- this.Controls.Add(this.statusStrip1);
- this.Name = "FormMap";
- this.Text = "Map";
- this.statusStrip1.ResumeLayout(false);
- this.statusStrip1.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).EndInit();
+ this.ClientSize = new System.Drawing.Size(956, 557);
+ this.Controls.Add(this.pictureBox);
+ this.Controls.Add(this.groupBoxTools);
+ this.Name = "FormMapWithSetBoats";
+ this.Text = "FormMapWithSetBoats";
+ this.groupBoxTools.ResumeLayout(false);
+ this.groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
- this.PerformLayout();
}
#endregion
- private System.Windows.Forms.StatusStrip statusStrip1;
- private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpeed;
- private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelWeight;
- private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelColor;
- private System.Windows.Forms.PictureBox pictureBoxCatamaran;
+
+ private System.Windows.Forms.GroupBox groupBoxTools;
+ private System.Windows.Forms.ComboBox comboBoxSelectorMap;
+ private System.Windows.Forms.PictureBox pictureBox;
+ private System.Windows.Forms.Button buttonShowOnMap;
+ private System.Windows.Forms.Button buttonShowStorage;
+ private System.Windows.Forms.Button buttonRemoveBoat;
+ private System.Windows.Forms.MaskedTextBox maskedTextBoxPosition;
+ private System.Windows.Forms.Button buttonAddBoat;
private System.Windows.Forms.Button buttonUp;
private System.Windows.Forms.Button buttonDown;
private System.Windows.Forms.Button buttonLeft;
private System.Windows.Forms.Button buttonRight;
- private System.Windows.Forms.Button buttonCreate;
- private System.Windows.Forms.ComboBox comboBoxSelectorMap;
- private System.Windows.Forms.Button buttonCreateModif;
}
}
\ No newline at end of file
diff --git a/Catamaran/FormMapWithSetBoats.cs b/Catamaran/FormMapWithSetBoats.cs
new file mode 100644
index 0000000..6accea3
--- /dev/null
+++ b/Catamaran/FormMapWithSetBoats.cs
@@ -0,0 +1,165 @@
+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 Catamaran
+{
+ public partial class FormMapWithSetBoats : Form
+ {
+ private MapWithSetBoatsGeneric _mapBoatsCollectionGeneric;
+
+
+ public FormMapWithSetBoats()
+ {
+ InitializeComponent();
+
+ }
+
+ ///
+ /// Выбор карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ AbstractMap map = null;
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "SimpleMap":
+ map = new SimpleMap();
+ break;
+ case "SecondMap":
+ map = new SecondMap();
+ break;
+ }
+ if (map != null)
+ {
+ _mapBoatsCollectionGeneric = new MapWithSetBoatsGeneric(pictureBox.Width, pictureBox.Height, map);
+ }
+ else
+ {
+ _mapBoatsCollectionGeneric = null;
+ }
+ }
+
+ ///
+ /// Добавление объекта
+ ///
+ ///
+ ///
+
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void buttonRemoveBoat_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
+ {
+ return;
+ }
+ if (MessageBox.Show("Удалить объект?", "Удаление",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_mapBoatsCollectionGeneric - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Вывод набора
+ ///
+ ///
+ ///
+ private void buttonShowStorage_Click(object sender, EventArgs e)
+ {
+ if (_mapBoatsCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
+ }
+ ///
+ /// Вывод карты
+ ///
+ ///
+ ///
+ private void buttonShowOnMap_Click(object sender, EventArgs e)
+ {
+ if (_mapBoatsCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapBoatsCollectionGeneric.ShowOnMap();
+ }
+
+ ///
+ /// Перемещение
+ ///
+ ///
+ ///
+ private void buttonMove_Click(object sender, EventArgs e)
+ {
+ if (_mapBoatsCollectionGeneric == null)
+ {
+ return;
+ }
+ //получаем имя кнопки
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ Direction dir = Direction.None;
+ switch (name)
+ {
+ case "buttonUp":
+ dir = Direction.Up;
+ break;
+ case "buttonDown":
+ dir = Direction.Down;
+ break;
+ case "buttonLeft":
+ dir = Direction.Left;
+ break;
+ case "buttonRight":
+ dir = Direction.Right;
+ break;
+ }
+ pictureBox.Image = _mapBoatsCollectionGeneric.MoveObject(dir);
+ }
+
+ private void buttonAddBoat_Click_1(object sender, EventArgs e)
+ {
+ if (_mapBoatsCollectionGeneric == null)
+ {
+ return;
+ }
+ FormBoat form = new FormBoat();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ DrawingObjectBoat boat = new DrawingObjectBoat(form.SelectedBoat);
+ if (_mapBoatsCollectionGeneric + boat != null)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ }
+}
diff --git a/Catamaran/FormMap.resx b/Catamaran/FormMapWithSetBoats.resx
similarity index 100%
rename from Catamaran/FormMap.resx
rename to Catamaran/FormMapWithSetBoats.resx
diff --git a/Catamaran/MapWithSetBoatsGeneric.cs b/Catamaran/MapWithSetBoatsGeneric.cs
new file mode 100644
index 0000000..6c97f4c
--- /dev/null
+++ b/Catamaran/MapWithSetBoatsGeneric.cs
@@ -0,0 +1,193 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Catamaran
+{
+ ///
+ /// Карта с набром объектов под нее
+ ///
+ ///
+ ///
+ internal class MapWithSetBoatsGeneric
+ where T : class, IDrawingObject
+ where U : AbstractMap
+ {
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 210;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 90;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetBoatsGeneric _setBoats;
+ ///
+ /// Карта
+ ///
+ private readonly U _map;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public MapWithSetBoatsGeneric(int picWidth, int picHeight, U map)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _setBoats = new SetBoatsGeneric(width * height);
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _map = map;
+ }
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
+ ///
+
+ public static int operator +(MapWithSetBoatsGeneric map, T Boat)
+ {
+ return map._setBoats.Insert(Boat);
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static T operator -(MapWithSetBoatsGeneric map, int position)
+ {
+ return map._setBoats.Remove(position);
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowSet()
+ {
+ Bitmap bmp = new Bitmap(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawBoats(gr);
+ return bmp;
+ }
+ ///
+ /// Просмотр объекта на карте
+ ///
+ ///
+ public Bitmap ShowOnMap()
+ {
+ Shaking();
+ for (int i = 0; i < _setBoats.Count; i++)
+ {
+ var Boat = _setBoats.Get(i);
+ if (Boat != null)
+ {
+ return _map.CreateMap(_pictureWidth, _pictureHeight, Boat);
+ }
+ }
+ return new Bitmap(_pictureWidth, _pictureHeight);
+ }
+ ///
+ /// Перемещение объекта по крате
+ ///
+ ///
+ ///
+ public Bitmap MoveObject(Direction direction)
+ {
+ if (_map != null)
+ {
+ return _map.MoveObject(direction);
+ }
+ return new Bitmap(_pictureWidth, _pictureHeight);
+ }
+ ///
+ /// "Взбалтываем" набор, чтобы все элементы оказались в начале
+ ///
+ private void Shaking()
+ {
+ int j = _setBoats.Count - 1;
+ for (int i = 0; i < _setBoats.Count; i++)
+ {
+ if (_setBoats.Get(i) == null)
+ {
+ for (; j > i; j--)
+ {
+ var Boat = _setBoats.Get(j);
+ if (Boat != null)
+ {
+ _setBoats.Insert(Boat, i);
+ _setBoats.Remove(j);
+ break;
+ }
+ }
+ if (j <= i)
+ {
+ return;
+ }
+ }
+ }
+ }
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new Pen(Color.Black, 3);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
+ {//линия рамзетки места
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i *
+ _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
+ for (int k = 0; k < 7; k++)
+ {
+ g.DrawEllipse(pen, i * _placeSizeWidth + 15 * k, j * _placeSizeHeight, 15, 15);
+ g.DrawEllipse(pen, i * _placeSizeWidth + 15 * k, j * _placeSizeHeight - 15, 15, 15);
+ }
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
+ for (int k = 0; k < 6 * 4; k++)
+ {
+ g.DrawEllipse(pen, i * _placeSizeWidth, 0 + 15 * k, 15, 15);
+ }
+ }
+ }
+ ///
+ /// Метод прорисовки объектов
+ ///
+ ///
+ private void DrawBoats(System.Drawing.Graphics g)
+ {
+ int numberOfSeatsInWidth = _pictureWidth / _placeSizeWidth;
+ int numberOfSeatsInHeight = _pictureHeight / _placeSizeHeight;
+ int bottomLine = (numberOfSeatsInHeight - 1) * _placeSizeHeight;
+ for (int i = 0; i < _setBoats.Count; i++)
+ {
+ // TODO установка позиции
+ _setBoats.Get(i)?.SetObject(i % numberOfSeatsInWidth * _placeSizeWidth, bottomLine - i / numberOfSeatsInWidth * _placeSizeHeight, _pictureWidth, _pictureHeight);
+ _setBoats.Get(i)?.DrawingObject(g);
+ }
+ }
+ }
+}
+
diff --git a/Catamaran/Program.cs b/Catamaran/Program.cs
index 9b40c48..fb95aab 100644
--- a/Catamaran/Program.cs
+++ b/Catamaran/Program.cs
@@ -16,7 +16,7 @@ namespace Catamaran
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new FormMap());
+ Application.Run(new FormMapWithSetBoats());
}
}
}
diff --git a/Catamaran/SetBoatsGeneric.cs b/Catamaran/SetBoatsGeneric.cs
new file mode 100644
index 0000000..4c74923
--- /dev/null
+++ b/Catamaran/SetBoatsGeneric.cs
@@ -0,0 +1,113 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Catamaran
+{
+ ///
+ /// Параметризованный набор объектов
+ ///
+ ///
+ internal class SetBoatsGeneric
+ where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private readonly T[] _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Length;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetBoatsGeneric(int count)
+ {
+ _places = new T[count];
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ /// Добавляемая лодка
+ ///
+ public int Insert(T boat)
+ {
+ for (int i = 0; i < Count; i++)
+ {
+ if (_places[i] == null)
+ {
+ _places[i] = boat;
+ return i;
+ }
+ }
+ return -1;
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемая лодка
+ /// Позиция
+ ///
+ public int Insert(T boat, int position)
+ {
+ // TODO проверка позиции
+ if (position < 0 || position >= Count) return -1;
+ // TODO проверка, что элемент массива по этой позиции пустой,если нет, то
+ // проверка, что после вставляемого элемента в массиве есть пустой элемент
+ // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
+ if (_places[position] == null)
+ {
+ _places[position] = boat;
+ return position;
+ }
+ else
+ {
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (_places[i] == null)
+ {
+ for (int j = i - 1; j >= position; j--)
+ {
+ _places[j + 1] = _places[j];
+ }
+ _places[position] = boat;
+ return position;
+ }
+ }
+ return -1;
+ }
+ // TODO вставка по позиции
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public T Remove(int position)
+ {
+ // TODO проверка позиции
+ if (position < 0 || position >= Count) return null;
+ // TODO удаление объекта из массива, присовив элементу массива значение null
+ T removed = _places[position];
+ _places[position] = null;
+ return removed;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T Get(int position)
+ {
+ // TODO проверка позиции
+ if (position < 0 || position >= Count) return null;
+ return _places[position];
+ }
+
+ }
+}
+