From 7beae4d50f12bc8ab0e864ff5b3db36ce7de07b0 Mon Sep 17 00:00:00 2001 From: ALINA_KURBANOVA Date: Sat, 11 Nov 2023 00:01:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyLocomotive/DrawningWarmlyLocomotive.cs | 20 ++- ...=> DrawningWarmlyLocomotiveWithTrumpet.cs} | 8 +- ... => EntityWarmlyLocomotiveWithTrumpet .cs} | 4 +- ...FormWarmlyLocomotiveCollection.Designer.cs | 135 ++++++++++++++++++ .../FormWarmlyLocomotiveCollection.cs | 65 +++++++++ .../FormWarmlyLocomotiveCollection.resx | 120 ++++++++++++++++ WarmlyLocomotive/Program.cs | 1 + WarmlyLocomotive/WarmlyLocomotiveForm.cs | 49 +++++-- .../WarmlylocomotiveForm.Designer.cs | 27 +++- 9 files changed, 398 insertions(+), 31 deletions(-) rename WarmlyLocomotive/{DrawningPro.cs => DrawningWarmlyLocomotiveWithTrumpet.cs} (75%) rename WarmlyLocomotive/{Pro.cs => EntityWarmlyLocomotiveWithTrumpet .cs} (82%) create mode 100644 WarmlyLocomotive/FormWarmlyLocomotiveCollection.Designer.cs create mode 100644 WarmlyLocomotive/FormWarmlyLocomotiveCollection.cs create mode 100644 WarmlyLocomotive/FormWarmlyLocomotiveCollection.resx diff --git a/WarmlyLocomotive/DrawningWarmlyLocomotive.cs b/WarmlyLocomotive/DrawningWarmlyLocomotive.cs index 88911f2..15df6f6 100644 --- a/WarmlyLocomotive/DrawningWarmlyLocomotive.cs +++ b/WarmlyLocomotive/DrawningWarmlyLocomotive.cs @@ -1,15 +1,18 @@ using WarmlyLocomotive.Entities; -namespace WarmlyLocomotive.DrawningObjects -{ - /// - /// Класс, отвечающий за прорисовку и перемещение объекта-сущности - /// - public class DrawningWarmlyLocomotive +using WarmlyLocomotive.MovementStrategy; + +namespace WarmlyLocomotive.DrawningObjects +{ +/// +/// Класс, отвечающий за прорисовку и перемещение объекта-сущности +/// +public class DrawningWarmlyLocomotive { /// /// Класс-сущность /// public EntityWarmlyLocomotive? EntityWarmlyLocomotive { get; protected set; } + public IMoveableObject GetMoveableObject => new DrawningObjectCar(this); /// /// Ширина окна /// @@ -151,6 +154,10 @@ namespace WarmlyLocomotive.DrawningObjects /// Прорисовка объекта /// /// + /// + /// Прорисовка объекта + /// + /// public virtual void DrawTransport(Graphics g) { if (EntityWarmlyLocomotive == null) @@ -184,3 +191,4 @@ namespace WarmlyLocomotive.DrawningObjects + diff --git a/WarmlyLocomotive/DrawningPro.cs b/WarmlyLocomotive/DrawningWarmlyLocomotiveWithTrumpet.cs similarity index 75% rename from WarmlyLocomotive/DrawningPro.cs rename to WarmlyLocomotive/DrawningWarmlyLocomotiveWithTrumpet.cs index a1d028f..f44ea1a 100644 --- a/WarmlyLocomotive/DrawningPro.cs +++ b/WarmlyLocomotive/DrawningWarmlyLocomotiveWithTrumpet.cs @@ -5,19 +5,19 @@ namespace WarmlyLocomotive.DrawningObjects /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// - public class DrawningPro : DrawningWarmlyLocomotive + public class DrawningWarmlyLocomotiveWithTrumpet : DrawningWarmlyLocomotive { - public DrawningPro(int speed, double weight, Color bodyColor, Color + public DrawningWarmlyLocomotiveWithTrumpet(int speed, double weight, Color bodyColor, Color additionalColor, bool trumpet, bool luggage, int width, int height) :base(speed, weight, bodyColor, width, height, 200, 75) { if (EntityWarmlyLocomotive != null) { - EntityWarmlyLocomotive = new Pro(speed, weight, bodyColor, additionalColor, trumpet, luggage); + EntityWarmlyLocomotive = new EntityWarmlyLocomotiveWithTrumpet(speed, weight, bodyColor, additionalColor, trumpet, luggage); } } public override void DrawTransport(Graphics g) { - if (EntityWarmlyLocomotive is not Pro warmlylocomotive) + if (EntityWarmlyLocomotive is not EntityWarmlyLocomotiveWithTrumpet warmlylocomotive) { return; } diff --git a/WarmlyLocomotive/Pro.cs b/WarmlyLocomotive/EntityWarmlyLocomotiveWithTrumpet .cs similarity index 82% rename from WarmlyLocomotive/Pro.cs rename to WarmlyLocomotive/EntityWarmlyLocomotiveWithTrumpet .cs index a3f3d79..0fab038 100644 --- a/WarmlyLocomotive/Pro.cs +++ b/WarmlyLocomotive/EntityWarmlyLocomotiveWithTrumpet .cs @@ -1,6 +1,6 @@ namespace WarmlyLocomotive.Entities { - public class Pro : EntityWarmlyLocomotive + public class EntityWarmlyLocomotiveWithTrumpet : EntityWarmlyLocomotive { /// /// Дополнительный цвет (для опциональных элементов) @@ -14,7 +14,7 @@ /// Признак (опция) наличия прицепа /// public bool Luggage { get; private set; } - public Pro(int speed, double weight, Color bodyColor, Color + public EntityWarmlyLocomotiveWithTrumpet(int speed, double weight, Color bodyColor, Color additionalColor, bool trumpet,bool luggage) : base(speed, weight, bodyColor) { diff --git a/WarmlyLocomotive/FormWarmlyLocomotiveCollection.Designer.cs b/WarmlyLocomotive/FormWarmlyLocomotiveCollection.Designer.cs new file mode 100644 index 0000000..867fb26 --- /dev/null +++ b/WarmlyLocomotive/FormWarmlyLocomotiveCollection.Designer.cs @@ -0,0 +1,135 @@ +namespace WarmlyLocomotive +{ + partial class FormWarmlyLocomotiveCollection + { + /// + /// 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() + { + labelCollection = new Label(); + panelCollectionWarmlyLocomotive = new Panel(); + buttonreFreshCollection = new Button(); + textBoxCollectionWarmlyLocomotive = new TextBox(); + buttonRemove = new Button(); + buttonadd = new Button(); + pictureBoxCollectionWarmlyLocomotive = new PictureBox(); + panelCollectionWarmlyLocomotive.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollectionWarmlyLocomotive).BeginInit(); + SuspendLayout(); + // + // labelCollection + // + labelCollection.AutoSize = true; + labelCollection.BorderStyle = BorderStyle.Fixed3D; + labelCollection.Location = new Point(662, 10); + labelCollection.Name = "labelCollection"; + labelCollection.Size = new Size(85, 17); + labelCollection.TabIndex = 0; + labelCollection.Text = "Инструменты"; + // + // panelCollectionWarmlyLocomotive + // + panelCollectionWarmlyLocomotive.Controls.Add(buttonreFreshCollection); + panelCollectionWarmlyLocomotive.Controls.Add(textBoxCollectionWarmlyLocomotive); + panelCollectionWarmlyLocomotive.Controls.Add(buttonRemove); + panelCollectionWarmlyLocomotive.Controls.Add(buttonadd); + panelCollectionWarmlyLocomotive.Location = new Point(662, 28); + panelCollectionWarmlyLocomotive.Name = "panelCollectionWarmlyLocomotive"; + panelCollectionWarmlyLocomotive.Size = new Size(149, 350); + panelCollectionWarmlyLocomotive.TabIndex = 1; + // + // buttonreFreshCollection + // + buttonreFreshCollection.Location = new Point(3, 193); + buttonreFreshCollection.Name = "buttonreFreshCollection"; + buttonreFreshCollection.Size = new Size(146, 23); + buttonreFreshCollection.TabIndex = 3; + buttonreFreshCollection.Text = "Обновить коллекцию"; + buttonreFreshCollection.UseVisualStyleBackColor = true; + buttonreFreshCollection.Click += buttonreFreshCollection_Click; + // + // textBoxCollectionWarmlyLocomotive + // + textBoxCollectionWarmlyLocomotive.Location = new Point(17, 128); + textBoxCollectionWarmlyLocomotive.Name = "textBoxCollectionWarmlyLocomotive"; + textBoxCollectionWarmlyLocomotive.Size = new Size(117, 23); + textBoxCollectionWarmlyLocomotive.TabIndex = 2; + // + // buttonRemove + // + buttonRemove.Location = new Point(3, 71); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(131, 23); + buttonRemove.TabIndex = 1; + buttonRemove.Text = "Удалить тепловоз"; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonadd + // + buttonadd.Location = new Point(3, 22); + buttonadd.Name = "buttonadd"; + buttonadd.Size = new Size(131, 23); + buttonadd.TabIndex = 0; + buttonadd.Text = "Добавить тепловоз"; + buttonadd.UseVisualStyleBackColor = true; + buttonadd.Click += buttonAdd_Click; + // + // pictureBoxCollectionWarmlyLocomotive + // + pictureBoxCollectionWarmlyLocomotive.Location = new Point(12, 28); + pictureBoxCollectionWarmlyLocomotive.Name = "pictureBoxCollectionWarmlyLocomotive"; + pictureBoxCollectionWarmlyLocomotive.Size = new Size(647, 350); + pictureBoxCollectionWarmlyLocomotive.TabIndex = 2; + pictureBoxCollectionWarmlyLocomotive.TabStop = false; + // + // FormWarmlyLocomotiveCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(823, 450); + Controls.Add(pictureBoxCollectionWarmlyLocomotive); + Controls.Add(panelCollectionWarmlyLocomotive); + Controls.Add(labelCollection); + Name = "FormWarmlyLocomotiveCollection"; + Text = "FormWarmlyLocomotiveCollection"; + panelCollectionWarmlyLocomotive.ResumeLayout(false); + panelCollectionWarmlyLocomotive.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollectionWarmlyLocomotive).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelCollection; + private Panel panelCollectionWarmlyLocomotive; + private PictureBox pictureBoxCollectionWarmlyLocomotive; + private Button buttonadd; + private Button buttonRemove; + private Button buttonreFreshCollection; + private TextBox textBoxCollectionWarmlyLocomotive; + } +} \ No newline at end of file diff --git a/WarmlyLocomotive/FormWarmlyLocomotiveCollection.cs b/WarmlyLocomotive/FormWarmlyLocomotiveCollection.cs new file mode 100644 index 0000000..a3d054a --- /dev/null +++ b/WarmlyLocomotive/FormWarmlyLocomotiveCollection.cs @@ -0,0 +1,65 @@ +using WarmlyLocomotive.DrawningObjects; +using WarmlyLocomotive.Generics; +using WarmlyLocomotive.MovementStrategy; + +namespace WarmlyLocomotive +{ + public partial class FormWarmlyLocomotiveCollection : Form + { + private readonly CarsGenericCollection _warmlylocomotives; + public FormWarmlyLocomotiveCollection() + { + InitializeComponent(); + _warmlylocomotives = new CarsGenericCollection(pictureBoxCollectionWarmlyLocomotive.Width, pictureBoxCollectionWarmlyLocomotive.Height); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + WarmlyLocomotiveForm form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_warmlylocomotives + form.SelectedCar != null) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollectionWarmlyLocomotive.Image = _warmlylocomotives.ShowCars(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + } + + private void buttonreFreshCollection_Click(object sender, EventArgs e) + { + pictureBoxCollectionWarmlyLocomotive.Image = _warmlylocomotives.ShowCars(); + } + + private void buttonRemove_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos; + if (textBoxCollectionWarmlyLocomotive.Text == null || !int.TryParse(textBoxCollectionWarmlyLocomotive.Text, out pos)) + { + MessageBox.Show("Введите номер парковочного места"); + return; + } + + if (_warmlylocomotives - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollectionWarmlyLocomotive.Image = _warmlylocomotives.ShowCars(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + } +} diff --git a/WarmlyLocomotive/FormWarmlyLocomotiveCollection.resx b/WarmlyLocomotive/FormWarmlyLocomotiveCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WarmlyLocomotive/FormWarmlyLocomotiveCollection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/WarmlyLocomotive/Program.cs b/WarmlyLocomotive/Program.cs index 742d1d3..fc272d5 100644 --- a/WarmlyLocomotive/Program.cs +++ b/WarmlyLocomotive/Program.cs @@ -11,6 +11,7 @@ namespace WarmlyLocomotive // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); + Application.Run(new FormWarmlyLocomotiveCollection()); Application.Run(new WarmlyLocomotiveForm()); } } diff --git a/WarmlyLocomotive/WarmlyLocomotiveForm.cs b/WarmlyLocomotive/WarmlyLocomotiveForm.cs index a9b7087..58f42d6 100644 --- a/WarmlyLocomotive/WarmlyLocomotiveForm.cs +++ b/WarmlyLocomotive/WarmlyLocomotiveForm.cs @@ -14,11 +14,13 @@ namespace WarmlyLocomotive private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive; private AbstractStrategy? _abstractStrategy; - + private AbstractStrategy? _strategy; public DrawningWarmlyLocomotive? SelectedCar { get; private set; } public WarmlyLocomotiveForm() { InitializeComponent(); + _strategy = null; + SelectedCar = null; } /// /// @@ -43,10 +45,17 @@ namespace WarmlyLocomotive private void buttonCreate_Click(object sender, EventArgs e) { Random random = new(); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } _drawningWarmlyLocomotive = new DrawningWarmlyLocomotive(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), + color, pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height); _drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100)); @@ -126,18 +135,34 @@ namespace WarmlyLocomotive private void buttonCreate_Pro_Click(object sender, EventArgs e) { Random random = new(); - _drawningWarmlyLocomotive = new DrawningPro(random.Next(100, 300), - random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), - Convert.ToBoolean(random.Next(0, 2)), - pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dopDialog = new(); + if (dopDialog.ShowDialog() == DialogResult.OK) + { + dopColor = dopDialog.Color; + } + _drawningWarmlyLocomotive = new DrawningWarmlyLocomotiveWithTrumpet(random.Next(100, 300), + random.Next(1000, 3000), + color, + dopColor, + Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2)), + pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height); _drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } + + private void buttonSelectCar_Click(object sender, EventArgs e) + { + SelectedCar = _drawningWarmlyLocomotive; + DialogResult = DialogResult.OK; + } } } diff --git a/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs b/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs index bcb4188..82933ad 100644 --- a/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs +++ b/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs @@ -38,6 +38,7 @@ comboBoxWarmlyLocomotive = new ComboBox(); buttonStep = new Button(); buttonCreate_Pro = new Button(); + buttonSelectCar = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).BeginInit(); SuspendLayout(); // @@ -46,7 +47,7 @@ pictureBoxWarmlyLocomotive.Dock = DockStyle.Fill; pictureBoxWarmlyLocomotive.Location = new Point(0, 0); pictureBoxWarmlyLocomotive.Name = "pictureBoxWarmlyLocomotive"; - pictureBoxWarmlyLocomotive.Size = new Size(884, 461); + pictureBoxWarmlyLocomotive.Size = new Size(884, 481); pictureBoxWarmlyLocomotive.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxWarmlyLocomotive.TabIndex = 0; pictureBoxWarmlyLocomotive.TabStop = false; @@ -54,7 +55,7 @@ // buttonCreate // buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(210, 404); + buttonCreate.Location = new Point(216, 399); buttonCreate.Name = "buttonCreate"; buttonCreate.Size = new Size(119, 23); buttonCreate.TabIndex = 1; @@ -67,7 +68,7 @@ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage"); buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; - buttonLeft.Location = new Point(751, 400); + buttonLeft.Location = new Point(751, 420); buttonLeft.Name = "buttonLeft"; buttonLeft.Size = new Size(30, 30); buttonLeft.TabIndex = 2; @@ -79,7 +80,7 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage"); buttonUp.BackgroundImageLayout = ImageLayout.Zoom; - buttonUp.Location = new Point(777, 372); + buttonUp.Location = new Point(777, 392); buttonUp.Name = "buttonUp"; buttonUp.Size = new Size(30, 30); buttonUp.TabIndex = 3; @@ -91,7 +92,7 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage"); buttonDown.BackgroundImageLayout = ImageLayout.Zoom; - buttonDown.Location = new Point(777, 400); + buttonDown.Location = new Point(777, 420); buttonDown.Name = "buttonDown"; buttonDown.Size = new Size(30, 30); buttonDown.TabIndex = 4; @@ -103,7 +104,7 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage"); buttonRight.BackgroundImageLayout = ImageLayout.Zoom; - buttonRight.Location = new Point(808, 400); + buttonRight.Location = new Point(808, 420); buttonRight.Name = "buttonRight"; buttonRight.Size = new Size(30, 30); buttonRight.TabIndex = 5; @@ -140,9 +141,20 @@ buttonCreate_Pro.UseVisualStyleBackColor = true; buttonCreate_Pro.Click += buttonCreate_Pro_Click; // + // buttonSelectCar + // + buttonSelectCar.Location = new Point(705, 99); + buttonSelectCar.Name = "buttonSelectCar"; + buttonSelectCar.Size = new Size(133, 23); + buttonSelectCar.TabIndex = 11; + buttonSelectCar.Text = "Выбор тепловоза"; + buttonSelectCar.UseVisualStyleBackColor = true; + buttonSelectCar.Click += buttonSelectCar_Click; + // // WarmlyLocomotiveForm // - ClientSize = new Size(884, 461); + ClientSize = new Size(884, 481); + Controls.Add(buttonSelectCar); Controls.Add(buttonCreate_Pro); Controls.Add(buttonStep); Controls.Add(comboBoxWarmlyLocomotive); @@ -173,5 +185,6 @@ private ComboBox comboBoxWarmlyLocomotive; private Button buttonStep; private Button buttonCreate_Pro; + private Button buttonSelectCar; } } \ No newline at end of file