diff --git a/Boats/Boats/Direction.cs b/Boats/Boats/Direction.cs index 0c4d00a..30b42ae 100644 --- a/Boats/Boats/Direction.cs +++ b/Boats/Boats/Direction.cs @@ -9,7 +9,7 @@ namespace Boats /// /// Направление перемещения /// - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/Boats/Boats/DrawingBoat.cs b/Boats/Boats/DrawingBoat.cs index e9b3975..a8cd315 100644 --- a/Boats/Boats/DrawingBoat.cs +++ b/Boats/Boats/DrawingBoat.cs @@ -9,7 +9,7 @@ namespace Boats /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// - internal class DrawingBoat + public class DrawingBoat { /// /// Класс-сущность diff --git a/Boats/Boats/EntityBoat.cs b/Boats/Boats/EntityBoat.cs index 0d4ce07..b5e96c6 100644 --- a/Boats/Boats/EntityBoat.cs +++ b/Boats/Boats/EntityBoat.cs @@ -9,7 +9,7 @@ namespace Boats /// /// Класс-сущность "Лодка" /// - internal class EntityBoat + public class EntityBoat { /// /// Скорость diff --git a/Boats/Boats/FormBoat.Designer.cs b/Boats/Boats/FormBoat.Designer.cs index e7e7ab0..f46a3e2 100644 --- a/Boats/Boats/FormBoat.Designer.cs +++ b/Boats/Boats/FormBoat.Designer.cs @@ -39,6 +39,7 @@ this.ButtonRight = new System.Windows.Forms.Button(); this.ButtonDown = new System.Windows.Forms.Button(); this.ButtonCreateModificate = new System.Windows.Forms.Button(); + this.ButtonSelectBoat = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -155,11 +156,23 @@ this.ButtonCreateModificate.UseVisualStyleBackColor = true; this.ButtonCreateModificate.Click += new System.EventHandler(this.ButtonCreateModificate_Click); // + // ButtonSelectBoat + // + this.ButtonSelectBoat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ButtonSelectBoat.Location = new System.Drawing.Point(491, 381); + this.ButtonSelectBoat.Name = "ButtonSelectBoat"; + this.ButtonSelectBoat.Size = new System.Drawing.Size(117, 29); + this.ButtonSelectBoat.TabIndex = 8; + this.ButtonSelectBoat.Text = "Выбрать"; + this.ButtonSelectBoat.UseVisualStyleBackColor = true; + this.ButtonSelectBoat.Click += new System.EventHandler(this.ButtonSelectBoat_Click); + // // FormBoat // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ButtonSelectBoat); this.Controls.Add(this.ButtonCreateModificate); this.Controls.Add(this.ButtonDown); this.Controls.Add(this.ButtonRight); @@ -191,5 +204,6 @@ private Button ButtonRight; private Button ButtonDown; private Button ButtonCreateModificate; + private Button ButtonSelectBoat; } } \ No newline at end of file diff --git a/Boats/Boats/FormBoat.cs b/Boats/Boats/FormBoat.cs index 2599211..3456eee 100644 --- a/Boats/Boats/FormBoat.cs +++ b/Boats/Boats/FormBoat.cs @@ -12,7 +12,8 @@ namespace Boats { public partial class FormBoat : Form { - private DrawingBoat _boat; + DrawingBoat _boat; + public DrawingBoat SelectedBoat { get; private set; } public FormBoat() { InitializeComponent(); @@ -44,18 +45,21 @@ namespace Boats pictureBoxBoat.Image = bmp; } /// - /// Обработка нажатия кнопки "Создать" + /// Обработчик нажатия кнопки "Создать" /// - /// - /// private void ButtonCreate_Click(object sender, EventArgs e) { - Random rnd = new(); + Random rnd = new Random(); + Color color = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)); + ColorDialog dialog = new ColorDialog(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } _boat = new DrawingBoat( rnd.Next(100, 300), - rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), - rnd.Next(0, 256), rnd.Next(0, 256)) + rnd.Next(1000, 3000), + color ); SetData(); Draw(); @@ -67,21 +71,34 @@ namespace Boats /// private void ButtonMove_Click(object sender, EventArgs e) { - //получаем имя кнопки - string name = ((Button)sender)?.Name ?? string.Empty; - switch (name) + if (_boat == null) + return; + + string btnName = ((Button)sender).Name; + + switch (btnName) { case "ButtonUp": - _boat?.MoveTransport(Direction.Up); + { + _boat.MoveTransport(Direction.Up); + } break; case "ButtonDown": - _boat?.MoveTransport(Direction.Down); + { + _boat.MoveTransport(Direction.Down); + } break; case "ButtonLeft": - _boat?.MoveTransport(Direction.Left); + { + _boat.MoveTransport(Direction.Left); + } break; case "ButtonRight": - _boat?.MoveTransport(Direction.Right); + { + _boat.MoveTransport(Direction.Right); + } + break; + default: break; } Draw(); @@ -104,16 +121,44 @@ namespace Boats private void ButtonCreateModificate_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(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } + _boat = new DrawingCatamaran( rnd.Next(100, 300), rnd.Next(1000, 3000), - Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), - Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), + 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 = _boat; + DialogResult = DialogResult.OK; + } } } diff --git a/Boats/Boats/FormMap.cs b/Boats/Boats/FormMap.cs deleted file mode 100644 index 169273a..0000000 --- a/Boats/Boats/FormMap.cs +++ /dev/null @@ -1,126 +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 Boats -{ - public partial class FormMap : Form - { - private AbstractMap _abstractMap; - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - /// - /// Метод установки данных - /// - private void SetData(DrawingBoat boat) - { - toolStripStatusLabelSpeed.Text = $"Скорость: {boat.Boat.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {boat.Boat.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {boat.Boat.BodyColor.Name}"; - pictureBoxMap.Image = _abstractMap.CreateMap(pictureBoxMap.Width, pictureBoxMap.Height, - new DrawingObjectBoat(boat)); - } - /// - /// Обработка нажатия кнопки "Создать" - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - var boat = new DrawingBoat( - rnd.Next(100, 300), - rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), - rnd.Next(0, 256), rnd.Next(0, 256)) - ); - SetData(boat); - } - /// - /// Обработчик нажатий кнопок передвижения - /// - /// - /// - private void ButtonMove_Click(object sender, EventArgs e) - { - //получаем имя кнопки - string btnName = ((Button)sender)?.Name ?? string.Empty; - Direction dir = Direction.None; - - switch (btnName) - { - case "ButtonUp": - { - dir = Direction.Up; - } - break; - case "ButtonDown": - { - dir = Direction.Down; - } - break; - case "ButtonLeft": - { - dir = Direction.Left; - } - break; - case "ButtonRight": - { - dir = Direction.Right; - } - break; - default: - break; - } - pictureBoxMap.Image = _abstractMap?.MoveObject(dir); - } - /// - /// Обработка нажатия кнопки "Модификация" - /// - /// - /// - private void ButtonCreateModificate_Click(object sender, EventArgs e) - { - Random rnd = new Random(); - - var boat = new DrawingCatamaran( - rnd.Next(100, 300), - rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), - Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), - Convert.ToBoolean(rnd.Next(0, 2)), - Convert.ToBoolean(rnd.Next(0, 2)) - ); - SetData(boat); - } - /// - /// Смена карты - /// - /// - /// - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Океан карта": - _abstractMap = new OceanMap(); - break; - case "Линии карта": - _abstractMap = new LineMap(); - break; - } - } - } -} diff --git a/Boats/Boats/FormMap.Designer.cs b/Boats/Boats/FormMapWithSetBoats.Designer.cs similarity index 50% rename from Boats/Boats/FormMap.Designer.cs rename to Boats/Boats/FormMapWithSetBoats.Designer.cs index ae9e3ce..ab44094 100644 --- a/Boats/Boats/FormMap.Designer.cs +++ b/Boats/Boats/FormMapWithSetBoats.Designer.cs @@ -1,6 +1,6 @@ namespace Boats { - partial class FormMap + partial class FormMapWithSetBoats { /// /// Required designer variable. @@ -28,132 +28,137 @@ /// private void InitializeComponent() { - this.pictureBoxMap = new System.Windows.Forms.PictureBox(); - this.statusStrip = new System.Windows.Forms.StatusStrip(); - this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.ButtonCreate = new System.Windows.Forms.Button(); - this.ButtonUp = new System.Windows.Forms.Button(); - this.ButtonLeft = new System.Windows.Forms.Button(); - this.ButtonRight = new System.Windows.Forms.Button(); + this.groupBox = new System.Windows.Forms.GroupBox(); this.ButtonDown = new System.Windows.Forms.Button(); - this.ButtonCreateModificate = new System.Windows.Forms.Button(); + this.ButtonRight = new System.Windows.Forms.Button(); + this.ButtonLeft = new System.Windows.Forms.Button(); + this.ButtonUp = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.ButtonShowOnMap = new System.Windows.Forms.Button(); + this.ButtonShowStorage = new System.Windows.Forms.Button(); + this.ButtonRemoveBoat = new System.Windows.Forms.Button(); + this.ButtonAddBoat = new System.Windows.Forms.Button(); this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxMap)).BeginInit(); - this.statusStrip.SuspendLayout(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); // - // pictureBoxMap + // groupBox // - this.pictureBoxMap.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxMap.Location = new System.Drawing.Point(0, 0); - this.pictureBoxMap.Name = "pictureBoxMap"; - this.pictureBoxMap.Size = new System.Drawing.Size(800, 424); - this.pictureBoxMap.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxMap.TabIndex = 0; - this.pictureBoxMap.TabStop = false; - // - // statusStrip - // - this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelBodyColor}); - this.statusStrip.Location = new System.Drawing.Point(0, 424); - this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(800, 26); - this.statusStrip.TabIndex = 1; - this.statusStrip.Text = "statusStrip1"; - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20); - this.toolStripStatusLabelSpeed.Text = "Скорость:"; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20); - this.toolStripStatusLabelWeight.Text = "Вес:"; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20); - this.toolStripStatusLabelBodyColor.Text = "Цвет:"; - // - // ButtonCreate - // - this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.ButtonCreate.Location = new System.Drawing.Point(12, 381); - this.ButtonCreate.Name = "ButtonCreate"; - this.ButtonCreate.Size = new System.Drawing.Size(94, 29); - this.ButtonCreate.TabIndex = 2; - this.ButtonCreate.Text = "Создать"; - this.ButtonCreate.UseVisualStyleBackColor = true; - this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); - // - // ButtonUp - // - this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonUp.BackgroundImage = global::Boats.Properties.Resources.arrow_up; - this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.ButtonUp.Location = new System.Drawing.Point(710, 344); - this.ButtonUp.Name = "ButtonUp"; - this.ButtonUp.Size = new System.Drawing.Size(30, 30); - this.ButtonUp.TabIndex = 3; - this.ButtonUp.UseVisualStyleBackColor = true; - this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click); - // - // ButtonLeft - // - this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonLeft.BackgroundImage = global::Boats.Properties.Resources.arrow_left; - this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.ButtonLeft.Location = new System.Drawing.Point(674, 380); - this.ButtonLeft.Name = "ButtonLeft"; - this.ButtonLeft.Size = new System.Drawing.Size(30, 30); - this.ButtonLeft.TabIndex = 4; - this.ButtonLeft.UseVisualStyleBackColor = true; - this.ButtonLeft.Click += new System.EventHandler(this.ButtonMove_Click); - // - // ButtonRight - // - this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonRight.BackgroundImage = global::Boats.Properties.Resources.arrow_right; - this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.ButtonRight.Location = new System.Drawing.Point(746, 380); - 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); + this.groupBox.Controls.Add(this.ButtonDown); + this.groupBox.Controls.Add(this.ButtonRight); + this.groupBox.Controls.Add(this.ButtonLeft); + this.groupBox.Controls.Add(this.ButtonUp); + this.groupBox.Controls.Add(this.maskedTextBoxPosition); + this.groupBox.Controls.Add(this.ButtonShowOnMap); + this.groupBox.Controls.Add(this.ButtonShowStorage); + this.groupBox.Controls.Add(this.ButtonRemoveBoat); + this.groupBox.Controls.Add(this.ButtonAddBoat); + this.groupBox.Controls.Add(this.comboBoxSelectorMap); + this.groupBox.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBox.Location = new System.Drawing.Point(901, 0); + this.groupBox.Name = "groupBox"; + this.groupBox.Size = new System.Drawing.Size(250, 589); + this.groupBox.TabIndex = 0; + this.groupBox.TabStop = false; + this.groupBox.Text = "Инструменты"; // // ButtonDown // this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.ButtonDown.BackgroundImage = global::Boats.Properties.Resources.arrow_down; this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.ButtonDown.Location = new System.Drawing.Point(710, 380); + this.ButtonDown.Location = new System.Drawing.Point(99, 537); this.ButtonDown.Name = "ButtonDown"; this.ButtonDown.Size = new System.Drawing.Size(30, 30); - this.ButtonDown.TabIndex = 6; + this.ButtonDown.TabIndex = 10; this.ButtonDown.UseVisualStyleBackColor = true; this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click); // - // ButtonCreateModificate + // ButtonRight // - this.ButtonCreateModificate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.ButtonCreateModificate.Location = new System.Drawing.Point(138, 381); - this.ButtonCreateModificate.Name = "ButtonCreateModificate"; - this.ButtonCreateModificate.Size = new System.Drawing.Size(117, 29); - this.ButtonCreateModificate.TabIndex = 7; - this.ButtonCreateModificate.Text = "Модификация"; - this.ButtonCreateModificate.UseVisualStyleBackColor = true; - this.ButtonCreateModificate.Click += new System.EventHandler(this.ButtonCreateModificate_Click); + this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRight.BackgroundImage = global::Boats.Properties.Resources.arrow_right; + this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonRight.Location = new System.Drawing.Point(135, 537); + this.ButtonRight.Name = "ButtonRight"; + this.ButtonRight.Size = new System.Drawing.Size(30, 30); + this.ButtonRight.TabIndex = 9; + this.ButtonRight.UseVisualStyleBackColor = true; + this.ButtonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // ButtonLeft + // + this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonLeft.BackgroundImage = global::Boats.Properties.Resources.arrow_left; + this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonLeft.Location = new System.Drawing.Point(63, 537); + this.ButtonLeft.Name = "ButtonLeft"; + this.ButtonLeft.Size = new System.Drawing.Size(30, 30); + this.ButtonLeft.TabIndex = 8; + this.ButtonLeft.UseVisualStyleBackColor = true; + this.ButtonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // ButtonUp + // + this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonUp.BackgroundImage = global::Boats.Properties.Resources.arrow_up; + this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonUp.Location = new System.Drawing.Point(99, 501); + this.ButtonUp.Name = "ButtonUp"; + this.ButtonUp.Size = new System.Drawing.Size(30, 30); + this.ButtonUp.TabIndex = 7; + this.ButtonUp.UseVisualStyleBackColor = true; + this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 168); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(232, 27); + this.maskedTextBoxPosition.TabIndex = 5; + // + // ButtonShowOnMap + // + this.ButtonShowOnMap.Location = new System.Drawing.Point(6, 389); + this.ButtonShowOnMap.Name = "ButtonShowOnMap"; + this.ButtonShowOnMap.Size = new System.Drawing.Size(232, 40); + this.ButtonShowOnMap.TabIndex = 4; + this.ButtonShowOnMap.Text = "Просмотреть карту"; + this.ButtonShowOnMap.UseVisualStyleBackColor = true; + this.ButtonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // ButtonShowStorage + // + this.ButtonShowStorage.Location = new System.Drawing.Point(6, 303); + this.ButtonShowStorage.Name = "ButtonShowStorage"; + this.ButtonShowStorage.Size = new System.Drawing.Size(232, 40); + this.ButtonShowStorage.TabIndex = 3; + this.ButtonShowStorage.Text = "Просмотреть хранилище"; + this.ButtonShowStorage.UseVisualStyleBackColor = true; + this.ButtonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // ButtonRemoveBoat + // + this.ButtonRemoveBoat.Location = new System.Drawing.Point(6, 212); + this.ButtonRemoveBoat.Name = "ButtonRemoveBoat"; + this.ButtonRemoveBoat.Size = new System.Drawing.Size(232, 40); + this.ButtonRemoveBoat.TabIndex = 2; + this.ButtonRemoveBoat.Text = "Удалить лодку"; + this.ButtonRemoveBoat.UseVisualStyleBackColor = true; + this.ButtonRemoveBoat.Click += new System.EventHandler(this.ButtonRemoveBoat_Click); + // + // ButtonAddBoat + // + this.ButtonAddBoat.Location = new System.Drawing.Point(6, 97); + this.ButtonAddBoat.Name = "ButtonAddBoat"; + this.ButtonAddBoat.Size = new System.Drawing.Size(232, 40); + this.ButtonAddBoat.TabIndex = 1; + this.ButtonAddBoat.Text = "Добавить лодку"; + this.ButtonAddBoat.UseVisualStyleBackColor = true; + this.ButtonAddBoat.Click += new System.EventHandler(this.ButtonAddBoat_Click); // // comboBoxSelectorMap // @@ -163,49 +168,50 @@ "Простая карта", "Океан карта", "Линии карта"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 26); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28); - this.comboBoxSelectorMap.TabIndex = 8; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(238, 28); + this.comboBoxSelectorMap.TabIndex = 0; this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); // - // FormMap + // pictureBox + // + 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(901, 589); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // FormMapWithSetBoats // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.comboBoxSelectorMap); - this.Controls.Add(this.ButtonCreateModificate); - this.Controls.Add(this.ButtonDown); - this.Controls.Add(this.ButtonRight); - this.Controls.Add(this.ButtonLeft); - this.Controls.Add(this.ButtonUp); - this.Controls.Add(this.ButtonCreate); - this.Controls.Add(this.pictureBoxMap); - this.Controls.Add(this.statusStrip); - this.Name = "FormMap"; - this.Text = "Лодка"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxMap)).EndInit(); - this.statusStrip.ResumeLayout(false); - this.statusStrip.PerformLayout(); + this.ClientSize = new System.Drawing.Size(1151, 589); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.groupBox); + this.Name = "FormMapWithSetBoats"; + this.Text = "Карта с набором элементов"; + this.groupBox.ResumeLayout(false); + this.groupBox.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - private PictureBox pictureBoxMap; - private StatusStrip statusStrip; - private ToolStripStatusLabel toolStripStatusLabelSpeed; - private ToolStripStatusLabel toolStripStatusLabelWeight; - private ToolStripStatusLabel toolStripStatusLabelBodyColor; - private Button ButtonCreate; - private Button ButtonUp; - private Button ButtonLeft; - private Button ButtonRight; - private Button ButtonDown; - private Button ButtonCreateModificate; + private GroupBox groupBox; + private MaskedTextBox maskedTextBoxPosition; + private Button ButtonShowOnMap; + private Button ButtonShowStorage; + private Button ButtonRemoveBoat; + private Button ButtonAddBoat; private ComboBox comboBoxSelectorMap; + private PictureBox pictureBox; + private Button ButtonDown; + private Button ButtonRight; + private Button ButtonLeft; + private Button ButtonUp; } } \ No newline at end of file diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs new file mode 100644 index 0000000..f45b130 --- /dev/null +++ b/Boats/Boats/FormMapWithSetBoats.cs @@ -0,0 +1,173 @@ +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 Boats +{ + 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 "Простая карта": + map = new SimpleMap(); + break; + case "Линии карта": + map = new LineMap(); + break; + case "Океан карта": + map = new OceanMap(); + break; + } + if (map != null) + { + _mapBoatsCollectionGeneric = new MapWithSetBoatsGeneric( + pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapBoatsCollectionGeneric = null; + } + } + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAddBoat_Click(object sender, EventArgs e) + { + if (_mapBoatsCollectionGeneric == null) + { + return; + } + FormBoat form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + bool added = false; + if (form.SelectedBoat != null) + { + DrawingObjectBoat boat = new(form.SelectedBoat); + if (_mapBoatsCollectionGeneric + boat != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet(); + added = true; + } + } + if (!added) + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта + /// + /// + /// + 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); + pos -= 1; + 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); + } + } +} diff --git a/Boats/Boats/FormMap.resx b/Boats/Boats/FormMapWithSetBoats.resx similarity index 93% rename from Boats/Boats/FormMap.resx rename to Boats/Boats/FormMapWithSetBoats.resx index 2c0949d..f298a7b 100644 --- a/Boats/Boats/FormMap.resx +++ b/Boats/Boats/FormMapWithSetBoats.resx @@ -57,7 +57,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - \ No newline at end of file diff --git a/Boats/Boats/Program.cs b/Boats/Boats/Program.cs index 45769f2..91dda50 100644 --- a/Boats/Boats/Program.cs +++ b/Boats/Boats/Program.cs @@ -11,7 +11,7 @@ namespace Boats // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMap()); + Application.Run(new FormMapWithSetBoats()); } } } \ No newline at end of file