diff --git a/Liner/Liner/Direction.cs b/Liner/Liner/Direction.cs
index 95a7a8d..24ae061 100644
--- a/Liner/Liner/Direction.cs
+++ b/Liner/Liner/Direction.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Liner
{
- internal enum Direction
+ public enum Direction
{
None=0,
Up = 1,
diff --git a/Liner/Liner/DrawingShip.cs b/Liner/Liner/DrawingShip.cs
index 7c3b324..848019b 100644
--- a/Liner/Liner/DrawingShip.cs
+++ b/Liner/Liner/DrawingShip.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Liner
{
- internal class DrawingShip
+ public class DrawingShip
{
public EntityShip Ship { get; protected set; }
protected float _startPosX;
diff --git a/Liner/Liner/EntityShip.cs b/Liner/Liner/EntityShip.cs
index 7946fa5..08b2b0b 100644
--- a/Liner/Liner/EntityShip.cs
+++ b/Liner/Liner/EntityShip.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Liner
{
- internal class EntityShip
+ public class EntityShip
{
public int Speed { get; private set; }
diff --git a/Liner/Liner/FormMap.Designer.cs b/Liner/Liner/FormMap.Designer.cs
deleted file mode 100644
index 4e97c18..0000000
--- a/Liner/Liner/FormMap.Designer.cs
+++ /dev/null
@@ -1,212 +0,0 @@
-namespace Liner
-{
- partial class FormMap
- {
- ///
- /// 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.pictureBoxShip = 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.buttonLeft = new System.Windows.Forms.Button();
- this.buttonUp = new System.Windows.Forms.Button();
- this.buttonDown = new System.Windows.Forms.Button();
- this.buttonRight = new System.Windows.Forms.Button();
- this.buttonCreateModif = new System.Windows.Forms.Button();
- this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
- this.statusStrip.SuspendLayout();
- this.SuspendLayout();
- //
- // pictureBoxShip
- //
- this.pictureBoxShip.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBoxShip.Location = new System.Drawing.Point(0, 0);
- this.pictureBoxShip.Name = "pictureBoxShip";
- this.pictureBoxShip.Size = new System.Drawing.Size(800, 424);
- this.pictureBoxShip.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
- this.pictureBoxShip.TabIndex = 0;
- this.pictureBoxShip.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, 392);
- 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);
- //
- // buttonLeft
- //
- this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonLeft.BackgroundImage = global::Liner.Properties.Resources._1;
- this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(686, 391);
- this.buttonLeft.Name = "buttonLeft";
- this.buttonLeft.Size = new System.Drawing.Size(30, 30);
- this.buttonLeft.TabIndex = 3;
- 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::Liner.Properties.Resources._4;
- this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(722, 355);
- this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(30, 30);
- this.buttonUp.TabIndex = 4;
- this.buttonUp.UseVisualStyleBackColor = true;
- this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonDown
- //
- this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonDown.BackgroundImage = global::Liner.Properties.Resources._2;
- this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(722, 391);
- this.buttonDown.Name = "buttonDown";
- this.buttonDown.Size = new System.Drawing.Size(30, 30);
- this.buttonDown.TabIndex = 5;
- this.buttonDown.UseVisualStyleBackColor = true;
- this.buttonDown.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::Liner.Properties.Resources._3;
- this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(758, 391);
- this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(30, 30);
- this.buttonRight.TabIndex = 6;
- this.buttonRight.UseVisualStyleBackColor = true;
- this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonCreateModif
- //
- this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreateModif.Location = new System.Drawing.Point(112, 391);
- this.buttonCreateModif.Name = "buttonCreateModif";
- this.buttonCreateModif.Size = new System.Drawing.Size(121, 29);
- this.buttonCreateModif.TabIndex = 7;
- this.buttonCreateModif.Text = "Модификация";
- this.buttonCreateModif.UseVisualStyleBackColor = true;
- this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
- //
- // comboBoxSelectorMap
- //
- this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBoxSelectorMap.FormattingEnabled = true;
- this.comboBoxSelectorMap.Items.AddRange(new object[] {
- "Простая карта",
- "Море и айсберги",
- "Болото"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
- this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28);
- this.comboBoxSelectorMap.TabIndex = 8;
- this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged_1);
- //
- // FormMap
- //
- 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.buttonCreateModif);
- this.Controls.Add(this.buttonRight);
- this.Controls.Add(this.buttonDown);
- this.Controls.Add(this.buttonUp);
- this.Controls.Add(this.buttonLeft);
- this.Controls.Add(this.buttonCreate);
- this.Controls.Add(this.pictureBoxShip);
- this.Controls.Add(this.statusStrip);
- this.Name = "FormMap";
- this.Text = "Карта";
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit();
- this.statusStrip.ResumeLayout(false);
- this.statusStrip.PerformLayout();
- this.ResumeLayout(false);
- this.PerformLayout();
-
- }
-
- #endregion
-
- private PictureBox pictureBoxShip;
- 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 buttonCreateModif;
- private ComboBox comboBoxSelectorMap;
-
- }
-}
\ No newline at end of file
diff --git a/Liner/Liner/FormMap.cs b/Liner/Liner/FormMap.cs
deleted file mode 100644
index 4315453..0000000
--- a/Liner/Liner/FormMap.cs
+++ /dev/null
@@ -1,91 +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 Liner
-{
- public partial class FormMap : Form
- {
- private AbstractMap _abstractMap;
- public FormMap()
- {
- InitializeComponent();
- _abstractMap = new SimpleMap();
- }
- private void SetData(DrawingShip ship)
- {
- Random rnd = new();
- toolStripStatusLabelSpeed.Text = $"Скорость: {ship.Ship.Speed}";
- toolStripStatusLabelWeight.Text = $"Вес: {ship.Ship.Weight}";
- toolStripStatusLabelBodyColor.Text = $"Цвет: {ship.Ship.BodyColor.Name}";
- pictureBoxShip.Image = _abstractMap.CreateMap(pictureBoxShip.Width, pictureBoxShip.Height, new DrawingObjectShip(ship));
- new DrawingObjectShip(ship);
- }
-
-
-
- private void ButtonCreate_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- var ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- SetData(ship);
-
- }
- 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;
- }
- pictureBoxShip.Image = _abstractMap?.MoveObject(dir);
- }
-
- private void ButtonCreateModif_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- var ship = new DrawningLiner(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(ship);
-
- }
-
-
-
- private void ComboBoxSelectorMap_SelectedIndexChanged_1(object sender, EventArgs e)
- {
- switch (comboBoxSelectorMap.Text)
- {
- case "Простая карта":
- _abstractMap = new SimpleMap();
- break;
- case "Море и айсберги":
- _abstractMap = new SeaMap();
- break;
- case "Болото":
- _abstractMap = new SwampMap();
- break;
-
- }
- }
-
-
- }
-}
diff --git a/Liner/Liner/FormMapWithSetShips.Designer.cs b/Liner/Liner/FormMapWithSetShips.Designer.cs
new file mode 100644
index 0000000..b2e1d3e
--- /dev/null
+++ b/Liner/Liner/FormMapWithSetShips.Designer.cs
@@ -0,0 +1,217 @@
+namespace Liner
+{
+ partial class FormMapWithSetShips
+ {
+ ///
+ /// 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.groupBox = new System.Windows.Forms.GroupBox();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.ButtonShowOnMap = new System.Windows.Forms.Button();
+ this.ButtonShowStorage = new System.Windows.Forms.Button();
+ this.ButtonRemoveShip = new System.Windows.Forms.Button();
+ this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
+ this.ButtonAddShip = new System.Windows.Forms.Button();
+ this.ComboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.groupBox.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.SuspendLayout();
+ //
+ // groupBox
+ //
+ this.groupBox.Controls.Add(this.buttonRight);
+ this.groupBox.Controls.Add(this.buttonDown);
+ this.groupBox.Controls.Add(this.buttonUp);
+ this.groupBox.Controls.Add(this.buttonLeft);
+ this.groupBox.Controls.Add(this.ButtonShowOnMap);
+ this.groupBox.Controls.Add(this.ButtonShowStorage);
+ this.groupBox.Controls.Add(this.ButtonRemoveShip);
+ this.groupBox.Controls.Add(this.maskedTextBoxPosition);
+ this.groupBox.Controls.Add(this.ButtonAddShip);
+ this.groupBox.Controls.Add(this.ComboBoxSelectorMap);
+ this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
+ this.groupBox.Location = new System.Drawing.Point(627, 0);
+ this.groupBox.Name = "groupBox";
+ this.groupBox.Size = new System.Drawing.Size(250, 450);
+ this.groupBox.TabIndex = 0;
+ this.groupBox.TabStop = false;
+ this.groupBox.Text = "Инструменты";
+ //
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::Liner.Properties.Resources._3;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(204, 408);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 17;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::Liner.Properties.Resources._2;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(168, 408);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 16;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.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::Liner.Properties.Resources._4;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(168, 372);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 15;
+ 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::Liner.Properties.Resources._1;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(132, 408);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.TabIndex = 14;
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // ButtonShowOnMap
+ //
+ this.ButtonShowOnMap.Location = new System.Drawing.Point(28, 323);
+ this.ButtonShowOnMap.Name = "ButtonShowOnMap";
+ this.ButtonShowOnMap.Size = new System.Drawing.Size(200, 29);
+ this.ButtonShowOnMap.TabIndex = 13;
+ this.ButtonShowOnMap.Text = "Посмотреть карту";
+ this.ButtonShowOnMap.UseVisualStyleBackColor = true;
+ this.ButtonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
+ //
+ // ButtonShowStorage
+ //
+ this.ButtonShowStorage.Location = new System.Drawing.Point(28, 258);
+ this.ButtonShowStorage.Name = "ButtonShowStorage";
+ this.ButtonShowStorage.Size = new System.Drawing.Size(200, 29);
+ this.ButtonShowStorage.TabIndex = 12;
+ this.ButtonShowStorage.Text = "Посмотреть хранилище";
+ this.ButtonShowStorage.UseVisualStyleBackColor = true;
+ this.ButtonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
+ //
+ // ButtonRemoveShip
+ //
+ this.ButtonRemoveShip.Location = new System.Drawing.Point(28, 191);
+ this.ButtonRemoveShip.Name = "ButtonRemoveShip";
+ this.ButtonRemoveShip.Size = new System.Drawing.Size(200, 29);
+ this.ButtonRemoveShip.TabIndex = 11;
+ this.ButtonRemoveShip.Text = "Удалить корабль";
+ this.ButtonRemoveShip.UseVisualStyleBackColor = true;
+ this.ButtonRemoveShip.Click += new System.EventHandler(this.ButtonRemoveShip_Click);
+ //
+ // maskedTextBoxPosition
+ //
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(28, 158);
+ this.maskedTextBoxPosition.Mask = "00";
+ this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(200, 27);
+ this.maskedTextBoxPosition.TabIndex = 10;
+ //
+ // ButtonAddShip
+ //
+ this.ButtonAddShip.Location = new System.Drawing.Point(28, 110);
+ this.ButtonAddShip.Name = "ButtonAddShip";
+ this.ButtonAddShip.Size = new System.Drawing.Size(200, 29);
+ this.ButtonAddShip.TabIndex = 2;
+ this.ButtonAddShip.Text = "Добавить корабль";
+ this.ButtonAddShip.UseVisualStyleBackColor = true;
+ this.ButtonAddShip.Click += new System.EventHandler(this.ButtonAddShip_Click);
+ //
+ // ComboBoxSelectorMap
+ //
+ this.ComboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.ComboBoxSelectorMap.FormattingEnabled = true;
+ this.ComboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта",
+ "Море и айсберги",
+ "Болото"});
+ this.ComboBoxSelectorMap.Location = new System.Drawing.Point(28, 38);
+ this.ComboBoxSelectorMap.Name = "ComboBoxSelectorMap";
+ this.ComboBoxSelectorMap.Size = new System.Drawing.Size(200, 28);
+ this.ComboBoxSelectorMap.TabIndex = 9;
+ this.ComboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
+ //
+ // 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(627, 450);
+ this.pictureBox.TabIndex = 1;
+ this.pictureBox.TabStop = false;
+ //
+ // FormMapWithSetShips
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(877, 450);
+ this.Controls.Add(this.pictureBox);
+ this.Controls.Add(this.groupBox);
+ this.Name = "FormMapWithSetShips";
+ this.Text = "FormMapWithSetShips";
+ this.groupBox.ResumeLayout(false);
+ this.groupBox.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private GroupBox groupBox;
+ private PictureBox pictureBox;
+ private ComboBox ComboBoxSelectorMap;
+ private Button ButtonShowOnMap;
+ private Button ButtonShowStorage;
+ private Button ButtonRemoveShip;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button ButtonAddShip;
+ private Button buttonRight;
+ private Button buttonDown;
+ private Button buttonUp;
+ private Button buttonLeft;
+ }
+}
\ No newline at end of file
diff --git a/Liner/Liner/FormMapWithSetShips.cs b/Liner/Liner/FormMapWithSetShips.cs
new file mode 100644
index 0000000..ee40e34
--- /dev/null
+++ b/Liner/Liner/FormMapWithSetShips.cs
@@ -0,0 +1,135 @@
+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 Liner
+{
+ public partial class FormMapWithSetShips : Form
+ {
+ private MapWithSetShipsGeneric _mapShipsCollectionGeneric;
+ public FormMapWithSetShips()
+ {
+ InitializeComponent();
+ }
+
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ AbstractMap map = null;
+ switch (ComboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ map = new SimpleMap();
+ break;
+ case "Море и айсберги":
+ map = new SeaMap();
+ break;
+ case "Болото":
+ map = new SwampMap();
+ break;
+ }
+ if (map != null)
+ {
+ _mapShipsCollectionGeneric = new MapWithSetShipsGeneric(
+ pictureBox.Width, pictureBox.Height, map);
+ }
+ else
+ {
+ _mapShipsCollectionGeneric = null;
+ }
+ }
+
+ private void ButtonAddShip_Click(object sender, EventArgs e)
+ {
+ if (_mapShipsCollectionGeneric == null)
+ {
+ return;
+ }
+ FormShip form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ DrawingObjectShip ship = new(form.SelectedShip);
+ if (_mapShipsCollectionGeneric + ship)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapShipsCollectionGeneric.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 (_mapShipsCollectionGeneric - pos)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapShipsCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ private void ButtonShowStorage_Click(object sender, EventArgs e)
+ {
+ if (_mapShipsCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapShipsCollectionGeneric.ShowSet();
+ }
+
+ private void ButtonShowOnMap_Click(object sender, EventArgs e)
+ {
+ if (_mapShipsCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapShipsCollectionGeneric.ShowOnMap();
+ }
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_mapShipsCollectionGeneric == 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 = _mapShipsCollectionGeneric.MoveObject(dir);
+ }
+ }
+}
diff --git a/Liner/Liner/FormMap.resx b/Liner/Liner/FormMapWithSetShips.resx
similarity index 93%
rename from Liner/Liner/FormMap.resx
rename to Liner/Liner/FormMapWithSetShips.resx
index 2c0949d..f298a7b 100644
--- a/Liner/Liner/FormMap.resx
+++ b/Liner/Liner/FormMapWithSetShips.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/Liner/Liner/FormShip.Designer.cs b/Liner/Liner/FormShip.Designer.cs
index 341b36c..c30db94 100644
--- a/Liner/Liner/FormShip.Designer.cs
+++ b/Liner/Liner/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.statusStrip.SuspendLayout();
this.SuspendLayout();
@@ -155,11 +156,23 @@
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
+ // ButtonSelectShip
+ //
+ this.ButtonSelectShip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.ButtonSelectShip.Location = new System.Drawing.Point(552, 373);
+ this.ButtonSelectShip.Name = "ButtonSelectShip";
+ this.ButtonSelectShip.Size = new System.Drawing.Size(94, 29);
+ 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(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.ButtonSelectShip);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight);
@@ -191,5 +204,6 @@
private Button buttonRight;
private Button buttonLeft;
private Button buttonCreateModif;
+ private Button ButtonSelectShip;
}
}
\ No newline at end of file
diff --git a/Liner/Liner/FormShip.cs b/Liner/Liner/FormShip.cs
index 10f9e4d..c86206e 100644
--- a/Liner/Liner/FormShip.cs
+++ b/Liner/Liner/FormShip.cs
@@ -5,12 +5,11 @@ namespace Liner
{
private DrawingShip _ship;
-
+ public DrawingShip SelectedShip { get; private set; }
public FormShip()
{
InitializeComponent();
}
-
private void Draw()
{
Bitmap bmp = new Bitmap(pictureBoxShip.Width, pictureBoxShip.Height);
@@ -19,7 +18,6 @@ namespace Liner
pictureBoxShip.Image = bmp;
}
-
private void SetData()
{
Random rnd = new();
@@ -30,8 +28,13 @@ namespace Liner
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
- Random rnd = new();
- _ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ Random random = new();
+ Color myColor = new Color();
+ ColorDialog MyDialog = new ColorDialog();
+ if (MyDialog.ShowDialog() == DialogResult.OK)
+ myColor = MyDialog.Color;
+ _ship = new DrawingShip(random.Next(30, 50), random.Next(1000, 2000),
+ myColor);
SetData();
Draw();
}
@@ -56,19 +59,32 @@ namespace Liner
}
Draw();
}
-
private void PictureBoxShip_Resize(object sender, EventArgs e)
{
_ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height);
Draw();
}
-
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
- Random rnd = new();
- _ship = new DrawningLiner(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)));
+ Random random = new();
+ Color firstColor = new Color();
+ Color secondColor = new Color();
+ ColorDialog MyDialog = new ColorDialog();
+ if (MyDialog.ShowDialog() == DialogResult.OK)
+ firstColor = MyDialog.Color;
+ MyDialog = new ColorDialog();
+ if (MyDialog.ShowDialog() == DialogResult.OK)
+ secondColor = MyDialog.Color;
+ _ship = new DrawningLiner(random.Next(30, 50), random.Next(1000, 2000),
+ firstColor, secondColor, Convert.ToBoolean(random.Next(0, 2)),
+ Convert.ToBoolean(random.Next(0, 2)));
SetData();
Draw();
}
+ private void ButtonSelectShip_Click(object sender, EventArgs e)
+ {
+ SelectedShip = _ship;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/Liner/Liner/MapWithSetShipsGeneric.cs b/Liner/Liner/MapWithSetShipsGeneric.cs
index 624fa39..a61420d 100644
--- a/Liner/Liner/MapWithSetShipsGeneric.cs
+++ b/Liner/Liner/MapWithSetShipsGeneric.cs
@@ -123,7 +123,7 @@ namespace Liner
int curHeight = 0;
for (int i = 0; i < _setShips.Count; i++)
{
- _setShips.Get(i)?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - (_pictureWidth / 8),
+ _setShips.Get(i)?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - (_pictureWidth / 7),
curHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
_setShips.Get(i)?.DrawningObject(g);
diff --git a/Liner/Liner/Program.cs b/Liner/Liner/Program.cs
index d04dba2..9edbf87 100644
--- a/Liner/Liner/Program.cs
+++ b/Liner/Liner/Program.cs
@@ -11,7 +11,7 @@ namespace Liner
// 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 FormMapWithSetShips());
}
}
}
\ No newline at end of file