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] =?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