From a0bdea876bc3fa823d7f1e91d7655f704d44b897 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 8 Oct 2022 17:39:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetArmoredCars.Designer.cs | 219 ++++++++++++++++++ .../ArmoredCar/FormMapWithSetArmoredCars.cs | 158 +++++++++++++ .../ArmoredCar/FormMapWithSetArmoredCars.resx | 60 +++++ ArmoredCar/ArmoredCar/Program.cs | 4 +- 4 files changed, 439 insertions(+), 2 deletions(-) create mode 100644 ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.Designer.cs create mode 100644 ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs create mode 100644 ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.resx diff --git a/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.Designer.cs b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.Designer.cs new file mode 100644 index 0000000..c58f4a8 --- /dev/null +++ b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.Designer.cs @@ -0,0 +1,219 @@ +using System.Windows.Forms; + +namespace ArmoredCar +{ + partial class FormMapWithSetArmoredCars + { + /// + /// 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.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonRemoveCar = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + 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.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonAddCar = 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(); + // + // groupBoxTools + // + this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); + this.groupBoxTools.Controls.Add(this.buttonRemoveCar); + this.groupBoxTools.Controls.Add(this.buttonShowStorage); + this.groupBoxTools.Controls.Add(this.buttonDown); + this.groupBoxTools.Controls.Add(this.buttonRight); + this.groupBoxTools.Controls.Add(this.buttonLeft); + this.groupBoxTools.Controls.Add(this.buttonUp); + this.groupBoxTools.Controls.Add(this.buttonShowOnMap); + this.groupBoxTools.Controls.Add(this.buttonAddCar); + this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); + this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBoxTools.Location = new System.Drawing.Point(811, 0); + this.groupBoxTools.Name = "groupBoxTools"; + this.groupBoxTools.Size = new System.Drawing.Size(204, 554); + this.groupBoxTools.TabIndex = 0; + this.groupBoxTools.TabStop = false; + this.groupBoxTools.Text = "Инструменты"; + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); + this.maskedTextBoxPosition.TabIndex = 2; + this.maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonRemoveCar + // + this.buttonRemoveCar.Location = new System.Drawing.Point(17, 195); + this.buttonRemoveCar.Name = "buttonRemoveCar"; + this.buttonRemoveCar.Size = new System.Drawing.Size(175, 35); + this.buttonRemoveCar.TabIndex = 3; + this.buttonRemoveCar.Text = "Удалить автомобиль"; + this.buttonRemoveCar.UseVisualStyleBackColor = true; + this.buttonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(17, 287); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(175, 35); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::ArmoredCar.Properties.Resources.Down; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(91, 504); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + 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::ArmoredCar.Properties.Resources.Right; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(127, 504); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 9; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::ArmoredCar.Properties.Resources.Left; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(55, 504); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 8; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::ArmoredCar.Properties.Resources.Up; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(91, 468); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 7; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonAddCar + // + this.buttonAddCar.Location = new System.Drawing.Point(17, 106); + this.buttonAddCar.Name = "buttonAddCar"; + this.buttonAddCar.Size = new System.Drawing.Size(175, 35); + this.buttonAddCar.TabIndex = 1; + this.buttonAddCar.Text = "Добавить автомобиль"; + this.buttonAddCar.UseVisualStyleBackColor = true; + this.buttonAddCar.Click += new System.EventHandler(this.ButtonAddCar_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(17, 32); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23); + this.comboBoxSelectorMap.TabIndex = 0; + 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(811, 554); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // FormMapWithSetArmoredCars + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1015, 554); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.groupBoxTools); + this.Name = "FormMapWithSetArmoredCars"; + this.Text = "Карта с набором объектов"; + this.groupBoxTools.ResumeLayout(false); + this.groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxTools; + private PictureBox pictureBox; + private ComboBox comboBoxSelectorMap; + private Button buttonShowOnMap; + private Button buttonAddCar; + private Button buttonDown; + private Button buttonRight; + private Button buttonLeft; + private Button buttonUp; + private Button buttonShowStorage; + private Button buttonRemoveCar; + private MaskedTextBox maskedTextBoxPosition; + } +} \ No newline at end of file diff --git a/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs new file mode 100644 index 0000000..659b54b --- /dev/null +++ b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs @@ -0,0 +1,158 @@ +using ArmoredCar; +using System.Windows.Forms; +using System; + +namespace ArmoredCar +{ + public partial class FormMapWithSetArmoredCars : Form + { + /// + /// Объект от класса карты с набором объектов + /// + private MapWithSetArmoredCarsGeneric _mapArmoredCarsCollectionGeneric; + /// + /// Конструктор + /// + public FormMapWithSetArmoredCars() + { + InitializeComponent(); + } + /// + /// Выбор карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + case "База": + //map = new BasaMap(); + + break; + } + if (map != null) + { + _mapArmoredCarsCollectionGeneric = new MapWithSetArmoredCarsGeneric( + pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapArmoredCarsCollectionGeneric = null; + } + } + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAddCar_Click(object sender, EventArgs e) + { + if (_mapArmoredCarsCollectionGeneric == null) + { + return; + } + FormCar form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObjectArmCar car = new(form.SelectedCar); + if (_mapArmoredCarsCollectionGeneric + car) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapArmoredCarsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveCar_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 (_mapArmoredCarsCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapArmoredCarsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Вывод набора + /// + /// + /// + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapArmoredCarsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapArmoredCarsCollectionGeneric.ShowSet(); + } + /// + /// Вывод карты + /// + /// + /// + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapArmoredCarsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapArmoredCarsCollectionGeneric.ShowOnMap(); + } + /// + /// Перемещение + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapArmoredCarsCollectionGeneric == 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 = _mapArmoredCarsCollectionGeneric.MoveObject(dir); + } + } +} \ No newline at end of file diff --git a/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.resx b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.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/ArmoredCar/ArmoredCar/Program.cs b/ArmoredCar/ArmoredCar/Program.cs index d282ea3..c75d3b0 100644 --- a/ArmoredCar/ArmoredCar/Program.cs +++ b/ArmoredCar/ArmoredCar/Program.cs @@ -16,8 +16,8 @@ namespace ArmoredCar { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new FormMap()); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new FormMapWithSetArmoredCars()); } } }