From 164be62345a27c8e34b2e360c0ddf6ce5013e87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 19 Oct 2022 10:36:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WarmlyShip/FormMapWithSetShip.Designer.cs | 211 ++++++++++++++++++ WarmlyShip/WarmlyShip/FormMapWithSetShip.cs | 130 +++++++++++ WarmlyShip/WarmlyShip/FormMapWithSetShip.resx | 60 +++++ .../WarmlyShip/MapWithSetShipGeneric.cs | 3 +- 4 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs create mode 100644 WarmlyShip/WarmlyShip/FormMapWithSetShip.cs create mode 100644 WarmlyShip/WarmlyShip/FormMapWithSetShip.resx diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs new file mode 100644 index 0000000..4625b4d --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs @@ -0,0 +1,211 @@ +namespace WarmlyShip +{ + partial class FormMapWithSetShip + { + /// + /// 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.buttonLeft = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.buttonAddShip = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.maskedTextBoxPosition); + this.groupBox1.Controls.Add(this.buttonDown); + this.groupBox1.Controls.Add(this.buttonLeft); + this.groupBox1.Controls.Add(this.buttonUp); + this.groupBox1.Controls.Add(this.buttonRight); + this.groupBox1.Controls.Add(this.button4); + this.groupBox1.Controls.Add(this.button3); + this.groupBox1.Controls.Add(this.button2); + this.groupBox1.Controls.Add(this.buttonAddShip); + this.groupBox1.Controls.Add(this.comboBoxSelectorMap); + 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 = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Инструменты"; + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::WarmlyShip.Properties.Resources.todown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(75, 391); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(50, 50); + this.buttonDown.TabIndex = 10; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.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::WarmlyShip.Properties.Resources.toleft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(19, 391); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(50, 50); + this.buttonLeft.TabIndex = 9; + 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::WarmlyShip.Properties.Resources.totop; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(75, 335); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(50, 50); + this.buttonUp.TabIndex = 8; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.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::WarmlyShip.Properties.Resources.toright; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(131, 391); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(50, 50); + this.buttonRight.TabIndex = 7; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(6, 281); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(188, 23); + this.button4.TabIndex = 5; + this.button4.Text = "Посмотреть карту"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(6, 226); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(188, 23); + this.button3.TabIndex = 4; + this.button3.Text = "Посмотреть хранилище"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(6, 170); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(188, 23); + this.button2.TabIndex = 3; + this.button2.Text = "Удалить корабль"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.ButtonRemoveShip_Click); + // + // buttonAddShip + // + this.buttonAddShip.Location = new System.Drawing.Point(6, 65); + this.buttonAddShip.Name = "buttonAddShip"; + this.buttonAddShip.Size = new System.Drawing.Size(188, 23); + this.buttonAddShip.TabIndex = 1; + this.buttonAddShip.Text = "Добавить корабль"; + this.buttonAddShip.UseVisualStyleBackColor = true; + this.buttonAddShip.Click += new System.EventHandler(this.ButtonAddShip_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23); + this.comboBoxSelectorMap.TabIndex = 0; + // + // 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(600, 450); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 116); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23); + this.maskedTextBoxPosition.TabIndex = 11; + // + // FormMapWithSetShip + // + 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.pictureBox); + this.Controls.Add(this.groupBox1); + this.Name = "FormMapWithSetShip"; + this.Text = "FormMapWithSetShip"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBox1; + private PictureBox pictureBox; + private Button buttonAddShip; + private ComboBox comboBoxSelectorMap; + private Button button4; + private Button button3; + private Button button2; + private Button buttonDown; + private Button buttonLeft; + private Button buttonUp; + private Button buttonRight; + private MaskedTextBox maskedTextBoxPosition; + } +} \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs new file mode 100644 index 0000000..78795d4 --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs @@ -0,0 +1,130 @@ +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 FormMapWithSetShip : Form + { + private MapWithSetShipGeneric _mapCarsCollectionGeneric; + + public FormMapWithSetShip() + { + InitializeComponent(); + } + + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + } + if (map != null) + { + _mapCarsCollectionGeneric = new MapWithSetShipGeneric(pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapCarsCollectionGeneric = null; + } + } + + private void ButtonAddShip_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == null) + { + return; + } + FormClass form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObjectShip ship = new(form.SelectedShip); + if (_mapCarsCollectionGeneric + ship) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapCarsCollectionGeneric.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 (_mapCarsCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); + } + + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapCarsCollectionGeneric.ShowOnMap(); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == 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 = _mapCarsCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.resx b/WarmlyShip/WarmlyShip/FormMapWithSetShip.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.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/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index 476b183..1fba030 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -104,8 +104,7 @@ namespace WarmlyShip g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, - (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } }