From d71d100ee87ffac3f9c9f81aa4a5b3f7c1f64d40 Mon Sep 17 00:00:00 2001 From: crum61kg Date: Thu, 24 Nov 2022 01:45:19 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/Direction.cs | 2 +- WarmlyShip/WarmlyShip/DrawningShip.cs | 2 +- WarmlyShip/WarmlyShip/EntityShip.cs | 2 +- .../FormMapWithSetWarmlyShip.Designer.cs | 210 ++++++++++++++++++ .../WarmlyShip/FormMapWithSetWarmlyShip.cs | 176 +++++++++++++++ .../WarmlyShip/FormMapWithSetWarmlyShip.resx | 60 +++++ WarmlyShip/WarmlyShip/FormShip.Designer.cs | 13 ++ WarmlyShip/WarmlyShip/FormShip.cs | 29 +-- WarmlyShip/WarmlyShip/Program.cs | 2 +- 9 files changed, 474 insertions(+), 22 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.Designer.cs create mode 100644 WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs create mode 100644 WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.resx diff --git a/WarmlyShip/WarmlyShip/Direction.cs b/WarmlyShip/WarmlyShip/Direction.cs index 390e32c..1e09d9a 100644 --- a/WarmlyShip/WarmlyShip/Direction.cs +++ b/WarmlyShip/WarmlyShip/Direction.cs @@ -9,7 +9,7 @@ namespace WarmlyShip /// /// Направление перемещения /// - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/WarmlyShip/WarmlyShip/DrawningShip.cs b/WarmlyShip/WarmlyShip/DrawningShip.cs index 99b4e42..8b4cc54 100644 --- a/WarmlyShip/WarmlyShip/DrawningShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningShip.cs @@ -9,7 +9,7 @@ namespace WarmlyShip /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// - internal class DrawningShip + public class DrawningShip { /// > /// Класс-сущность diff --git a/WarmlyShip/WarmlyShip/EntityShip.cs b/WarmlyShip/WarmlyShip/EntityShip.cs index 43b9e48..5629338 100644 --- a/WarmlyShip/WarmlyShip/EntityShip.cs +++ b/WarmlyShip/WarmlyShip/EntityShip.cs @@ -10,7 +10,7 @@ namespace WarmlyShip /// Класс - сущность "Корабль" /// - internal class EntityShip + public class EntityShip { /// /// Скорость diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.Designer.cs b/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.Designer.cs new file mode 100644 index 0000000..d059d9d --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.Designer.cs @@ -0,0 +1,210 @@ +namespace WarmlyShip +{ + partial class FormMapWithSetWarmlyShip + { + /// + /// 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.groupBox1 = new System.Windows.Forms.GroupBox(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.ButtonShowStorage = new System.Windows.Forms.Button(); + this.ButtonShowOnMap = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.ButtonRemoveShip = new System.Windows.Forms.Button(); + this.ButtonAddShip = new System.Windows.Forms.Button(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.buttonDown); + this.groupBox1.Controls.Add(this.buttonUp); + this.groupBox1.Controls.Add(this.buttonRight); + this.groupBox1.Controls.Add(this.buttonLeft); + this.groupBox1.Controls.Add(this.ButtonShowStorage); + this.groupBox1.Controls.Add(this.ButtonShowOnMap); + this.groupBox1.Controls.Add(this.maskedTextBoxPosition); + this.groupBox1.Controls.Add(this.comboBoxSelectorMap); + this.groupBox1.Controls.Add(this.ButtonRemoveShip); + this.groupBox1.Controls.Add(this.ButtonAddShip); + this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBox1.Location = new System.Drawing.Point(600, 0); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(200, 450); + this.groupBox1.TabIndex = 1; + this.groupBox1.TabStop = false; + // + // buttonDown + // + this.buttonDown.BackgroundImage = global::WarmlyShip.Properties.Resources.Down; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(96, 388); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 11; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonUp + // + this.buttonUp.BackgroundImage = global::WarmlyShip.Properties.Resources.Up; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(96, 352); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 10; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.BackgroundImage = global::WarmlyShip.Properties.Resources.Right; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(132, 388); + 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.BackgroundImage = global::WarmlyShip.Properties.Resources.Left; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(60, 388); + 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); + // + // ButtonShowStorage + // + this.ButtonShowStorage.Location = new System.Drawing.Point(6, 193); + this.ButtonShowStorage.Name = "ButtonShowStorage"; + this.ButtonShowStorage.Size = new System.Drawing.Size(182, 23); + this.ButtonShowStorage.TabIndex = 7; + this.ButtonShowStorage.Text = "Посмотреть хранилище"; + this.ButtonShowStorage.UseVisualStyleBackColor = true; + this.ButtonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // ButtonShowOnMap + // + this.ButtonShowOnMap.Location = new System.Drawing.Point(6, 243); + this.ButtonShowOnMap.Name = "ButtonShowOnMap"; + this.ButtonShowOnMap.Size = new System.Drawing.Size(188, 23); + this.ButtonShowOnMap.TabIndex = 6; + this.ButtonShowOnMap.Text = "Посмотреть карту"; + this.ButtonShowOnMap.UseVisualStyleBackColor = true; + this.ButtonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 108); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23); + this.maskedTextBoxPosition.TabIndex = 5; + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Море"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 32); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23); + this.comboBoxSelectorMap.TabIndex = 4; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorShip_SelectedIndexChanged); + // + // ButtonRemoveShip + // + this.ButtonRemoveShip.Location = new System.Drawing.Point(6, 137); + this.ButtonRemoveShip.Name = "ButtonRemoveShip"; + this.ButtonRemoveShip.Size = new System.Drawing.Size(188, 25); + this.ButtonRemoveShip.TabIndex = 3; + this.ButtonRemoveShip.Text = "Удалить корабль"; + this.ButtonRemoveShip.UseVisualStyleBackColor = true; + this.ButtonRemoveShip.Click += new System.EventHandler(this.ButtonRemoveShip_Click); + // + // ButtonAddShip + // + this.ButtonAddShip.Location = new System.Drawing.Point(6, 61); + this.ButtonAddShip.Name = "ButtonAddShip"; + this.ButtonAddShip.Size = new System.Drawing.Size(188, 25); + this.ButtonAddShip.TabIndex = 2; + this.ButtonAddShip.Text = "Добавить корабль"; + this.ButtonAddShip.UseVisualStyleBackColor = true; + this.ButtonAddShip.Click += new System.EventHandler(this.ButtonAddShip_Click); + // + // pictureBox1 + // + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox1.Location = new System.Drawing.Point(0, 0); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(600, 450); + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // FormMapWithSetWarmlyShip + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.groupBox1); + this.Name = "FormMapWithSetWarmlyShip"; + this.Text = "FormMapWithSetWarmlyShip"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBox1; + private PictureBox pictureBox1; + private ComboBox comboBoxSelectorMap; + private Button ButtonRemoveShip; + private Button ButtonAddShip; + private MaskedTextBox maskedTextBoxPosition; + private Button ButtonShowOnMap; + private Button ButtonShowStorage; + private Button buttonDown; + private Button buttonUp; + private Button buttonRight; + private Button buttonLeft; + } +} \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs new file mode 100644 index 0000000..5e5f9bd --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.DataFormats; + +namespace WarmlyShip +{ + public partial class FormMapWithSetWarmlyShip : Form + { + /// + /// Объект от класса карты с набором объектов + /// + private MapWithSetWarmlyShipGeneric _mapWarmlyShipCollectionGeneric; + /// + /// Конструктор + /// + public FormMapWithSetWarmlyShip() + { + InitializeComponent(); + } + /// + /// Выбор карты + /// + /// + /// + private void ComboBoxSelectorShip_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + case "Море": + map = new MyMap(); + break; + } + if (map != null) + { + _mapWarmlyShipCollectionGeneric = new MapWithSetWarmlyShipGeneric( + pictureBox1.Width, pictureBox1.Height, map); + } + else + { + _mapWarmlyShipCollectionGeneric = null; + } + + } + + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAddShip_Click(object sender, EventArgs e) + { + if (_mapWarmlyShipCollectionGeneric == null) + { + return; + } + FormShip form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObjectShip car = new(form.SelectedShip); + if (_mapWarmlyShipCollectionGeneric + car) + { + MessageBox.Show("Объект добавлен"); + pictureBox1.Image = _mapWarmlyShipCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + } + + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveShip_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 (_mapWarmlyShipCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBox1.Image = _mapWarmlyShipCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + + } + + /// + /// Вывод набора + /// + /// + /// + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapWarmlyShipCollectionGeneric == null) + { + return; + } + pictureBox1.Image = _mapWarmlyShipCollectionGeneric.ShowSet(); + } + + /// + /// Вывод карты + /// + /// + /// + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapWarmlyShipCollectionGeneric == null) + { + return; + } + pictureBox1.Image = _mapWarmlyShipCollectionGeneric.ShowOnMap(); + } + + /// + /// Перемещение + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapWarmlyShipCollectionGeneric == 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; + } + + pictureBox1.Image = _mapWarmlyShipCollectionGeneric.MoveObject(dir); + } + + + } +} diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.resx b/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormShip.Designer.cs b/WarmlyShip/WarmlyShip/FormShip.Designer.cs index a7d1bc9..0520fd6 100644 --- a/WarmlyShip/WarmlyShip/FormShip.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormShip.Designer.cs @@ -39,6 +39,7 @@ this.buttonRight = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); this.buttonCreateModif = new System.Windows.Forms.Button(); + this.buttonSelectShip = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -153,11 +154,22 @@ this.buttonCreateModif.UseVisualStyleBackColor = true; this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); // + // buttonSelectShip + // + this.buttonSelectShip.Location = new System.Drawing.Point(611, 403); + this.buttonSelectShip.Name = "buttonSelectShip"; + this.buttonSelectShip.Size = new System.Drawing.Size(75, 23); + this.buttonSelectShip.TabIndex = 8; + this.buttonSelectShip.Text = "Выбрать"; + this.buttonSelectShip.UseVisualStyleBackColor = true; + this.buttonSelectShip.Click += new System.EventHandler(this.buttonSelectShip_Click); + // // FormShip // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(824, 462); + this.Controls.Add(this.buttonSelectShip); this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonRight); @@ -189,5 +201,6 @@ private Button buttonRight; private Button buttonLeft; private Button buttonCreateModif; + private Button buttonSelectShip; } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormShip.cs b/WarmlyShip/WarmlyShip/FormShip.cs index 275a2eb..125d023 100644 --- a/WarmlyShip/WarmlyShip/FormShip.cs +++ b/WarmlyShip/WarmlyShip/FormShip.cs @@ -5,6 +5,10 @@ namespace WarmlyShip public partial class FormShip : Form { private DrawningShip _ship; + /// + /// + /// + public DrawningShip SelectedShip { get; private set; } public FormShip() { @@ -50,24 +54,7 @@ namespace WarmlyShip /// private void ButtonMove_Click(object sender, EventArgs e) { - // - string name = ((Button)sender)?.Name ?? string.Empty; - switch (name) - { - case "buttonUp": - _ship?.MoveTransport(Direction.Up); - break; - case "buttonDown": - _ship?.MoveTransport(Direction.Down); - break; - case "buttonLeft": - _ship?.MoveTransport(Direction.Left); - break; - case "buttonRight": - _ship?.MoveTransport(Direction.Right); - break; - } - Draw(); + } /// /// @@ -94,5 +81,11 @@ namespace WarmlyShip SetData(); Draw(); } + + private void buttonSelectShip_Click(object sender, EventArgs e) + { + SelectedShip = _ship; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/Program.cs b/WarmlyShip/WarmlyShip/Program.cs index 9bf5de7..e3b8eb1 100644 --- a/WarmlyShip/WarmlyShip/Program.cs +++ b/WarmlyShip/WarmlyShip/Program.cs @@ -11,7 +11,7 @@ namespace WarmlyShip // 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 FormMapWithSetWarmlyShip()); } } } \ No newline at end of file