From 4b867003e2639d3bb8a1674666f63042538ee696 Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Sat, 1 Oct 2022 12:51:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetWarships.Designer.cs | 139 +++++++++--------- .../AircraftCarrier/FormMapWithSetWarships.cs | 22 +++ .../AircraftCarrier/FormWarship.cs | 22 ++- .../MapWithSetWarshipsGeneric.cs | 9 +- 4 files changed, 118 insertions(+), 74 deletions(-) diff --git a/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.Designer.cs b/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.Designer.cs index acef8a2..263bcbd 100644 --- a/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.Designer.cs +++ b/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.Designer.cs @@ -29,17 +29,17 @@ private void InitializeComponent() { this.groupBoxTools = new System.Windows.Forms.GroupBox(); - this.pictureBox = new System.Windows.Forms.PictureBox(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveWarship = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonAddWarship = 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.buttonDown = new System.Windows.Forms.Button(); - this.buttonAddWarship = new System.Windows.Forms.Button(); - this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); - this.buttonRemoveWarship = new System.Windows.Forms.Button(); - this.buttonShowStorage = new System.Windows.Forms.Button(); - this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); this.groupBoxTools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); @@ -64,26 +64,54 @@ this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Tools"; // - // pictureBox + // buttonShowOnMap // - 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(787, 593); - this.pictureBox.TabIndex = 1; - this.pictureBox.TabStop = false; + this.buttonShowOnMap.Location = new System.Drawing.Point(13, 431); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35); + this.buttonShowOnMap.TabIndex = 18; + this.buttonShowOnMap.Text = "Show map"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); // - // comboBoxSelectorMap + // buttonShowStorage // - 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(13, 22); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23); - this.comboBoxSelectorMap.TabIndex = 9; + this.buttonShowStorage.Location = new System.Drawing.Point(13, 323); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(175, 35); + this.buttonShowStorage.TabIndex = 17; + this.buttonShowStorage.Text = "Show storage"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // buttonRemoveWarship + // + this.buttonRemoveWarship.Location = new System.Drawing.Point(13, 208); + this.buttonRemoveWarship.Name = "buttonRemoveWarship"; + this.buttonRemoveWarship.Size = new System.Drawing.Size(175, 35); + this.buttonRemoveWarship.TabIndex = 16; + this.buttonRemoveWarship.Text = "Remove warship"; + this.buttonRemoveWarship.UseVisualStyleBackColor = true; + this.buttonRemoveWarship.Click += new System.EventHandler(this.ButtonRemoveWarship_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(13, 177); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); + this.maskedTextBoxPosition.TabIndex = 15; + this.maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonAddWarship + // + this.buttonAddWarship.Location = new System.Drawing.Point(13, 114); + this.buttonAddWarship.Name = "buttonAddWarship"; + this.buttonAddWarship.Size = new System.Drawing.Size(175, 35); + this.buttonAddWarship.TabIndex = 14; + this.buttonAddWarship.Text = "Add warship"; + this.buttonAddWarship.UseVisualStyleBackColor = true; + this.buttonAddWarship.Click += new System.EventHandler(this.ButtonAddWarship_Click); // // buttonRight // @@ -137,54 +165,27 @@ this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); // - // buttonAddWarship + // comboBoxSelectorMap // - this.buttonAddWarship.Location = new System.Drawing.Point(13, 114); - this.buttonAddWarship.Name = "buttonAddWarship"; - this.buttonAddWarship.Size = new System.Drawing.Size(175, 35); - this.buttonAddWarship.TabIndex = 14; - this.buttonAddWarship.Text = "Add warship"; - this.buttonAddWarship.UseVisualStyleBackColor = true; - this.buttonAddWarship.Click += new System.EventHandler(this.ButtonAddWarship_Click); + 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(13, 22); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23); + this.comboBoxSelectorMap.TabIndex = 9; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); // - // maskedTextBoxPosition + // pictureBox // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(13, 177); - this.maskedTextBoxPosition.Mask = "00"; - this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); - this.maskedTextBoxPosition.TabIndex = 15; - this.maskedTextBoxPosition.ValidatingType = typeof(int); - // - // buttonRemoveWarship - // - this.buttonRemoveWarship.Location = new System.Drawing.Point(13, 208); - this.buttonRemoveWarship.Name = "buttonRemoveWarship"; - this.buttonRemoveWarship.Size = new System.Drawing.Size(175, 35); - this.buttonRemoveWarship.TabIndex = 16; - this.buttonRemoveWarship.Text = "Remove warship"; - this.buttonRemoveWarship.UseVisualStyleBackColor = true; - this.buttonRemoveWarship.Click += new System.EventHandler(this.ButtonRemoveWarship_Click); - // - // buttonShowStorage - // - this.buttonShowStorage.Location = new System.Drawing.Point(13, 323); - this.buttonShowStorage.Name = "buttonShowStorage"; - this.buttonShowStorage.Size = new System.Drawing.Size(175, 35); - this.buttonShowStorage.TabIndex = 17; - this.buttonShowStorage.Text = "Show storage"; - this.buttonShowStorage.UseVisualStyleBackColor = true; - this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); - // - // buttonShowOnMap - // - this.buttonShowOnMap.Location = new System.Drawing.Point(13, 431); - this.buttonShowOnMap.Name = "buttonShowOnMap"; - this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35); - this.buttonShowOnMap.TabIndex = 18; - this.buttonShowOnMap.Text = "Show map"; - this.buttonShowOnMap.UseVisualStyleBackColor = true; - this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_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(787, 593); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; // // FormMapWithSetWarships // diff --git a/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.cs b/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.cs index 6915f00..96c5f9d 100644 --- a/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.cs +++ b/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.cs @@ -24,6 +24,28 @@ namespace AircraftCarrier { 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; + } + if (map != null) + { + _mapWarshipsCollectionGeneric = new MapWithSetWarshipsGeneric( + pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapWarshipsCollectionGeneric = null; + } + } /// /// Добавление объекта /// diff --git a/AircraftCarrier/AircraftCarrier/FormWarship.cs b/AircraftCarrier/AircraftCarrier/FormWarship.cs index d73d312..c6d7f9c 100644 --- a/AircraftCarrier/AircraftCarrier/FormWarship.cs +++ b/AircraftCarrier/AircraftCarrier/FormWarship.cs @@ -40,6 +40,12 @@ namespace AircraftCarrier private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } _warship = new DrawingWarship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); SetData(); Draw(); @@ -87,9 +93,19 @@ namespace AircraftCarrier private void ButtonCreateModif_Click(object sender, EventArgs e) { Random rnd = new(); - _warship = new DrawingAircraftCarrier(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)), + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + 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; + } + _warship = new DrawingAircraftCarrier(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(); Draw(); diff --git a/AircraftCarrier/AircraftCarrier/MapWithSetWarshipsGeneric.cs b/AircraftCarrier/AircraftCarrier/MapWithSetWarshipsGeneric.cs index d0d7e83..4caabe2 100644 --- a/AircraftCarrier/AircraftCarrier/MapWithSetWarshipsGeneric.cs +++ b/AircraftCarrier/AircraftCarrier/MapWithSetWarshipsGeneric.cs @@ -167,8 +167,13 @@ namespace AircraftCarrier { for (int i = 0; i < _setWarships.Count; i++) { - // TODO установка позиции - + for (int k = 0; k < _pictureWidth / _placeSizeWidth; k++) + { + for (int l = 0; l < _pictureHeight / _placeSizeHeight + 1; ++l) + { + _setWarships.Get(i)?.SetObject(k * _placeSizeWidth, l * _placeSizeHeight, _pictureWidth, _pictureHeight); + } + } _setWarships.Get(i)?.DrawningObject(g); } }