From c11451d5f27e5ede8b75ed1479e853b0037a279c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Thu, 24 Nov 2022 01:50:26 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=203=20=D0=B1=D1=8D=D0=B9?= =?UTF-8?q?=D0=B7=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LocomotivesAdvanced/Direction.cs | 2 +- .../LocomotivesAdvanced/DrawningLocomotive.cs | 2 +- .../LocomotivesAdvanced/EntityLocomotive.cs | 2 +- .../FormLocomotive.Designer.cs | 52 +++-- .../LocomotivesAdvanced/FormLocomotive.cs | 14 ++ .../FormMapWithSetLocomotives.Designer.cs | 217 ++++++++++++++++++ .../FormMapWithSetLocomotives.cs | 161 +++++++++++++ .../FormMapWithSetLocomotives.resx | 60 +++++ .../IDrawningAdditionalElements.cs | 2 +- .../MapWithSetLocomotivesGeneric.cs | 180 +++++++++++++++ .../LocomotivesAdvanced/Program.cs | 2 +- .../SetLocomotivesGeneric.cs | 105 +++++++++ 12 files changed, 775 insertions(+), 24 deletions(-) create mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.Designer.cs create mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.cs create mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.resx create mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/MapWithSetLocomotivesGeneric.cs create mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/SetLocomotivesGeneric.cs diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/Direction.cs b/LocomotivesAdvanced/LocomotivesAdvanced/Direction.cs index 12f3478..95122fa 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/Direction.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/Direction.cs @@ -3,7 +3,7 @@ /// /// Перечисление направлений перемещения /// - internal enum Direction + public enum Direction { /// /// никуда diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs index d74e59a..1d9bd91 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs @@ -3,7 +3,7 @@ /// /// Класс, отвечающий за отрисовку объекта-сущности /// - internal class DrawningLocomotive + public class DrawningLocomotive { /// /// Класс-сущность diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/EntityLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/EntityLocomotive.cs index 927a9b7..4a13f9f 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/EntityLocomotive.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/EntityLocomotive.cs @@ -3,7 +3,7 @@ /// /// Класс-сущность локомотив /// - internal class EntityLocomotive + public class EntityLocomotive { /// /// Скорость diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs index 507a2cc..b97056a 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs @@ -33,6 +33,9 @@ this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel(); this.buttonCreate = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); @@ -41,9 +44,7 @@ this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown(); this.labelWheelsNumber = new System.Windows.Forms.Label(); this.buttonCreateModif = new System.Windows.Forms.Button(); - this.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonSelectLocomotive = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); this.statusStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit(); @@ -94,6 +95,24 @@ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17); this.toolStripStatusLabelBodyColor.Text = "Цвет: "; // + // toolStripStatusLabelAdditionalColor + // + this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor"; + this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17); + this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: "; + // + // toolStripStatusLabelHasPipe + // + this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe"; + this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17); + this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: "; + // + // toolStripStatusLabelHasFuelTank + // + this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank"; + this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17); + this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: "; + // // buttonCreate // this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -198,29 +217,23 @@ this.buttonCreateModif.UseVisualStyleBackColor = true; this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); // - // toolStripStatusLabelAdditionalColor + // buttonSelectLocomotive // - this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor"; - this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17); - this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: "; - // - // toolStripStatusLabelHasPipe - // - this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe"; - this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17); - this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: "; - // - // toolStripStatusLabelHasFuelTank - // - this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank"; - this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17); - this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: "; + this.buttonSelectLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonSelectLocomotive.Location = new System.Drawing.Point(461, 396); + this.buttonSelectLocomotive.Name = "buttonSelectLocomotive"; + this.buttonSelectLocomotive.Size = new System.Drawing.Size(98, 30); + this.buttonSelectLocomotive.TabIndex = 10; + this.buttonSelectLocomotive.Text = "Выбрать"; + this.buttonSelectLocomotive.UseVisualStyleBackColor = true; + this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click); // // FormLocomotive // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSelectLocomotive); this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.labelWheelsNumber); this.Controls.Add(this.numericUpDownWheelsNumber); @@ -260,5 +273,6 @@ private ToolStripStatusLabel toolStripStatusLabelAdditionalColor; private ToolStripStatusLabel toolStripStatusLabelHasPipe; private ToolStripStatusLabel toolStripStatusLabelHasFuelTank; + private Button buttonSelectLocomotive; } } \ No newline at end of file diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs index 35cfbbd..d03a63b 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs @@ -6,6 +6,10 @@ /// Объект от класса отрисовки локомотива /// private DrawningLocomotive _locomotive; + /// + /// Выбранный объект + /// + public DrawningLocomotive SelectedLocomotive { get; private set; } public FormLocomotive() { @@ -118,5 +122,15 @@ _locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value; Draw(); } + /// + /// Метод обработки нажатия на кнопку "Выбрать" + /// + /// + /// + private void ButtonSelectLocomotive_Click(object sender, EventArgs e) + { + SelectedLocomotive = _locomotive; + DialogResult = DialogResult.OK; + } } } diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.Designer.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.Designer.cs new file mode 100644 index 0000000..6ddfa44 --- /dev/null +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.Designer.cs @@ -0,0 +1,217 @@ +namespace WarmlyLocomotove +{ + partial class FormMapWithSetLocomotives + { + /// + /// 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.buttonUp = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveLocomotive = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonAddCar = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBoxLocomotives = new System.Windows.Forms.PictureBox(); + this.groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotives)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxTools + // + this.groupBoxTools.Controls.Add(this.buttonUp); + this.groupBoxTools.Controls.Add(this.buttonDown); + this.groupBoxTools.Controls.Add(this.buttonLeft); + this.groupBoxTools.Controls.Add(this.buttonRight); + this.groupBoxTools.Controls.Add(this.buttonShowOnMap); + this.groupBoxTools.Controls.Add(this.buttonShowStorage); + this.groupBoxTools.Controls.Add(this.buttonRemoveLocomotive); + this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); + 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(577, 0); + this.groupBoxTools.Name = "groupBoxTools"; + this.groupBoxTools.Size = new System.Drawing.Size(223, 450); + this.groupBoxTools.TabIndex = 0; + this.groupBoxTools.TabStop = false; + this.groupBoxTools.Text = "Инструменты"; + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(107, 378); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 10; + 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::WarmlyLocomotive.Properties.Resources.ArrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(107, 414); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 9; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(71, 414); + 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); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(143, 414); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 7; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(31, 314); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(164, 26); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(31, 217); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(164, 26); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // buttonRemoveLocomotive + // + this.buttonRemoveLocomotive.Location = new System.Drawing.Point(31, 156); + this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive"; + this.buttonRemoveLocomotive.Size = new System.Drawing.Size(164, 26); + this.buttonRemoveLocomotive.TabIndex = 3; + this.buttonRemoveLocomotive.Text = "Удалить локомотив"; + this.buttonRemoveLocomotive.UseVisualStyleBackColor = true; + this.buttonRemoveLocomotive.Click += new System.EventHandler(this.ButtonRemoveLocomotive_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(31, 127); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(164, 23); + this.maskedTextBoxPosition.TabIndex = 2; + // + // buttonAddCar + // + this.buttonAddCar.Location = new System.Drawing.Point(31, 72); + this.buttonAddCar.Name = "buttonAddCar"; + this.buttonAddCar.Size = new System.Drawing.Size(164, 26); + this.buttonAddCar.TabIndex = 1; + this.buttonAddCar.Text = "Добавить локомотив"; + this.buttonAddCar.UseVisualStyleBackColor = true; + this.buttonAddCar.Click += new System.EventHandler(this.ButtonAddLocomotive_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(31, 22); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(164, 23); + this.comboBoxSelectorMap.TabIndex = 0; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + // + // pictureBoxLocomotives + // + this.pictureBoxLocomotives.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxLocomotives.Location = new System.Drawing.Point(0, 0); + this.pictureBoxLocomotives.Name = "pictureBoxLocomotives"; + this.pictureBoxLocomotives.Size = new System.Drawing.Size(577, 450); + this.pictureBoxLocomotives.TabIndex = 1; + this.pictureBoxLocomotives.TabStop = false; + // + // FormMapWithSetLocomotives + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.pictureBoxLocomotives); + this.Controls.Add(this.groupBoxTools); + this.Name = "FormMapWithSetLocomotives"; + this.Text = "Карта с набором объектов"; + this.groupBoxTools.ResumeLayout(false); + this.groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotives)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxTools; + private PictureBox pictureBoxLocomotives; + private ComboBox comboBoxSelectorMap; + private Button buttonAddCar; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonRemoveLocomotive; + private Button buttonShowStorage; + private Button buttonShowOnMap; + private Button buttonUp; + private Button buttonDown; + private Button buttonLeft; + private Button buttonRight; + } +} \ No newline at end of file diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.cs new file mode 100644 index 0000000..3409b66 --- /dev/null +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.cs @@ -0,0 +1,161 @@ +namespace WarmlyLocomotove +{ + /// + /// Форма для работы с набором объектов + /// + public partial class FormMapWithSetLocomotives : Form + { + /// + /// Объект от класса карты с набором объектов + /// + private MapWithSetLocomotivesGeneric _mapCarsCollectionGeneric; + /// + /// Конструктор + /// + public FormMapWithSetLocomotives() + { + InitializeComponent(); + } + /// + /// Выбор карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + case "Карта с крестом": + map = new CrossMap(); + break; + case "Карта с дорожками": + map = new RoadsMap(); + break; + default: + break; + } + if (map != null) + { + _mapCarsCollectionGeneric = new + MapWithSetLocomotivesGeneric(pictureBoxLocomotives.Width, pictureBoxLocomotives.Height, map); + } + else + { + _mapCarsCollectionGeneric = null; + } + } + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAddLocomotive_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == null) + { + return; + } + FormLocomotive form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive); + if ((_mapCarsCollectionGeneric + locomotive) > -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveLocomotive_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if ((_mapCarsCollectionGeneric - pos) > -1) + { + MessageBox.Show("Объект удален"); + pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Вывод набора + /// + /// + /// + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == null) + { + return; + } + pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet(); + } + /// + /// Вывод карты + /// + /// + /// + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == null) + { + return; + } + pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowOnMap(); + } + /// + /// Перемещение + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == null) + { + return; + } + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "buttonUp": + dir = Direction.Up; + break; + case "buttonDown": + dir = Direction.Down; + break; + case "buttonLeft": + dir = Direction.Left; + break; + case "buttonRight": + dir = Direction.Right; + break; + } + pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.resx b/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.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/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningAdditionalElements.cs b/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningAdditionalElements.cs index c9cef98..968e2f7 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningAdditionalElements.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningAdditionalElements.cs @@ -3,7 +3,7 @@ /// /// Интерфейс для прорисовки элементов усложнения /// - internal interface IDrawningAdditionalElements + public interface IDrawningAdditionalElements { /// /// Свойство получения количества колёс diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/MapWithSetLocomotivesGeneric.cs b/LocomotivesAdvanced/LocomotivesAdvanced/MapWithSetLocomotivesGeneric.cs new file mode 100644 index 0000000..7623fe8 --- /dev/null +++ b/LocomotivesAdvanced/LocomotivesAdvanced/MapWithSetLocomotivesGeneric.cs @@ -0,0 +1,180 @@ +namespace WarmlyLocomotove +{ + internal class MapWithSetLocomotivesGeneric + where T : class, IDrawningObject + where U : AbstractMap + { + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 210; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 110; + /// + /// Набор объектов + /// + private readonly SetLocomotivesGeneric _setLocomotives; + /// + /// Карта + /// + private readonly U _map; + /// + /// Конструктор + /// + /// + /// + /// + public MapWithSetLocomotivesGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setLocomotives = new SetLocomotivesGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static int operator +(MapWithSetLocomotivesGeneric map, T locomotive) + { + return map._setLocomotives.Insert(locomotive); + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static int operator -(MapWithSetLocomotivesGeneric map, int position) + { + return map._setLocomotives.Remove(position); + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawLocomotives(gr); + return bmp; + } + /// + /// Просмотр объекта на карте + /// + /// + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setLocomotives.Count; i++) + { + var locomotive = _setLocomotives.Get(i); + if (locomotive != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive); + } + } + 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 = _setLocomotives.Count - 1; + for (int i = 0; i < _setLocomotives.Count; i++) + { + if (_setLocomotives.Get(i) == null) + { + for (; j > i; j--) + { + var locomotive = _setLocomotives.Get(j); + if (locomotive != null) + { + _setLocomotives.Insert(locomotive, i); + _setLocomotives.Remove(j); + break; + } + } + if (j <= i) + { + return; + } + } + } + } + /// + /// Метод отрисовки фона + /// + /// + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Brown, 3); + Brush brBackground = new SolidBrush(Color.Yellow); + g.FillRectangle(brBackground, 0, 0, _pictureWidth, _pictureHeight); + 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 DrawLocomotives(Graphics g) + { + int LocomotivesInLine = _pictureWidth / _placeSizeWidth; + int CurrentVertPos = 20; + int CurrentHorPos = 0; + for (int i = 0; i < _setLocomotives.Count; i++) + { + _setLocomotives.Get(i)?.SetObject(CurrentHorPos, CurrentVertPos, _pictureWidth, _pictureHeight); + _setLocomotives.Get(i)?.DrawningObject(g); + if (CurrentHorPos < LocomotivesInLine) + { + CurrentHorPos += _placeSizeWidth; + } + else + { + CurrentHorPos = 0; + CurrentVertPos += _placeSizeHeight; + } + } + } + } +} diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs b/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs index 49fcafd..5159350 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs @@ -8,7 +8,7 @@ namespace WarmlyLocomotove // 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 FormMapWithSetLocomotives()); } } } \ No newline at end of file diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/SetLocomotivesGeneric.cs b/LocomotivesAdvanced/LocomotivesAdvanced/SetLocomotivesGeneric.cs new file mode 100644 index 0000000..8292d60 --- /dev/null +++ b/LocomotivesAdvanced/LocomotivesAdvanced/SetLocomotivesGeneric.cs @@ -0,0 +1,105 @@ +namespace WarmlyLocomotove +{ + internal class SetLocomotivesGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetLocomotivesGeneric(int count) + { + _places = new T[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый локомотив + /// + public int Insert(T locomotive) + { + T testLocomotive = _places[0]; + for (int i = 0; i < Count; i++) + { + if (_places[i] == null) + { + testLocomotive = _places[i]; + } + } + if (testLocomotive != null) + { + return -1; + } + for (int i = Count - 2; i >= 0; i--) + { + _places[i + 1] = _places[i]; + } + _places[0] = locomotive; + return 0; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый локомотив + /// Позиция + /// + public int Insert(T locomotive, int position) + { + if (position < 0 || position >= Count) + { + return position; + } + int ClosestNullElementIndex = position; + while (_places[ClosestNullElementIndex] != null) + { + if (ClosestNullElementIndex == Count) + { + return position; + } + ClosestNullElementIndex++; + } + while (ClosestNullElementIndex != position) + { + _places[ClosestNullElementIndex] = _places[ClosestNullElementIndex - 1]; + ClosestNullElementIndex--; + } + _places[position] = locomotive; + return position; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public int Remove(int position) + { + if (_places[position] == null) + { + return -1; + } + _places[position] = null; + return position; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T Get(int position) + { + if (_places[position] != null) + { + return _places[position]; + } + return null; + } + } +} -- 2.25.1 From e198915d98b789d74f04d7425e55180984d4b043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Thu, 24 Nov 2022 15:17:30 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D1=85=D0=B0=D1=80=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdvancedObjectGeneric.cs | 55 +++ .../LocomotivesAdvanced/DrawningLocomotive.cs | 2 +- ...omotive - Копировать.Designer.cs | 317 ++++++++++++++++++ .../FormLocomotive - Копировать.cs | 194 +++++++++++ ...FormLocomotive - Копировать.resx | 63 ++++ .../FormLocomotive.Designer.cs | 4 +- .../LocomotivesAdvanced/FormLocomotive.cs | 5 + .../LocomotivesAdvanced/Program.cs | 2 +- .../WarmlyLocomotive.csproj | 3 + 9 files changed, 641 insertions(+), 4 deletions(-) create mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/AdvancedObjectGeneric.cs create mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.Designer.cs create mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.cs create mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.resx diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/AdvancedObjectGeneric.cs b/LocomotivesAdvanced/LocomotivesAdvanced/AdvancedObjectGeneric.cs new file mode 100644 index 0000000..369d541 --- /dev/null +++ b/LocomotivesAdvanced/LocomotivesAdvanced/AdvancedObjectGeneric.cs @@ -0,0 +1,55 @@ +namespace WarmlyLocomotove +{ + internal class AdvancedObjectGeneric + where T : EntityLocomotive + where U : class, IDrawningAdditionalElements + { + T[] Entities = new T[10]; + public int CurrentEntityIndex = 0; + public U[] AdditionalElementsSetups = new U[10]; + public int CurrentAdditionalElementSetupIndex = 0; + public void AddEntity(T NewEntity) + { + if (CurrentEntityIndex >= 9) + { + return; + } + Entities[CurrentEntityIndex] = NewEntity; + CurrentEntityIndex++; + } + public void AddAdditionalElementSetup(U NewAdditionalElementSetup) + { + if (CurrentAdditionalElementSetupIndex >= 9) + { + return; + } + AdditionalElementsSetups[CurrentAdditionalElementSetupIndex] = NewAdditionalElementSetup; + CurrentAdditionalElementSetupIndex++; + } + public DrawningLocomotive GeneratedObject() + { + Random rnd = new(); + int SelectedEntityIndex = rnd.Next(0, 9); + int SelectedAdditionalElementSetupIndex = rnd.Next(0, 9); + DrawningLocomotive Object; + if (Entities[SelectedEntityIndex] is EntityLocomotive) + { + Object = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + Object.Locomotive = Entities[SelectedEntityIndex]; + Object.AdditionalElements = AdditionalElementsSetups[SelectedAdditionalElementSetupIndex]; + } + else + { + Object = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + 160, 115, + 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))); + Object.Locomotive = Entities[SelectedEntityIndex]; + Object.AdditionalElements = AdditionalElementsSetups[SelectedAdditionalElementSetupIndex]; + } + return Object; + } + } +} diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs index 1d9bd91..51e9e60 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs @@ -8,7 +8,7 @@ /// /// Класс-сущность /// - public EntityLocomotive Locomotive { get; protected set; } + public EntityLocomotive Locomotive { get; set; } /// /// Класс отрисовки колёс /// diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.Designer.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.Designer.cs new file mode 100644 index 0000000..55c3db6 --- /dev/null +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.Designer.cs @@ -0,0 +1,317 @@ +namespace WarmlyLocomotove +{ + partial class FormLocomotiveAdditional + { + /// + /// 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.pictureBoxLocomotive = 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.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown(); + this.labelWheelsNumber = new System.Windows.Forms.Label(); + this.buttonCreateModif = new System.Windows.Forms.Button(); + this.buttonSelectLocomotive = new System.Windows.Forms.Button(); + this.buttonGenerateEntities = new System.Windows.Forms.Button(); + this.buttonGenerateAdditionalElementsSetup = new System.Windows.Forms.Button(); + this.buttonShowGeneratedObject = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); + this.statusStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit(); + this.SuspendLayout(); + // + // pictureBoxLocomotive + // + this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0); + this.pictureBoxLocomotive.MinimumSize = new System.Drawing.Size(1, 1); + this.pictureBoxLocomotive.Name = "pictureBoxLocomotive"; + this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 450); + this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxLocomotive.TabIndex = 0; + this.pictureBoxLocomotive.TabStop = false; + this.pictureBoxLocomotive.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize); + // + // statusStrip + // + this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor, + this.toolStripStatusLabelAdditionalColor, + this.toolStripStatusLabelHasPipe, + this.toolStripStatusLabelHasFuelTank}); + this.statusStrip.Location = new System.Drawing.Point(0, 428); + this.statusStrip.Name = "statusStrip"; + this.statusStrip.Size = new System.Drawing.Size(800, 22); + this.statusStrip.TabIndex = 1; + this.statusStrip.Text = "statusStrip1"; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17); + this.toolStripStatusLabelSpeed.Text = "Скорость: "; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17); + this.toolStripStatusLabelWeight.Text = "Вес: "; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17); + this.toolStripStatusLabelBodyColor.Text = "Цвет: "; + // + // toolStripStatusLabelAdditionalColor + // + this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor"; + this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17); + this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: "; + // + // toolStripStatusLabelHasPipe + // + this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe"; + this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17); + this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: "; + // + // toolStripStatusLabelHasFuelTank + // + this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank"; + this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17); + this.toolStripStatusLabelHasFuelTank.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, 395); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(90, 30); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(758, 395); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 3; + 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::WarmlyLocomotive.Properties.Resources.ArrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(686, 395); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 4; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.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::WarmlyLocomotive.Properties.Resources.ArrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(722, 395); + 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); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(722, 359); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 6; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // numericUpDownWheelsNumber + // + this.numericUpDownWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownWheelsNumber.Location = new System.Drawing.Point(651, 402); + this.numericUpDownWheelsNumber.Maximum = new decimal(new int[] { + 4, + 0, + 0, + 0}); + this.numericUpDownWheelsNumber.Minimum = new decimal(new int[] { + 2, + 0, + 0, + 0}); + this.numericUpDownWheelsNumber.Name = "numericUpDownWheelsNumber"; + this.numericUpDownWheelsNumber.ReadOnly = true; + this.numericUpDownWheelsNumber.Size = new System.Drawing.Size(29, 23); + this.numericUpDownWheelsNumber.TabIndex = 7; + this.numericUpDownWheelsNumber.Value = new decimal(new int[] { + 2, + 0, + 0, + 0}); + // + // labelWheelsNumber + // + this.labelWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.labelWheelsNumber.AutoSize = true; + this.labelWheelsNumber.Location = new System.Drawing.Point(565, 404); + this.labelWheelsNumber.Name = "labelWheelsNumber"; + this.labelWheelsNumber.Size = new System.Drawing.Size(80, 15); + this.labelWheelsNumber.TabIndex = 8; + this.labelWheelsNumber.Text = "Число колёс:"; + // + // 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(108, 395); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(98, 30); + this.buttonCreateModif.TabIndex = 9; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // + // buttonSelectLocomotive + // + this.buttonSelectLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonSelectLocomotive.Location = new System.Drawing.Point(461, 396); + this.buttonSelectLocomotive.Name = "buttonSelectLocomotive"; + this.buttonSelectLocomotive.Size = new System.Drawing.Size(98, 30); + this.buttonSelectLocomotive.TabIndex = 10; + this.buttonSelectLocomotive.Text = "Выбрать"; + this.buttonSelectLocomotive.UseVisualStyleBackColor = true; + this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click); + // + // buttonGenerateEntities + // + this.buttonGenerateEntities.Location = new System.Drawing.Point(12, 294); + this.buttonGenerateEntities.Name = "buttonGenerateEntities"; + this.buttonGenerateEntities.Size = new System.Drawing.Size(90, 32); + this.buttonGenerateEntities.TabIndex = 11; + this.buttonGenerateEntities.Text = "button1"; + this.buttonGenerateEntities.UseVisualStyleBackColor = true; + this.buttonGenerateEntities.Click += new System.EventHandler(this.ButtonGenerateEntities_Click_1); + // + // buttonGenerateAdditionalElementsSetup + // + this.buttonGenerateAdditionalElementsSetup.Location = new System.Drawing.Point(188, 294); + this.buttonGenerateAdditionalElementsSetup.Name = "buttonGenerateAdditionalElementsSetup"; + this.buttonGenerateAdditionalElementsSetup.Size = new System.Drawing.Size(90, 32); + this.buttonGenerateAdditionalElementsSetup.TabIndex = 12; + this.buttonGenerateAdditionalElementsSetup.Text = "button1"; + this.buttonGenerateAdditionalElementsSetup.UseVisualStyleBackColor = true; + this.buttonGenerateAdditionalElementsSetup.Click += new System.EventHandler(this.ButtonGenerateAdditionalElementsSetup_Click); + // + // buttonShowGeneratedObject + // + this.buttonShowGeneratedObject.Location = new System.Drawing.Point(98, 216); + this.buttonShowGeneratedObject.Name = "buttonShowGeneratedObject"; + this.buttonShowGeneratedObject.Size = new System.Drawing.Size(90, 32); + this.buttonShowGeneratedObject.TabIndex = 13; + this.buttonShowGeneratedObject.Text = "button1"; + this.buttonShowGeneratedObject.UseVisualStyleBackColor = true; + this.buttonShowGeneratedObject.Click += new System.EventHandler(this.ButtonShowGeneratedObject_Click); + // + // FormLocomotiveAdditional + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonShowGeneratedObject); + this.Controls.Add(this.buttonGenerateAdditionalElementsSetup); + this.Controls.Add(this.buttonGenerateEntities); + this.Controls.Add(this.buttonSelectLocomotive); + this.Controls.Add(this.buttonCreateModif); + this.Controls.Add(this.labelWheelsNumber); + this.Controls.Add(this.numericUpDownWheelsNumber); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.statusStrip); + this.Controls.Add(this.pictureBoxLocomotive); + this.Name = "FormLocomotiveAdditional"; + this.Text = "Локомотив"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); + this.statusStrip.ResumeLayout(false); + this.statusStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxLocomotive; + private StatusStrip statusStrip; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private Button buttonCreate; + private Button buttonRight; + private Button buttonLeft; + private Button buttonDown; + private Button buttonUp; + private NumericUpDown numericUpDownWheelsNumber; + private Label labelWheelsNumber; + private Button buttonCreateModif; + private ToolStripStatusLabel toolStripStatusLabelAdditionalColor; + private ToolStripStatusLabel toolStripStatusLabelHasPipe; + private ToolStripStatusLabel toolStripStatusLabelHasFuelTank; + private Button buttonSelectLocomotive; + private Button buttonGenerateEntities; + private Button buttonGenerateAdditionalElementsSetup; + private Button buttonShowGeneratedObject; + } +} \ No newline at end of file diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.cs new file mode 100644 index 0000000..7c1e40a --- /dev/null +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.cs @@ -0,0 +1,194 @@ +namespace WarmlyLocomotove +{ + public partial class FormLocomotiveAdditional : Form + { + /// + /// Объект от класса отрисовки локомотива + /// + private DrawningLocomotive _locomotive; + /// + /// Выбранный объект + /// + public DrawningLocomotive SelectedLocomotive { get; private set; } + + private AdvancedObjectGeneric AdvancedObject = new AdvancedObjectGeneric(); + + public FormLocomotiveAdditional() + { + InitializeComponent(); + } + /// + /// Метод отрисовки локомотива + /// + private void Draw() + { + Bitmap bmp = new(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); + Graphics gr = Graphics.FromImage(bmp); + _locomotive?.DrawTransport(gr); + pictureBoxLocomotive.Image = bmp; + } + /// + /// Заполнение информации по объекту + /// + /// Объект от класса отрисовки или его наследника + private void SetData(DrawningLocomotive locomotive) + { + Random rnd = new(); + toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}"; + toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: н/д"; + toolStripStatusLabelHasPipe.Text = $"Наличие трубы: н/д"; + toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: н/д"; + _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); + } + /// + /// Заполнение дополнительной информации по объекту (только для усложнённого объекта) + /// + /// Объект от наследника класса отрисовки + private void SetAdditionalData(DrawningWarmlyLocomotive warmlylocomotive) + { + if (warmlylocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive) + { + toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: {entityWarmlyLocomotive.AdditionalColor.Name}"; + toolStripStatusLabelHasPipe.Text = $"Наличие трубы: {entityWarmlyLocomotive.HasPipe}"; + toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: {entityWarmlyLocomotive.HasFuelTank}"; + } + } + /// + /// Метод обработки нажатия на кнопку "Создать" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + _locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); + SetData(_locomotive); + _locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value; + Draw(); + } + /// + /// Метод обработки нажатия на кнопки перемещения + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _locomotive?.MoveLocomotive(Direction.Up); + break; + case "buttonDown": + _locomotive?.MoveLocomotive(Direction.Down); + break; + case "buttonLeft": + _locomotive?.MoveLocomotive(Direction.Left); + break; + case "buttonRight": + _locomotive?.MoveLocomotive(Direction.Right); + break; + } + Draw(); + } + /// + /// Изменение размеров формы + /// + /// + /// + private void PictureBoxLocomotive_Resize(object sender, EventArgs e) + { + _locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); + Draw(); + } + /// + /// Метод обработки нажатия на кнопку "Модификация" + /// + /// + /// + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + 160, 115, + 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(_locomotive); + SetAdditionalData((DrawningWarmlyLocomotive)_locomotive); + _locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value; + Draw(); + } + /// + /// Метод обработки нажатия на кнопку "Выбрать" + /// + /// + /// + private void ButtonSelectLocomotive_Click(object sender, EventArgs e) + { + SelectedLocomotive = _locomotive; + DialogResult = DialogResult.OK; + } + + private void ButtonGenerateEntities_Click_1(object sender, EventArgs e) + { + Random rnd = new(); + AdvancedObject.CurrentEntityIndex = 0; + for (int i = 0; i < 10; i++) + { + bool IsAdvancedEntity = Convert.ToBoolean(rnd.Next(0, 2)); + EntityLocomotive Entity; + if (!IsAdvancedEntity) + { + Entity = new EntityLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + } + else + { + Entity = new EntityWarmlyLocomotive(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))); + } + AdvancedObject.AddEntity(Entity); + } + } + + private void ButtonGenerateAdditionalElementsSetup_Click(object sender, EventArgs e) + { + Random rnd = new(); + for (int i = 0; i < 10; i++) + { + int AdditionalElementSetupType = rnd.Next(0, 2); + switch (AdditionalElementSetupType) + { + case 0: + AdvancedObject.AddAdditionalElementSetup(new DrawningWheels()); + break; + case 1: + AdvancedObject.AddAdditionalElementSetup(new DrawningRectOrnament()); + break; + case 2: + AdvancedObject.AddAdditionalElementSetup(new DrawningEllipseOrnament()); + break; + } + } + } + + private void ButtonShowGeneratedObject_Click(object sender, EventArgs e) + { + Random rnd = new(); + _locomotive = AdvancedObject.GeneratedObject(); + _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); + SetData(_locomotive); + _locomotive.AdditionalElements.WheelsNum = 2; + _locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value; + Draw(); + } + } +} diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.resx b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.resx new file mode 100644 index 0000000..2c0949d --- /dev/null +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs index b97056a..291e339 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs @@ -228,7 +228,7 @@ this.buttonSelectLocomotive.UseVisualStyleBackColor = true; this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click); // - // FormLocomotive + // FormLocomotiveAdditional // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -244,7 +244,7 @@ this.Controls.Add(this.buttonCreate); this.Controls.Add(this.statusStrip); this.Controls.Add(this.pictureBoxLocomotive); - this.Name = "FormLocomotive"; + this.Name = "FormLocomotiveAdditional"; this.Text = "Локомотив"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); this.statusStrip.ResumeLayout(false); diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs index d03a63b..2162005 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs @@ -132,5 +132,10 @@ SelectedLocomotive = _locomotive; DialogResult = DialogResult.OK; } + + private void buttonGenerateEntities_Click(object sender, EventArgs e) + { + + } } } diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs b/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs index 5159350..74da26b 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs @@ -8,7 +8,7 @@ namespace WarmlyLocomotove // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetLocomotives()); + Application.Run(new FormLocomotiveAdditional()); } } } \ No newline at end of file diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/WarmlyLocomotive.csproj b/LocomotivesAdvanced/LocomotivesAdvanced/WarmlyLocomotive.csproj index ce86fc6..72f3413 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/WarmlyLocomotive.csproj +++ b/LocomotivesAdvanced/LocomotivesAdvanced/WarmlyLocomotive.csproj @@ -9,6 +9,9 @@ + + Form + True True -- 2.25.1 From 19a298716dbe13dd62dc626fc96158d9f3419336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Thu, 24 Nov 2022 18:25:49 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BA=D0=BE=D0=B4=D0=B0,=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D0=B5=D0=B2,=20?= =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=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 --- .../AdvancedObjectGeneric.cs | 53 ++- ...FormLocomotive - Копировать.resx | 63 ---- .../FormLocomotive.Designer.cs | 134 +++---- ...s => FormLocomotiveAdditional.Designer.cs} | 143 +------- ...ать.cs => FormLocomotiveAdditional.cs} | 95 +---- ...Map.resx => FormLocomotiveAdditional.resx} | 3 - .../LocomotivesAdvanced/FormMap.Designer.cs | 327 ------------------ .../LocomotivesAdvanced/FormMap.cs | 151 -------- .../FormMapWithSetLocomotives.cs | 2 +- .../MapWithSetLocomotivesGeneric.cs | 4 +- .../SetLocomotivesGeneric.cs | 37 +- .../WarmlyLocomotive.csproj | 2 +- 12 files changed, 148 insertions(+), 866 deletions(-) delete mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.resx rename LocomotivesAdvanced/LocomotivesAdvanced/{FormLocomotive - Копировать.Designer.cs => FormLocomotiveAdditional.Designer.cs} (59%) rename LocomotivesAdvanced/LocomotivesAdvanced/{FormLocomotive - Копировать.cs => FormLocomotiveAdditional.cs} (57%) rename LocomotivesAdvanced/LocomotivesAdvanced/{FormMap.resx => FormLocomotiveAdditional.resx} (93%) delete mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/FormMap.Designer.cs delete mode 100644 LocomotivesAdvanced/LocomotivesAdvanced/FormMap.cs diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/AdvancedObjectGeneric.cs b/LocomotivesAdvanced/LocomotivesAdvanced/AdvancedObjectGeneric.cs index 369d541..5e1d16b 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/AdvancedObjectGeneric.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/AdvancedObjectGeneric.cs @@ -1,13 +1,34 @@ namespace WarmlyLocomotove { + /// + /// Параметризованный класс с параметрами типа сущности и интерфейса отрисовки дополнительных частей + /// + /// + /// internal class AdvancedObjectGeneric where T : EntityLocomotive where U : class, IDrawningAdditionalElements { - T[] Entities = new T[10]; - public int CurrentEntityIndex = 0; - public U[] AdditionalElementsSetups = new U[10]; - public int CurrentAdditionalElementSetupIndex = 0; + /// + /// Массив сущностей + /// + private T[] Entities = new T[10]; + /// + /// Текущая выбранная сущность(индекс для заполнения) + /// + private int CurrentEntityIndex = 0; + /// + /// Массив конфигураций(набора параметров для доп. отрисовки) + /// + private U[] AdditionalElementsSetups = new U[10]; + /// + /// Текущая выбранная конфигурация + /// + int CurrentAdditionalElementSetupIndex = 0; + /// + /// Добавление новой сущности в массив сущностей + /// + /// Добавляемая сущность public void AddEntity(T NewEntity) { if (CurrentEntityIndex >= 9) @@ -17,6 +38,10 @@ Entities[CurrentEntityIndex] = NewEntity; CurrentEntityIndex++; } + /// + /// Добавление новой конфигурации в массив конфигураций + /// + /// Добавляемая конфигурация public void AddAdditionalElementSetup(U NewAdditionalElementSetup) { if (CurrentAdditionalElementSetupIndex >= 9) @@ -26,26 +51,24 @@ AdditionalElementsSetups[CurrentAdditionalElementSetupIndex] = NewAdditionalElementSetup; CurrentAdditionalElementSetupIndex++; } + /// + /// Генерация нового объекта от класса отрисовки на основе случайно выбранной сущности и набора конфигураций + /// + /// public DrawningLocomotive GeneratedObject() { Random rnd = new(); int SelectedEntityIndex = rnd.Next(0, 9); int SelectedAdditionalElementSetupIndex = rnd.Next(0, 9); - DrawningLocomotive Object; - if (Entities[SelectedEntityIndex] is EntityLocomotive) + DrawningLocomotive Object = null; + if (Entities[SelectedEntityIndex] is EntityWarmlyLocomotive entitywarmlylocomotive) { - Object = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - Object.Locomotive = Entities[SelectedEntityIndex]; + Object = new DrawningWarmlyLocomotive(entitywarmlylocomotive.Speed, entitywarmlylocomotive.Weight, entitywarmlylocomotive.BodyColor, 160, 115, entitywarmlylocomotive.AdditionalColor, entitywarmlylocomotive.HasPipe, entitywarmlylocomotive.HasFuelTank); Object.AdditionalElements = AdditionalElementsSetups[SelectedAdditionalElementSetupIndex]; } - else + else if (Entities[SelectedEntityIndex] is EntityLocomotive entitylocomotive) { - Object = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - 160, 115, - 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))); + Object = new DrawningLocomotive(entitylocomotive.Speed, entitylocomotive.Weight, entitylocomotive.BodyColor); Object.Locomotive = Entities[SelectedEntityIndex]; Object.AdditionalElements = AdditionalElementsSetups[SelectedAdditionalElementSetupIndex]; } diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.resx b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.resx deleted file mode 100644 index 2c0949d..0000000 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.resx +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - 17, 17 - - \ No newline at end of file diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs index 291e339..a1974a1 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs @@ -29,13 +29,6 @@ private void InitializeComponent() { this.pictureBoxLocomotive = 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.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel(); this.buttonCreate = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); @@ -45,9 +38,16 @@ this.labelWheelsNumber = new System.Windows.Forms.Label(); this.buttonCreateModif = new System.Windows.Forms.Button(); this.buttonSelectLocomotive = new System.Windows.Forms.Button(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel(); + this.statusStrip = new System.Windows.Forms.StatusStrip(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); - this.statusStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit(); + this.statusStrip.SuspendLayout(); this.SuspendLayout(); // // pictureBoxLocomotive @@ -62,57 +62,6 @@ this.pictureBoxLocomotive.TabStop = false; this.pictureBoxLocomotive.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize); // - // statusStrip - // - this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelBodyColor, - this.toolStripStatusLabelAdditionalColor, - this.toolStripStatusLabelHasPipe, - this.toolStripStatusLabelHasFuelTank}); - this.statusStrip.Location = new System.Drawing.Point(0, 428); - this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(800, 22); - this.statusStrip.TabIndex = 1; - this.statusStrip.Text = "statusStrip1"; - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17); - this.toolStripStatusLabelSpeed.Text = "Скорость: "; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17); - this.toolStripStatusLabelWeight.Text = "Вес: "; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17); - this.toolStripStatusLabelBodyColor.Text = "Цвет: "; - // - // toolStripStatusLabelAdditionalColor - // - this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor"; - this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17); - this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: "; - // - // toolStripStatusLabelHasPipe - // - this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe"; - this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17); - this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: "; - // - // toolStripStatusLabelHasFuelTank - // - this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank"; - this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17); - this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: "; - // // buttonCreate // this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -228,7 +177,58 @@ this.buttonSelectLocomotive.UseVisualStyleBackColor = true; this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click); // - // FormLocomotiveAdditional + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17); + this.toolStripStatusLabelSpeed.Text = "Скорость: "; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17); + this.toolStripStatusLabelWeight.Text = "Вес: "; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17); + this.toolStripStatusLabelBodyColor.Text = "Цвет: "; + // + // toolStripStatusLabelAdditionalColor + // + this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor"; + this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17); + this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: "; + // + // toolStripStatusLabelHasPipe + // + this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe"; + this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17); + this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: "; + // + // toolStripStatusLabelHasFuelTank + // + this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank"; + this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17); + this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: "; + // + // statusStrip + // + this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor, + this.toolStripStatusLabelAdditionalColor, + this.toolStripStatusLabelHasPipe, + this.toolStripStatusLabelHasFuelTank}); + this.statusStrip.Location = new System.Drawing.Point(0, 428); + this.statusStrip.Name = "statusStrip"; + this.statusStrip.Size = new System.Drawing.Size(800, 22); + this.statusStrip.TabIndex = 1; + this.statusStrip.Text = "statusStrip1"; + // + // FormLocomotive // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -244,12 +244,12 @@ this.Controls.Add(this.buttonCreate); this.Controls.Add(this.statusStrip); this.Controls.Add(this.pictureBoxLocomotive); - this.Name = "FormLocomotiveAdditional"; + this.Name = "FormLocomotive"; this.Text = "Локомотив"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit(); this.statusStrip.ResumeLayout(false); this.statusStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -258,10 +258,6 @@ #endregion private PictureBox pictureBoxLocomotive; - private StatusStrip statusStrip; - private ToolStripStatusLabel toolStripStatusLabelSpeed; - private ToolStripStatusLabel toolStripStatusLabelWeight; - private ToolStripStatusLabel toolStripStatusLabelBodyColor; private Button buttonCreate; private Button buttonRight; private Button buttonLeft; @@ -270,9 +266,13 @@ private NumericUpDown numericUpDownWheelsNumber; private Label labelWheelsNumber; private Button buttonCreateModif; + private Button buttonSelectLocomotive; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; private ToolStripStatusLabel toolStripStatusLabelAdditionalColor; private ToolStripStatusLabel toolStripStatusLabelHasPipe; private ToolStripStatusLabel toolStripStatusLabelHasFuelTank; - private Button buttonSelectLocomotive; + private StatusStrip statusStrip; } } \ No newline at end of file diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.Designer.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotiveAdditional.Designer.cs similarity index 59% rename from LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.Designer.cs rename to LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotiveAdditional.Designer.cs index 55c3db6..3589525 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.Designer.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotiveAdditional.Designer.cs @@ -29,27 +29,16 @@ private void InitializeComponent() { this.pictureBoxLocomotive = 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.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel(); - this.buttonCreate = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown(); this.labelWheelsNumber = new System.Windows.Forms.Label(); - this.buttonCreateModif = new System.Windows.Forms.Button(); - this.buttonSelectLocomotive = new System.Windows.Forms.Button(); this.buttonGenerateEntities = new System.Windows.Forms.Button(); this.buttonGenerateAdditionalElementsSetup = new System.Windows.Forms.Button(); this.buttonShowGeneratedObject = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); - this.statusStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit(); this.SuspendLayout(); // @@ -65,74 +54,12 @@ this.pictureBoxLocomotive.TabStop = false; this.pictureBoxLocomotive.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize); // - // statusStrip - // - this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelBodyColor, - this.toolStripStatusLabelAdditionalColor, - this.toolStripStatusLabelHasPipe, - this.toolStripStatusLabelHasFuelTank}); - this.statusStrip.Location = new System.Drawing.Point(0, 428); - this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(800, 22); - this.statusStrip.TabIndex = 1; - this.statusStrip.Text = "statusStrip1"; - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17); - this.toolStripStatusLabelSpeed.Text = "Скорость: "; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17); - this.toolStripStatusLabelWeight.Text = "Вес: "; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17); - this.toolStripStatusLabelBodyColor.Text = "Цвет: "; - // - // toolStripStatusLabelAdditionalColor - // - this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor"; - this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17); - this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: "; - // - // toolStripStatusLabelHasPipe - // - this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe"; - this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17); - this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: "; - // - // toolStripStatusLabelHasFuelTank - // - this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank"; - this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17); - this.toolStripStatusLabelHasFuelTank.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, 395); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(90, 30); - this.buttonCreate.TabIndex = 2; - this.buttonCreate.Text = "Создать"; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); - // // buttonRight // this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(758, 395); + this.buttonRight.Location = new System.Drawing.Point(761, 406); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 3; @@ -144,7 +71,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(686, 395); + this.buttonLeft.Location = new System.Drawing.Point(689, 406); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 4; @@ -156,7 +83,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(722, 395); + this.buttonDown.Location = new System.Drawing.Point(725, 406); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 5; @@ -168,7 +95,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(722, 359); + this.buttonUp.Location = new System.Drawing.Point(725, 370); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 6; @@ -178,7 +105,7 @@ // numericUpDownWheelsNumber // this.numericUpDownWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.numericUpDownWheelsNumber.Location = new System.Drawing.Point(651, 402); + this.numericUpDownWheelsNumber.Location = new System.Drawing.Point(651, 413); this.numericUpDownWheelsNumber.Maximum = new decimal(new int[] { 4, 0, @@ -203,61 +130,39 @@ // this.labelWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.labelWheelsNumber.AutoSize = true; - this.labelWheelsNumber.Location = new System.Drawing.Point(565, 404); + this.labelWheelsNumber.Location = new System.Drawing.Point(565, 415); this.labelWheelsNumber.Name = "labelWheelsNumber"; this.labelWheelsNumber.Size = new System.Drawing.Size(80, 15); this.labelWheelsNumber.TabIndex = 8; this.labelWheelsNumber.Text = "Число колёс:"; // - // 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(108, 395); - this.buttonCreateModif.Name = "buttonCreateModif"; - this.buttonCreateModif.Size = new System.Drawing.Size(98, 30); - this.buttonCreateModif.TabIndex = 9; - this.buttonCreateModif.Text = "Модификация"; - this.buttonCreateModif.UseVisualStyleBackColor = true; - this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); - // - // buttonSelectLocomotive - // - this.buttonSelectLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonSelectLocomotive.Location = new System.Drawing.Point(461, 396); - this.buttonSelectLocomotive.Name = "buttonSelectLocomotive"; - this.buttonSelectLocomotive.Size = new System.Drawing.Size(98, 30); - this.buttonSelectLocomotive.TabIndex = 10; - this.buttonSelectLocomotive.Text = "Выбрать"; - this.buttonSelectLocomotive.UseVisualStyleBackColor = true; - this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click); - // // buttonGenerateEntities // - this.buttonGenerateEntities.Location = new System.Drawing.Point(12, 294); + this.buttonGenerateEntities.Location = new System.Drawing.Point(12, 406); this.buttonGenerateEntities.Name = "buttonGenerateEntities"; - this.buttonGenerateEntities.Size = new System.Drawing.Size(90, 32); + this.buttonGenerateEntities.Size = new System.Drawing.Size(156, 32); this.buttonGenerateEntities.TabIndex = 11; - this.buttonGenerateEntities.Text = "button1"; + this.buttonGenerateEntities.Text = "Сгенерировать сущности"; this.buttonGenerateEntities.UseVisualStyleBackColor = true; - this.buttonGenerateEntities.Click += new System.EventHandler(this.ButtonGenerateEntities_Click_1); + this.buttonGenerateEntities.Click += new System.EventHandler(this.ButtonGenerateEntities_Click); // // buttonGenerateAdditionalElementsSetup // - this.buttonGenerateAdditionalElementsSetup.Location = new System.Drawing.Point(188, 294); + this.buttonGenerateAdditionalElementsSetup.Location = new System.Drawing.Point(375, 406); this.buttonGenerateAdditionalElementsSetup.Name = "buttonGenerateAdditionalElementsSetup"; - this.buttonGenerateAdditionalElementsSetup.Size = new System.Drawing.Size(90, 32); + this.buttonGenerateAdditionalElementsSetup.Size = new System.Drawing.Size(184, 32); this.buttonGenerateAdditionalElementsSetup.TabIndex = 12; - this.buttonGenerateAdditionalElementsSetup.Text = "button1"; + this.buttonGenerateAdditionalElementsSetup.Text = "Сгенерировать доп. отрисовку"; this.buttonGenerateAdditionalElementsSetup.UseVisualStyleBackColor = true; this.buttonGenerateAdditionalElementsSetup.Click += new System.EventHandler(this.ButtonGenerateAdditionalElementsSetup_Click); // // buttonShowGeneratedObject // - this.buttonShowGeneratedObject.Location = new System.Drawing.Point(98, 216); + this.buttonShowGeneratedObject.Location = new System.Drawing.Point(204, 406); this.buttonShowGeneratedObject.Name = "buttonShowGeneratedObject"; - this.buttonShowGeneratedObject.Size = new System.Drawing.Size(90, 32); + this.buttonShowGeneratedObject.Size = new System.Drawing.Size(139, 32); this.buttonShowGeneratedObject.TabIndex = 13; - this.buttonShowGeneratedObject.Text = "button1"; + this.buttonShowGeneratedObject.Text = "Сгенерировать объект"; this.buttonShowGeneratedObject.UseVisualStyleBackColor = true; this.buttonShowGeneratedObject.Click += new System.EventHandler(this.ButtonShowGeneratedObject_Click); // @@ -269,22 +174,16 @@ this.Controls.Add(this.buttonShowGeneratedObject); this.Controls.Add(this.buttonGenerateAdditionalElementsSetup); this.Controls.Add(this.buttonGenerateEntities); - this.Controls.Add(this.buttonSelectLocomotive); - this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.labelWheelsNumber); this.Controls.Add(this.numericUpDownWheelsNumber); this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.statusStrip); this.Controls.Add(this.pictureBoxLocomotive); this.Name = "FormLocomotiveAdditional"; this.Text = "Локомотив"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); - this.statusStrip.ResumeLayout(false); - this.statusStrip.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -294,22 +193,12 @@ #endregion private PictureBox pictureBoxLocomotive; - private StatusStrip statusStrip; - private ToolStripStatusLabel toolStripStatusLabelSpeed; - private ToolStripStatusLabel toolStripStatusLabelWeight; - private ToolStripStatusLabel toolStripStatusLabelBodyColor; - private Button buttonCreate; private Button buttonRight; private Button buttonLeft; private Button buttonDown; private Button buttonUp; private NumericUpDown numericUpDownWheelsNumber; private Label labelWheelsNumber; - private Button buttonCreateModif; - private ToolStripStatusLabel toolStripStatusLabelAdditionalColor; - private ToolStripStatusLabel toolStripStatusLabelHasPipe; - private ToolStripStatusLabel toolStripStatusLabelHasFuelTank; - private Button buttonSelectLocomotive; private Button buttonGenerateEntities; private Button buttonGenerateAdditionalElementsSetup; private Button buttonShowGeneratedObject; diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotiveAdditional.cs similarity index 57% rename from LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.cs rename to LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotiveAdditional.cs index 7c1e40a..3627e76 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive - Копировать.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotiveAdditional.cs @@ -7,12 +7,12 @@ /// private DrawningLocomotive _locomotive; /// - /// Выбранный объект + /// Объект от параметризованного класса с параметрами типа сущности и интерфейса отрисовки дополнительных частей /// - public DrawningLocomotive SelectedLocomotive { get; private set; } - private AdvancedObjectGeneric AdvancedObject = new AdvancedObjectGeneric(); - + /// + /// Конструктор + /// public FormLocomotiveAdditional() { InitializeComponent(); @@ -28,48 +28,6 @@ pictureBoxLocomotive.Image = bmp; } /// - /// Заполнение информации по объекту - /// - /// Объект от класса отрисовки или его наследника - private void SetData(DrawningLocomotive locomotive) - { - Random rnd = new(); - toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}"; - toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: н/д"; - toolStripStatusLabelHasPipe.Text = $"Наличие трубы: н/д"; - toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: н/д"; - _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); - } - /// - /// Заполнение дополнительной информации по объекту (только для усложнённого объекта) - /// - /// Объект от наследника класса отрисовки - private void SetAdditionalData(DrawningWarmlyLocomotive warmlylocomotive) - { - if (warmlylocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive) - { - toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: {entityWarmlyLocomotive.AdditionalColor.Name}"; - toolStripStatusLabelHasPipe.Text = $"Наличие трубы: {entityWarmlyLocomotive.HasPipe}"; - toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: {entityWarmlyLocomotive.HasFuelTank}"; - } - } - /// - /// Метод обработки нажатия на кнопку "Создать" - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - _locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); - SetData(_locomotive); - _locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value; - Draw(); - } - /// /// Метод обработки нажатия на кнопки перемещения /// /// @@ -106,39 +64,13 @@ Draw(); } /// - /// Метод обработки нажатия на кнопку "Модификация" + /// Метод обработки нажатия на кнопку "Сгенерировать сущности" /// /// /// - private void ButtonCreateModif_Click(object sender, EventArgs e) + private void ButtonGenerateEntities_Click(object sender, EventArgs e) { Random rnd = new(); - _locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - 160, 115, - 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(_locomotive); - SetAdditionalData((DrawningWarmlyLocomotive)_locomotive); - _locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value; - Draw(); - } - /// - /// Метод обработки нажатия на кнопку "Выбрать" - /// - /// - /// - private void ButtonSelectLocomotive_Click(object sender, EventArgs e) - { - SelectedLocomotive = _locomotive; - DialogResult = DialogResult.OK; - } - - private void ButtonGenerateEntities_Click_1(object sender, EventArgs e) - { - Random rnd = new(); - AdvancedObject.CurrentEntityIndex = 0; for (int i = 0; i < 10; i++) { bool IsAdvancedEntity = Convert.ToBoolean(rnd.Next(0, 2)); @@ -158,13 +90,17 @@ AdvancedObject.AddEntity(Entity); } } - + /// + /// Метод обработки нажатия на кнопку "Сгенерировать доп. элементы" + /// + /// + /// private void ButtonGenerateAdditionalElementsSetup_Click(object sender, EventArgs e) { Random rnd = new(); for (int i = 0; i < 10; i++) { - int AdditionalElementSetupType = rnd.Next(0, 2); + int AdditionalElementSetupType = rnd.Next(0, 3); switch (AdditionalElementSetupType) { case 0: @@ -179,13 +115,16 @@ } } } - + /// + /// Метод обработки нажатия на кнопку "Сгенерировать объект" + /// + /// + /// private void ButtonShowGeneratedObject_Click(object sender, EventArgs e) { Random rnd = new(); _locomotive = AdvancedObject.GeneratedObject(); _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); - SetData(_locomotive); _locomotive.AdditionalElements.WheelsNum = 2; _locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value; Draw(); diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.resx b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotiveAdditional.resx similarity index 93% rename from LocomotivesAdvanced/LocomotivesAdvanced/FormMap.resx rename to LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotiveAdditional.resx index 2c0949d..f298a7b 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.resx +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotiveAdditional.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/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.Designer.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.Designer.cs deleted file mode 100644 index 8daa082..0000000 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.Designer.cs +++ /dev/null @@ -1,327 +0,0 @@ -namespace WarmlyLocomotove -{ - 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.pictureBoxLocomotive = 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.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel(); - this.buttonCreate = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - this.buttonCreateModif = new System.Windows.Forms.Button(); - this.labelWheelsNumber = new System.Windows.Forms.Label(); - this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown(); - this.radioButtonNoOrnament = new System.Windows.Forms.RadioButton(); - this.radioButtonRectOrnament = new System.Windows.Forms.RadioButton(); - this.radioButtonEllipseOrnament = new System.Windows.Forms.RadioButton(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); - this.statusStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit(); - this.SuspendLayout(); - // - // pictureBoxLocomotive - // - this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0); - this.pictureBoxLocomotive.MinimumSize = new System.Drawing.Size(1, 1); - this.pictureBoxLocomotive.Name = "pictureBoxLocomotive"; - this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 450); - this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxLocomotive.TabIndex = 0; - this.pictureBoxLocomotive.TabStop = false; - // - // statusStrip - // - this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelBodyColor, - this.toolStripStatusLabelAdditionalColor, - this.toolStripStatusLabelHasPipe, - this.toolStripStatusLabelHasFuelTank}); - this.statusStrip.Location = new System.Drawing.Point(0, 428); - this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(800, 22); - this.statusStrip.TabIndex = 1; - this.statusStrip.Text = "statusStrip1"; - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17); - this.toolStripStatusLabelSpeed.Text = "Скорость: "; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17); - this.toolStripStatusLabelWeight.Text = "Вес: "; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17); - this.toolStripStatusLabelBodyColor.Text = "Цвет: "; - // - // toolStripStatusLabelAdditionalColor - // - this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor"; - this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17); - this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: "; - // - // toolStripStatusLabelHasPipe - // - this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe"; - this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17); - this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: "; - // - // toolStripStatusLabelHasFuelTank - // - this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank"; - this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17); - this.toolStripStatusLabelHasFuelTank.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, 395); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(90, 30); - this.buttonCreate.TabIndex = 2; - this.buttonCreate.Text = "Создать"; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(758, 395); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 3; - 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::WarmlyLocomotive.Properties.Resources.ArrowLeft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(686, 395); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(30, 30); - this.buttonLeft.TabIndex = 4; - this.buttonLeft.UseVisualStyleBackColor = true; - this.buttonLeft.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::WarmlyLocomotive.Properties.Resources.ArrowDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(722, 395); - 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); - // - // buttonUp - // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(722, 359); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - this.buttonUp.TabIndex = 6; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.Click += new System.EventHandler(this.ButtonMove_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(141, 23); - this.comboBoxSelectorMap.TabIndex = 7; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); - // - // 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(108, 395); - this.buttonCreateModif.Name = "buttonCreateModif"; - this.buttonCreateModif.Size = new System.Drawing.Size(109, 30); - this.buttonCreateModif.TabIndex = 8; - this.buttonCreateModif.Text = "Модификация"; - this.buttonCreateModif.UseVisualStyleBackColor = true; - this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); - // - // labelWheelsNumber - // - this.labelWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.labelWheelsNumber.AutoSize = true; - this.labelWheelsNumber.Location = new System.Drawing.Point(560, 403); - this.labelWheelsNumber.Name = "labelWheelsNumber"; - this.labelWheelsNumber.Size = new System.Drawing.Size(80, 15); - this.labelWheelsNumber.TabIndex = 10; - this.labelWheelsNumber.Text = "Число колёс:"; - // - // numericUpDownWheelsNumber - // - this.numericUpDownWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.numericUpDownWheelsNumber.Location = new System.Drawing.Point(646, 401); - this.numericUpDownWheelsNumber.Maximum = new decimal(new int[] { - 4, - 0, - 0, - 0}); - this.numericUpDownWheelsNumber.Minimum = new decimal(new int[] { - 2, - 0, - 0, - 0}); - this.numericUpDownWheelsNumber.Name = "numericUpDownWheelsNumber"; - this.numericUpDownWheelsNumber.ReadOnly = true; - this.numericUpDownWheelsNumber.Size = new System.Drawing.Size(29, 23); - this.numericUpDownWheelsNumber.TabIndex = 9; - this.numericUpDownWheelsNumber.Value = new decimal(new int[] { - 2, - 0, - 0, - 0}); - // - // radioButtonNoOrnament - // - this.radioButtonNoOrnament.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.radioButtonNoOrnament.AutoSize = true; - this.radioButtonNoOrnament.Checked = true; - this.radioButtonNoOrnament.Location = new System.Drawing.Point(223, 399); - this.radioButtonNoOrnament.Name = "radioButtonNoOrnament"; - this.radioButtonNoOrnament.Size = new System.Drawing.Size(108, 19); - this.radioButtonNoOrnament.TabIndex = 11; - this.radioButtonNoOrnament.TabStop = true; - this.radioButtonNoOrnament.Text = "Нет орнамента"; - this.radioButtonNoOrnament.UseVisualStyleBackColor = true; - this.radioButtonNoOrnament.CheckedChanged += new System.EventHandler(this.RadioButtonOrnament_CheckedChanged); - // - // radioButtonRectOrnament - // - this.radioButtonRectOrnament.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.radioButtonRectOrnament.AutoSize = true; - this.radioButtonRectOrnament.Location = new System.Drawing.Point(337, 399); - this.radioButtonRectOrnament.Name = "radioButtonRectOrnament"; - this.radioButtonRectOrnament.Size = new System.Drawing.Size(91, 19); - this.radioButtonRectOrnament.TabIndex = 12; - this.radioButtonRectOrnament.Text = "Квадратный"; - this.radioButtonRectOrnament.UseVisualStyleBackColor = true; - this.radioButtonRectOrnament.CheckedChanged += new System.EventHandler(this.RadioButtonOrnament_CheckedChanged); - // - // radioButtonEllipseOrnament - // - this.radioButtonEllipseOrnament.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.radioButtonEllipseOrnament.AutoSize = true; - this.radioButtonEllipseOrnament.Location = new System.Drawing.Point(437, 399); - this.radioButtonEllipseOrnament.Name = "radioButtonEllipseOrnament"; - this.radioButtonEllipseOrnament.Size = new System.Drawing.Size(73, 19); - this.radioButtonEllipseOrnament.TabIndex = 13; - this.radioButtonEllipseOrnament.Text = "Круглый"; - this.radioButtonEllipseOrnament.UseVisualStyleBackColor = true; - this.radioButtonEllipseOrnament.CheckedChanged += new System.EventHandler(this.RadioButtonOrnament_CheckedChanged); - // - // FormMap - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.radioButtonEllipseOrnament); - this.Controls.Add(this.radioButtonRectOrnament); - this.Controls.Add(this.radioButtonNoOrnament); - this.Controls.Add(this.labelWheelsNumber); - this.Controls.Add(this.numericUpDownWheelsNumber); - this.Controls.Add(this.buttonCreateModif); - this.Controls.Add(this.comboBoxSelectorMap); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.statusStrip); - this.Controls.Add(this.pictureBoxLocomotive); - this.Name = "FormMap"; - this.Text = "Локомотив"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); - this.statusStrip.ResumeLayout(false); - this.statusStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private PictureBox pictureBoxLocomotive; - private StatusStrip statusStrip; - private ToolStripStatusLabel toolStripStatusLabelSpeed; - private ToolStripStatusLabel toolStripStatusLabelWeight; - private ToolStripStatusLabel toolStripStatusLabelBodyColor; - private Button buttonCreate; - private Button buttonRight; - private Button buttonLeft; - private Button buttonDown; - private Button buttonUp; - private ComboBox comboBoxSelectorMap; - private Button buttonCreateModif; - private ToolStripStatusLabel toolStripStatusLabelAdditionalColor; - private ToolStripStatusLabel toolStripStatusLabelHasPipe; - private ToolStripStatusLabel toolStripStatusLabelHasFuelTank; - private Label labelWheelsNumber; - private NumericUpDown numericUpDownWheelsNumber; - private RadioButton radioButtonNoOrnament; - private RadioButton radioButtonRectOrnament; - private RadioButton radioButtonEllipseOrnament; - } -} \ No newline at end of file diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.cs deleted file mode 100644 index 26cb35d..0000000 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.cs +++ /dev/null @@ -1,151 +0,0 @@ -namespace WarmlyLocomotove -{ - public partial class FormMap : Form - { - /// - /// Создание объекта от абстрактного класса карты - /// - private AbstractMap _abstractMap; - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - /// - /// Заполнение информации по объекту - /// - /// Объект от класса отрисовки или его наследника - private void SetData(DrawningLocomotive locomotive) - { - toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}"; - toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: н/д"; - toolStripStatusLabelHasPipe.Text = $"Наличие трубы: н/д"; - toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: н/д"; - pictureBoxLocomotive.Image = _abstractMap.CreateMap(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height, - new DrawningObjectLocomotive(locomotive)); - } - /// - /// Заполнение дополнительной информации по объекту (только для усложнённого объекта) - /// - /// Объект от наследника класса отрисовки - private void SetAdditionalData(DrawningWarmlyLocomotive warmlylocomotive) - { - if (warmlylocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive) - { - toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: {entityWarmlyLocomotive.AdditionalColor.Name}"; - toolStripStatusLabelHasPipe.Text = $"Наличие трубы: {entityWarmlyLocomotive.HasPipe}"; - toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: {entityWarmlyLocomotive.HasFuelTank}"; - } - } - /// - /// Обработка нажатия кнопки "Создать" - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - var locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - SetOrnament(locomotive); - locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value; - SetData(locomotive); - } - /// - /// Перемещение объекта по форме - /// - /// - /// - 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; - } - pictureBoxLocomotive.Image = _abstractMap?.MoveObject(dir); - } - /// - /// Обработка нажатия кнопки "Модификация" - /// - /// - /// - private void ButtonCreateModif_Click(object sender, EventArgs e) - { - Random rnd = new(); - var locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - 160, 85, - 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))); - SetOrnament(locomotive); - locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value; - SetData(locomotive); - SetAdditionalData(locomotive); - } - /// - /// Смена карты - /// - /// - /// - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Карта с крестом": - _abstractMap = new CrossMap(); - break; - case "Карта с дорожками": - _abstractMap = new RoadsMap(); - break; - default: - break; - } - } - - string CurrentOrnament = ""; - - private void RadioButtonOrnament_CheckedChanged(object sender, EventArgs e) - { - if (((RadioButton)sender).Checked) - { - CurrentOrnament = ((RadioButton)sender).Name; - } - } - - private void SetOrnament(DrawningLocomotive locomotive) - { - switch (CurrentOrnament) - { - case "radioButtonNoOrnament": - locomotive.AdditionalElements = new DrawningWheels(); - break; - case "radioButtonRectOrnament": - locomotive.AdditionalElements = new DrawningRectOrnament(); - break; - case "radioButtonEllipseOrnament": - locomotive.AdditionalElements = new DrawningEllipseOrnament(); - break; - } - } - } -} diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.cs index 3409b66..b9afc36 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormMapWithSetLocomotives.cs @@ -90,7 +90,7 @@ return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if ((_mapCarsCollectionGeneric - pos) > -1) + if ((_mapCarsCollectionGeneric - pos) != null) { MessageBox.Show("Объект удален"); pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet(); diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/MapWithSetLocomotivesGeneric.cs b/LocomotivesAdvanced/LocomotivesAdvanced/MapWithSetLocomotivesGeneric.cs index 7623fe8..b548f36 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/MapWithSetLocomotivesGeneric.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/MapWithSetLocomotivesGeneric.cs @@ -51,7 +51,7 @@ /// public static int operator +(MapWithSetLocomotivesGeneric map, T locomotive) { - return map._setLocomotives.Insert(locomotive); + return map._setLocomotives.Insert(locomotive, 0); } /// /// Перегрузка оператора вычитания @@ -59,7 +59,7 @@ /// /// /// - public static int operator -(MapWithSetLocomotivesGeneric map, int position) + public static T operator -(MapWithSetLocomotivesGeneric map, int position) { return map._setLocomotives.Remove(position); } diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/SetLocomotivesGeneric.cs b/LocomotivesAdvanced/LocomotivesAdvanced/SetLocomotivesGeneric.cs index 8292d60..ceb760e 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/SetLocomotivesGeneric.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/SetLocomotivesGeneric.cs @@ -20,32 +20,6 @@ _places = new T[count]; } /// - /// Добавление объекта в набор - /// - /// Добавляемый локомотив - /// - public int Insert(T locomotive) - { - T testLocomotive = _places[0]; - for (int i = 0; i < Count; i++) - { - if (_places[i] == null) - { - testLocomotive = _places[i]; - } - } - if (testLocomotive != null) - { - return -1; - } - for (int i = Count - 2; i >= 0; i--) - { - _places[i + 1] = _places[i]; - } - _places[0] = locomotive; - return 0; - } - /// /// Добавление объекта в набор на конкретную позицию /// /// Добавляемый локомотив @@ -55,14 +29,14 @@ { if (position < 0 || position >= Count) { - return position; + return -1; } int ClosestNullElementIndex = position; while (_places[ClosestNullElementIndex] != null) { if (ClosestNullElementIndex == Count) { - return position; + return -1; } ClosestNullElementIndex++; } @@ -79,14 +53,15 @@ /// /// /// - public int Remove(int position) + public T Remove(int position) { if (_places[position] == null) { - return -1; + return null; } + var result = _places[position]; _places[position] = null; - return position; + return result; } /// /// Получение объекта из набора по позиции diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/WarmlyLocomotive.csproj b/LocomotivesAdvanced/LocomotivesAdvanced/WarmlyLocomotive.csproj index 72f3413..64d54a0 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/WarmlyLocomotive.csproj +++ b/LocomotivesAdvanced/LocomotivesAdvanced/WarmlyLocomotive.csproj @@ -9,7 +9,7 @@ - + Form -- 2.25.1