From 2cea7ab205686ba97df6deee7a36b91533ea28d0 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Sat, 1 Oct 2022 15:59:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D1=80=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81=D1=8B=20=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=BD=D0=B8=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AntiAircraftGun/AntiAircraftGun/Direction.cs | 2 +- .../AntiAircraftGun/DrawingAntiAircraftGun.cs | 2 +- .../AntiAircraftGun/EntityAntiAircraftGun.cs | 2 +- .../FormAntiAircraftGun.Designer.cs | 14 ++ .../AntiAircraftGun/FormAntiAircraftGun.cs | 10 + .../AntiAircraftGun/FormMap.Designer.cs | 210 ----------------- AntiAircraftGun/AntiAircraftGun/FormMap.cs | 103 --------- ...FormMapWithSetAntiAircraftGuns.Designer.cs | 216 ++++++++++++++++++ .../FormMapWithSetAntiAircraftGuns.cs | 165 +++++++++++++ ...sx => FormMapWithSetAntiAircraftGuns.resx} | 3 - .../MapWithSetAntiAircraftGunsGeneric.cs | 175 ++++++++++++++ AntiAircraftGun/AntiAircraftGun/Program.cs | 2 +- .../SetAntiAircraftGunsGeneric.cs | 80 +++++++ 13 files changed, 664 insertions(+), 320 deletions(-) delete mode 100644 AntiAircraftGun/AntiAircraftGun/FormMap.Designer.cs delete mode 100644 AntiAircraftGun/AntiAircraftGun/FormMap.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.Designer.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs rename AntiAircraftGun/AntiAircraftGun/{FormMap.resx => FormMapWithSetAntiAircraftGuns.resx} (93%) create mode 100644 AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs diff --git a/AntiAircraftGun/AntiAircraftGun/Direction.cs b/AntiAircraftGun/AntiAircraftGun/Direction.cs index 2d7a988..d086607 100644 --- a/AntiAircraftGun/AntiAircraftGun/Direction.cs +++ b/AntiAircraftGun/AntiAircraftGun/Direction.cs @@ -9,7 +9,7 @@ namespace AntiAircraftGun /// /// Направление перемещения /// - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/AntiAircraftGun/AntiAircraftGun/DrawingAntiAircraftGun.cs b/AntiAircraftGun/AntiAircraftGun/DrawingAntiAircraftGun.cs index dd6cbf3..803c3b2 100644 --- a/AntiAircraftGun/AntiAircraftGun/DrawingAntiAircraftGun.cs +++ b/AntiAircraftGun/AntiAircraftGun/DrawingAntiAircraftGun.cs @@ -9,7 +9,7 @@ namespace AntiAircraftGun /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// - internal class DrawingAntiAircraftGun + public class DrawingAntiAircraftGun { /// /// Класс-сущность diff --git a/AntiAircraftGun/AntiAircraftGun/EntityAntiAircraftGun.cs b/AntiAircraftGun/AntiAircraftGun/EntityAntiAircraftGun.cs index a9705c9..aa554aa 100644 --- a/AntiAircraftGun/AntiAircraftGun/EntityAntiAircraftGun.cs +++ b/AntiAircraftGun/AntiAircraftGun/EntityAntiAircraftGun.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AntiAircraftGun { - internal class EntityAntiAircraftGun + public class EntityAntiAircraftGun { /// /// Скорость diff --git a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs index 57fd6b3..1031628 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs @@ -39,6 +39,7 @@ this.buttonRight = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonCreareModif = new System.Windows.Forms.Button(); + this.buttonSelect = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -154,11 +155,23 @@ this.buttonCreareModif.UseVisualStyleBackColor = true; this.buttonCreareModif.Click += new System.EventHandler(this.ButtonCreareModif_Click); // + // buttonSelect + // + this.buttonSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSelect.Location = new System.Drawing.Point(578, 379); + this.buttonSelect.Name = "buttonSelect"; + this.buttonSelect.Size = new System.Drawing.Size(94, 29); + this.buttonSelect.TabIndex = 8; + this.buttonSelect.Text = "Выбрать"; + this.buttonSelect.UseVisualStyleBackColor = true; + this.buttonSelect.Click += new System.EventHandler(this.ButtonSelect_Click); + // // FormAntiAircraftGun // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 451); + this.Controls.Add(this.buttonSelect); this.Controls.Add(this.buttonCreareModif); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonRight); @@ -192,5 +205,6 @@ private Button buttonRight; private Button buttonDown; private Button buttonCreareModif; + private Button buttonSelect; } } \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs index 9964a36..3edd9de 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs @@ -5,6 +5,10 @@ namespace AntiAircraftGun public partial class FormAntiAircraftGun : Form { private DrawingAntiAircraftGun _antiAircrafGun; + /// + /// + /// + public DrawingAntiAircraftGun SelectedAntiAircraftGun { get; private set; } public FormAntiAircraftGun() { @@ -99,5 +103,11 @@ namespace AntiAircraftGun SetData(); Draw(); } + + private void ButtonSelect_Click(object sender, EventArgs e) + { + SelectedAntiAircraftGun = _antiAircrafGun; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/FormMap.Designer.cs b/AntiAircraftGun/AntiAircraftGun/FormMap.Designer.cs deleted file mode 100644 index a90c9f4..0000000 --- a/AntiAircraftGun/AntiAircraftGun/FormMap.Designer.cs +++ /dev/null @@ -1,210 +0,0 @@ -namespace AntiAircraftGun -{ - 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.pictureBoxAntiAircraftGun = 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.buttonDown = new System.Windows.Forms.Button(); - this.buttonCreareModif = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit(); - this.statusStrip.SuspendLayout(); - this.SuspendLayout(); - // - // pictureBoxAntiAircraftGun - // - this.pictureBoxAntiAircraftGun.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxAntiAircraftGun.Location = new System.Drawing.Point(0, 0); - this.pictureBoxAntiAircraftGun.Name = "pictureBoxAntiAircraftGun"; - this.pictureBoxAntiAircraftGun.Size = new System.Drawing.Size(800, 425); - this.pictureBoxAntiAircraftGun.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxAntiAircraftGun.TabIndex = 0; - this.pictureBoxAntiAircraftGun.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, 425); - this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(800, 26); - this.statusStrip.TabIndex = 1; - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(73, 20); - this.toolStripStatusLabelSpeed.Text = "Скорость"; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(33, 20); - this.toolStripStatusLabelWeight.Text = "Вес"; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(42, 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(11, 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::AntiAircraftGun.Properties.Resources.arrowUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(725, 341); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 29); - 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::AntiAircraftGun.Properties.Resources.arrowLeft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(688, 379); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(30, 29); - 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::AntiAircraftGun.Properties.Resources.arrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(760, 379); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 29); - this.buttonRight.TabIndex = 5; - 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::AntiAircraftGun.Properties.Resources.arrowDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(725, 379); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(30, 29); - this.buttonDown.TabIndex = 6; - this.buttonDown.UseVisualStyleBackColor = true; - this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonCreareModif - // - this.buttonCreareModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCreareModif.Location = new System.Drawing.Point(111, 381); - this.buttonCreareModif.Name = "buttonCreareModif"; - this.buttonCreareModif.Size = new System.Drawing.Size(125, 29); - this.buttonCreareModif.TabIndex = 7; - this.buttonCreareModif.Text = "Модификация"; - this.buttonCreareModif.UseVisualStyleBackColor = true; - this.buttonCreareModif.Click += new System.EventHandler(this.ButtonCreareModif_Click); - // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта", - "Простая карта 2"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(11, 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); - // - // FormMap - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 451); - this.Controls.Add(this.comboBoxSelectorMap); - this.Controls.Add(this.buttonCreareModif); - 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.pictureBoxAntiAircraftGun); - this.Controls.Add(this.statusStrip); - this.MinimumSize = new System.Drawing.Size(50, 80); - this.Name = "FormMap"; - this.Text = "Карта"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).EndInit(); - this.statusStrip.ResumeLayout(false); - this.statusStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private PictureBox pictureBoxAntiAircraftGun; - 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 buttonCreareModif; - private ComboBox comboBoxSelectorMap; - } -} \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/FormMap.cs b/AntiAircraftGun/AntiAircraftGun/FormMap.cs deleted file mode 100644 index 8a7ce35..0000000 --- a/AntiAircraftGun/AntiAircraftGun/FormMap.cs +++ /dev/null @@ -1,103 +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 AntiAircraftGun -{ - public partial class FormMap : Form - { - private AbstractMap _abstractMap; - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - /// - /// Заполнение информации по объекту - /// - /// - private void SetData(DrawingAntiAircraftGun antiAircraftGun) - { - toolStripStatusLabelSpeed.Text = $"Скорость: {antiAircraftGun.AntiAircraftGun.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {antiAircraftGun.AntiAircraftGun.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {antiAircraftGun.AntiAircraftGun.BodyColor.Name}"; - pictureBoxAntiAircraftGun.Image = _abstractMap.CreateMap(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height, - new DrawingObjectAntiAircraftGun(antiAircraftGun)); - } - /// - /// Обработка нажатия кнопки "Создать" - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - var antiAircraftGun = new DrawingAntiAircraftGun(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - SetData(antiAircraftGun); - } - /// - /// Определение направления - /// - /// - /// - 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; - } - pictureBoxAntiAircraftGun.Image = _abstractMap?.MoveObject(dir); - } - /// - /// Обработка нажатия кнопки "Модификация" - /// - /// - /// - private void ButtonCreareModif_Click(object sender, EventArgs e) - { - Random rnd = new(); - var antiAircraftGun = new DrawingUpdateAntiAircraftGun(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(antiAircraftGun); - } - /// - /// Смена карты - /// - /// - /// - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Простая карта 2": - _abstractMap = new SimpleMap2(); - break; - } - } - } -} diff --git a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.Designer.cs b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.Designer.cs new file mode 100644 index 0000000..a2115ac --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.Designer.cs @@ -0,0 +1,216 @@ +namespace AntiAircraftGun +{ + partial class FormMapWithSetAntiAircraftGuns + { + /// + /// 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.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveAntiAircraftGun = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonAddAntiAircraftGun = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.buttonDown = 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.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBox + // + this.groupBox.Controls.Add(this.buttonShowOnMap); + this.groupBox.Controls.Add(this.buttonShowStorage); + this.groupBox.Controls.Add(this.buttonRemoveAntiAircraftGun); + this.groupBox.Controls.Add(this.maskedTextBoxPosition); + this.groupBox.Controls.Add(this.buttonAddAntiAircraftGun); + this.groupBox.Controls.Add(this.comboBoxSelectorMap); + 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.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBox.Location = new System.Drawing.Point(562, 0); + this.groupBox.Name = "groupBox"; + this.groupBox.Size = new System.Drawing.Size(238, 450); + this.groupBox.TabIndex = 0; + this.groupBox.TabStop = false; + this.groupBox.Text = "Инструменты"; + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(34, 309); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(194, 29); + this.buttonShowOnMap.TabIndex = 16; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(34, 245); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(194, 29); + this.buttonShowStorage.TabIndex = 15; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // buttonRemoveAntiAircraftGun + // + this.buttonRemoveAntiAircraftGun.Location = new System.Drawing.Point(34, 177); + this.buttonRemoveAntiAircraftGun.Name = "buttonRemoveAntiAircraftGun"; + this.buttonRemoveAntiAircraftGun.Size = new System.Drawing.Size(194, 29); + this.buttonRemoveAntiAircraftGun.TabIndex = 14; + this.buttonRemoveAntiAircraftGun.Text = "Удалить орудие"; + this.buttonRemoveAntiAircraftGun.UseVisualStyleBackColor = true; + this.buttonRemoveAntiAircraftGun.Click += new System.EventHandler(this.ButtonRemoveAntiAircraftGun_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(34, 144); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(194, 27); + this.maskedTextBoxPosition.TabIndex = 13; + // + // buttonAddAntiAircraftGun + // + this.buttonAddAntiAircraftGun.Location = new System.Drawing.Point(34, 95); + this.buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun"; + this.buttonAddAntiAircraftGun.Size = new System.Drawing.Size(194, 29); + this.buttonAddAntiAircraftGun.TabIndex = 12; + this.buttonAddAntiAircraftGun.Text = "Добавить орудие"; + this.buttonAddAntiAircraftGun.UseVisualStyleBackColor = true; + this.buttonAddAntiAircraftGun.Click += new System.EventHandler(this.ButtonAddAntiAircraftGun_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Простая карта 2"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(34, 40); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(194, 28); + this.comboBoxSelectorMap.TabIndex = 11; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(120, 408); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 29); + this.buttonDown.TabIndex = 10; + 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::AntiAircraftGun.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(155, 408); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 29); + 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::AntiAircraftGun.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(83, 408); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 29); + 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::AntiAircraftGun.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(120, 370); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 29); + this.buttonUp.TabIndex = 7; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // 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(562, 450); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // FormMapWithSetAntiAircraftGuns + // + 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.pictureBox); + this.Controls.Add(this.groupBox); + this.Name = "FormMapWithSetAntiAircraftGuns"; + this.Text = "FormMapWithSetAntiAircraftGuns"; + this.groupBox.ResumeLayout(false); + this.groupBox.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBox; + private PictureBox pictureBox; + private Button buttonDown; + private Button buttonRight; + private Button buttonLeft; + private Button buttonUp; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private Button buttonRemoveAntiAircraftGun; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonAddAntiAircraftGun; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs new file mode 100644 index 0000000..63ad8f1 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs @@ -0,0 +1,165 @@ +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 AntiAircraftGun +{ + public partial class FormMapWithSetAntiAircraftGuns : Form + { + /// + /// Объект от класса карты с набором объектов + /// + private MapWithSetAntiAircraftGunsGeneric _mapAntiAircraftGunsCollectionGeneric; + /// + /// Конструктор + /// + public FormMapWithSetAntiAircraftGuns() + { + InitializeComponent(); + } + /// + /// Выбор карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + case "Простая карта 2": + map = new SimpleMap2(); + break; + } + if (map != null) + { + _mapAntiAircraftGunsCollectionGeneric = new MapWithSetAntiAircraftGunsGeneric( + pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapAntiAircraftGunsCollectionGeneric = null; + } + } + /// + /// Добавление объекта + /// + /// + /// + /// + private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e) + { + if (_mapAntiAircraftGunsCollectionGeneric == null) + { + return; + } + FormAntiAircraftGun form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawingObjectAntiAircraftGun antiAircraftGun = new(form.SelectedAntiAircraftGun); + if (_mapAntiAircraftGunsCollectionGeneric + antiAircraftGun) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveAntiAircraftGun_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 (_mapAntiAircraftGunsCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Вывод набора + /// + /// + /// + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapAntiAircraftGunsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet(); + } + /// + /// Вывод карты + /// + /// + /// + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapAntiAircraftGunsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowOnMap(); + } + /// + /// Перемещение + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapAntiAircraftGunsCollectionGeneric == 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 = _mapAntiAircraftGunsCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/AntiAircraftGun/AntiAircraftGun/FormMap.resx b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.resx similarity index 93% rename from AntiAircraftGun/AntiAircraftGun/FormMap.resx rename to AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.resx index 2c0949d..f298a7b 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormMap.resx +++ b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.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/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs new file mode 100644 index 0000000..a877ef6 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs @@ -0,0 +1,175 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AntiAircraftGun +{ + /// + /// Карта с набром объектов под нее + /// + /// + /// + internal class MapWithSetAntiAircraftGunsGeneric + where T : class, IDrawingObject + where U : AbstractMap + { + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 210; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 90; + /// + /// Набор объектов + /// + private readonly SetAntiAircraftGunsGeneric _setAntiAircraftGuns; + /// + /// Карта + /// + private readonly U _map; + /// + /// Конструктор + /// + /// + /// + /// + public MapWithSetAntiAircraftGunsGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setAntiAircraftGuns = new SetAntiAircraftGunsGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(MapWithSetAntiAircraftGunsGeneric map, T antiAircraftGuns) + { + return map._setAntiAircraftGuns.Insert(antiAircraftGuns); + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static bool operator -(MapWithSetAntiAircraftGunsGeneric map, int position) + { + return map._setAntiAircraftGuns.Remove(position); + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawCars(gr); + return bmp; + } + /// + /// Просмотр объекта на карте + /// + /// + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setAntiAircraftGuns.Count; i++) + { + var car = _setAntiAircraftGuns.Get(i); + if (car != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, car); + } + } + return new(_pictureWidth, _pictureHeight); + } + /// + /// Перемещение объекта по крате + /// + /// + /// + public Bitmap MoveObject(Direction direction) + { + if (_map != null) + { + return _map.MoveObject(direction); + } + return new(_pictureWidth, _pictureHeight); + } + /// + /// "Взбалтываем" набор, чтобы все элементы оказались в начале + /// + private void Shaking() + { + int j = _setAntiAircraftGuns.Count - 1; + for (int i = 0; i < _setAntiAircraftGuns.Count; i++) + { + if (_setAntiAircraftGuns.Get(i) == null) + { + for (; j > i; j--) + { + var car = _setAntiAircraftGuns.Get(j); + if (car != null) + { + _setAntiAircraftGuns.Insert(car, i); + _setAntiAircraftGuns.Remove(j); + break; + } + } + if (j <= i) + { + return; + } + } + } + } + /// + /// Метод отрисовки фона + /// + /// + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + {//линия рамзетки места + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + } + } + /// + /// Метод прорисовки объектов + /// + /// + private void DrawCars(Graphics g) + { + for (int i = 0; i < _setAntiAircraftGuns.Count; i++) + { + // TODO установка позиции + _setAntiAircraftGuns.Get(i)?.DrawingObjectAntiAircraftGun(g); + } + } + } +} diff --git a/AntiAircraftGun/AntiAircraftGun/Program.cs b/AntiAircraftGun/AntiAircraftGun/Program.cs index a824863..ce76065 100644 --- a/AntiAircraftGun/AntiAircraftGun/Program.cs +++ b/AntiAircraftGun/AntiAircraftGun/Program.cs @@ -11,7 +11,7 @@ namespace AntiAircraftGun // 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 FormMapWithSetAntiAircraftGuns()); } } } \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs new file mode 100644 index 0000000..1f4fa88 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AntiAircraftGun +{ + /// + /// Параметризованный набор объектов + /// + /// + internal class SetAntiAircraftGunsGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetAntiAircraftGunsGeneric(int count) + { + _places = new T[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый автомобиль + /// + public bool Insert(T antiAircraftGun) + { + // TODO вставка в начало набора + return true; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемое орудие + /// Позиция + /// + public bool Insert(T antiAircraftGun, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = antiAircraftGun; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присовив элементу массива значение null + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + } +}