From 46283ecf8f60c3feeb8fb0cccb218bfd3e07cf53 Mon Sep 17 00:00:00 2001 From: Itos Date: Thu, 3 Oct 2024 00:43:12 +0300 Subject: [PATCH] Lab5_DONE --- .../Drawings/DrawingTruck.cs | 23 +- .../Entities/EntityGasolineTanker.cs | 5 + .../Entities/EntityTruck.cs | 5 + .../FormTruckCollection.Designer.cs | 7 +- .../FormTruckCollection.cs | 41 +- .../FormTruckConfig.Designer.cs | 382 ++++++++++++++++++ .../ProjectGasolineTanker/FormTruckConfig.cs | 151 +++++++ .../FormTruckConfig.resx | 60 +++ .../Generic/SetGeneric.cs | 5 +- .../Generic/TruckGenericCollection.cs | 3 - .../Generic/TruckGenericStorage.cs | 4 +- .../MovementStratg/AbstractStrategy.cs | 7 +- .../MovementStratg/IMoveableObject.cs | 1 + .../MovementStratg/MoveToCenter.cs | 4 +- 14 files changed, 659 insertions(+), 39 deletions(-) create mode 100644 GasolineTanker/ProjectGasolineTanker/FormTruckConfig.Designer.cs create mode 100644 GasolineTanker/ProjectGasolineTanker/FormTruckConfig.cs create mode 100644 GasolineTanker/ProjectGasolineTanker/FormTruckConfig.resx diff --git a/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs b/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs index 977c7f6..a833630 100644 --- a/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs +++ b/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs @@ -9,7 +9,7 @@ using ProjectGasolineTanker.MovementStratg; namespace ProjectGasolineTanker.Drawings { - + public class DrawingTruck { public IMoveableObject GetMoveableObject => new DrawingObjectTruck(this); @@ -27,7 +27,7 @@ namespace ProjectGasolineTanker.Drawings protected readonly int _tankerWidth = 130; protected readonly int _tankerHeight = 70; - + public int GetPosX => _startPosX; public int GetPosY => _startPosY; @@ -38,7 +38,6 @@ namespace ProjectGasolineTanker.Drawings public DrawingTruck(int speed, double weight, Color bodyColor, int width, int height) { - if (width < _tankerWidth || height < _tankerHeight) { return; @@ -50,7 +49,7 @@ namespace ProjectGasolineTanker.Drawings protected DrawingTruck(int speed, double weight, Color bodyColor, int width, int height, int tankerWidth, int tankerHeight) { - + // TODO: Продумать проверки if (width < _tankerWidth || height < _tankerHeight) { return; @@ -117,7 +116,7 @@ namespace ProjectGasolineTanker.Drawings Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(EntityTruck.BodyColor); - g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 11, 71, 28); + g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 11, 71, 28); g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 20, 71, 9); g.DrawRectangle(pen, _startPosX + 29, _startPosY + 11, 71, 28); @@ -126,7 +125,7 @@ namespace ProjectGasolineTanker.Drawings Brush additionalBrush1 = new SolidBrush(EntityTruck.BodyColor); - //кабина + g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 24, 16); g.FillRectangle(additionalBrush1, _startPosX + 124, _startPosY + 10, 9, 16); g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 33, 16); @@ -145,6 +144,7 @@ namespace ProjectGasolineTanker.Drawings g.FillRectangle(additionalBrush2, _startPosX + 4, _startPosY + 40, 130, 25); g.DrawLine(pen, _startPosX + 4, _startPosY + 65, _startPosX + 25, _startPosY + 40); + Brush gr = new SolidBrush(Color.Gray); g.FillEllipse(additionalBrush, _startPosX + 15, _startPosY + 50, 26, 26); @@ -157,6 +157,7 @@ namespace ProjectGasolineTanker.Drawings g.DrawEllipse(pen, _startPosX + 110, _startPosY + 55, 22, 22); } + public bool CanMove(DirectionType direction) { if (EntityTruck == null) @@ -170,12 +171,18 @@ namespace ProjectGasolineTanker.Drawings //вверх DirectionType.Up => _startPosY - EntityTruck.Step > 0, // вправо - DirectionType.Right => _startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth, + DirectionType.Right => _startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth,// TODO: Продумать логику //вниз - DirectionType.Down => _startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight, + DirectionType.Down => _startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight,// TODO: Продумать логику _ => false, }; } + + public void ChangePictureSize(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + } } } diff --git a/GasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs b/GasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs index ce11941..4c99f3e 100644 --- a/GasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs +++ b/GasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs @@ -23,6 +23,11 @@ namespace ProjectGasolineTanker.Entities Tank = tank; Wheel = wheel; } + + public void ChangeAdditionalColor(Color additionalColor) + { + Add_Color = additionalColor; + } } } diff --git a/GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs b/GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs index 9466d19..c6d24cd 100644 --- a/GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs +++ b/GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs @@ -25,5 +25,10 @@ namespace ProjectGasolineTanker.Entities BodyColor = bodyColor; } + public void ChangeBodyColor(Color color) + { + BodyColor = color; + } + } } diff --git a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs index ed7380f..dda3d3b 100644 --- a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs +++ b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs @@ -57,10 +57,10 @@ // // pictureBoxCollection // - this.pictureBoxCollection.Location = new System.Drawing.Point(1, 12); + this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); this.pictureBoxCollection.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(668, 381); + this.pictureBoxCollection.Size = new System.Drawing.Size(715, 581); this.pictureBoxCollection.TabIndex = 1; this.pictureBoxCollection.TabStop = false; // @@ -148,7 +148,6 @@ this.buttonDeleteStorage.TabIndex = 10; this.buttonDeleteStorage.Text = "Удалить набор"; this.buttonDeleteStorage.UseVisualStyleBackColor = true; - this.buttonDeleteStorage.TabIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged); this.buttonDeleteStorage.Click += new System.EventHandler(this.buttonDeleteStorage_Click); // // textBoxStorageName @@ -162,7 +161,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(911, 689); + this.ClientSize = new System.Drawing.Size(911, 591); this.Controls.Add(this.textBoxStorageName); this.Controls.Add(this.buttonDeleteStorage); this.Controls.Add(this.buttonAddStorage); diff --git a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs index 4f48e79..2a0dcfd 100644 --- a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs +++ b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs @@ -16,7 +16,7 @@ namespace ProjectGasolineTanker { public partial class FormTruckCollection : Form { - + // Набор объектов private readonly TruckGenericStorage _storage; public FormTruckCollection() @@ -25,6 +25,7 @@ namespace ProjectGasolineTanker _storage = new TruckGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); } + // заполнение лист бокс private void ReloadObjects() { int index = listBoxStorages.SelectedIndex; @@ -44,6 +45,7 @@ namespace ProjectGasolineTanker } + // добавить набор в коллекцию private void buttonAddStorage_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxStorageName.Text)) @@ -55,11 +57,13 @@ namespace ProjectGasolineTanker ReloadObjects(); } + // выбрать набор private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e) { pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTruck(); } + // удалить набор private void buttonDeleteStorage_Click(object sender, EventArgs e) { if (listBoxStorages.SelectedIndex == -1) @@ -74,6 +78,15 @@ namespace ProjectGasolineTanker } private void buttonAddTruck_Click(object sender, EventArgs e) + { + + var formTruckConfig = new FormTruckConfig(); + + formTruckConfig.AddEvent(AddTruck); + formTruckConfig.Show(); + } + + private void AddTruck(DrawingTruck selectedTruck) { if (listBoxStorages.SelectedIndex == -1) { @@ -85,22 +98,19 @@ namespace ProjectGasolineTanker { return; } - FormGasolineTanker form = new(); - - if (form.ShowDialog() == DialogResult.OK) + selectedTruck.ChangePictureSize(pictureBoxCollection.Width, pictureBoxCollection.Height); + if (obj + selectedTruck != -1) { - if (obj + form.SelectedTruck != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowTruck(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowTruck(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } + private void buttonDeleteTruck_Click(object sender, EventArgs e) { if (listBoxStorages.SelectedIndex == -1) @@ -126,7 +136,7 @@ namespace ProjectGasolineTanker MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (obj - pos) + if (obj - pos) { MessageBox.Show("Объект удален"); pictureBoxCollection.Image = obj.ShowTruck(); @@ -137,6 +147,7 @@ namespace ProjectGasolineTanker } } + // обновить рисунок по набору private void buttonUpdate_Click(object sender, EventArgs e) { if (listBoxStorages.SelectedIndex == -1) @@ -151,5 +162,7 @@ namespace ProjectGasolineTanker } pictureBoxCollection.Image = obj.ShowTruck(); } + + } } diff --git a/GasolineTanker/ProjectGasolineTanker/FormTruckConfig.Designer.cs b/GasolineTanker/ProjectGasolineTanker/FormTruckConfig.Designer.cs new file mode 100644 index 0000000..beec2ad --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/FormTruckConfig.Designer.cs @@ -0,0 +1,382 @@ +namespace ProjectGasolineTanker +{ + partial class FormTruckConfig + { + /// + /// 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.groupBoxConfig = new System.Windows.Forms.GroupBox(); + this.labelAdvancedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColor = new System.Windows.Forms.GroupBox(); + this.panelLightBlue = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelOrange = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxWheel = new System.Windows.Forms.CheckBox(); + this.checkBoxTanker = new System.Windows.Forms.CheckBox(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.panelObject = new System.Windows.Forms.Panel(); + this.labelAdditionalColor = new System.Windows.Forms.Label(); + this.labelMainColor = new System.Windows.Forms.Label(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxConfig.SuspendLayout(); + this.groupBoxColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.panelObject.SuspendLayout(); + this.SuspendLayout(); + // + // groupBoxConfig + // + this.groupBoxConfig.Controls.Add(this.labelAdvancedObject); + this.groupBoxConfig.Controls.Add(this.labelSimpleObject); + this.groupBoxConfig.Controls.Add(this.groupBoxColor); + this.groupBoxConfig.Controls.Add(this.checkBoxWheel); + this.groupBoxConfig.Controls.Add(this.checkBoxTanker); + this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed); + this.groupBoxConfig.Controls.Add(this.numericUpDownWeight); + this.groupBoxConfig.Controls.Add(this.labelWeight); + this.groupBoxConfig.Controls.Add(this.labelSpeed); + this.groupBoxConfig.Location = new System.Drawing.Point(14, 48); + this.groupBoxConfig.Name = "groupBoxConfig"; + this.groupBoxConfig.Size = new System.Drawing.Size(570, 251); + this.groupBoxConfig.TabIndex = 0; + this.groupBoxConfig.TabStop = false; + this.groupBoxConfig.Text = "Параметры"; + // + // labelAdvancedObject + // + this.labelAdvancedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAdvancedObject.Location = new System.Drawing.Point(440, 188); + this.labelAdvancedObject.Name = "labelAdvancedObject"; + this.labelAdvancedObject.Size = new System.Drawing.Size(120, 30); + this.labelAdvancedObject.TabIndex = 8; + this.labelAdvancedObject.Text = "Продвинутый"; + this.labelAdvancedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAdvancedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(283, 188); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(120, 30); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // groupBoxColor + // + this.groupBoxColor.Controls.Add(this.panelLightBlue); + this.groupBoxColor.Controls.Add(this.panelBlue); + this.groupBoxColor.Controls.Add(this.panelPurple); + this.groupBoxColor.Controls.Add(this.panelGray); + this.groupBoxColor.Controls.Add(this.panelGreen); + this.groupBoxColor.Controls.Add(this.panelYellow); + this.groupBoxColor.Controls.Add(this.panelOrange); + this.groupBoxColor.Controls.Add(this.panelRed); + this.groupBoxColor.Location = new System.Drawing.Point(283, 32); + this.groupBoxColor.Name = "groupBoxColor"; + this.groupBoxColor.Size = new System.Drawing.Size(277, 145); + this.groupBoxColor.TabIndex = 6; + this.groupBoxColor.TabStop = false; + this.groupBoxColor.Text = "Цвета"; + // + // panelLightBlue + // + this.panelLightBlue.BackColor = System.Drawing.Color.Indigo; + this.panelLightBlue.Location = new System.Drawing.Point(5, 85); + this.panelLightBlue.Name = "panelLightBlue"; + this.panelLightBlue.Size = new System.Drawing.Size(50, 40); + this.panelLightBlue.TabIndex = 0; + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Black; + this.panelBlue.Location = new System.Drawing.Point(75, 85); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(50, 40); + this.panelBlue.TabIndex = 0; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Fuchsia; + this.panelPurple.Location = new System.Drawing.Point(145, 85); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(50, 40); + this.panelPurple.TabIndex = 0; + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(215, 85); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(50, 40); + this.panelGray.TabIndex = 0; + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.panelGreen.Location = new System.Drawing.Point(215, 25); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(50, 40); + this.panelGreen.TabIndex = 0; + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Gold; + this.panelYellow.Location = new System.Drawing.Point(145, 25); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(50, 40); + this.panelYellow.TabIndex = 0; + // + // panelOrange + // + this.panelOrange.BackColor = System.Drawing.Color.Cyan; + this.panelOrange.Location = new System.Drawing.Point(75, 25); + this.panelOrange.Name = "panelOrange"; + this.panelOrange.Size = new System.Drawing.Size(50, 40); + this.panelOrange.TabIndex = 0; + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.LawnGreen; + this.panelRed.Location = new System.Drawing.Point(5, 25); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(50, 40); + this.panelRed.TabIndex = 0; + // + // checkBoxWheel + // + this.checkBoxWheel.AutoSize = true; + this.checkBoxWheel.Location = new System.Drawing.Point(13, 149); + this.checkBoxWheel.Name = "checkBoxWheel"; + this.checkBoxWheel.Size = new System.Drawing.Size(173, 24); + this.checkBoxWheel.TabIndex = 5; + this.checkBoxWheel.Text = "Наличие доп колеса"; + this.checkBoxWheel.UseVisualStyleBackColor = true; + // + // checkBoxTanker + // + this.checkBoxTanker.AutoSize = true; + this.checkBoxTanker.Location = new System.Drawing.Point(13, 119); + this.checkBoxTanker.Name = "checkBoxTanker"; + this.checkBoxTanker.Size = new System.Drawing.Size(128, 24); + this.checkBoxTanker.TabIndex = 4; + this.checkBoxTanker.Text = "Наличие бака"; + this.checkBoxTanker.UseVisualStyleBackColor = true; + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(94, 32); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(150, 27); + this.numericUpDownSpeed.TabIndex = 3; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(94, 83); + this.numericUpDownWeight.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownWeight.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(150, 27); + this.numericUpDownWeight.TabIndex = 2; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(6, 85); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(36, 20); + this.labelWeight.TabIndex = 1; + this.labelWeight.Text = "Вес:"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(6, 32); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(76, 20); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость:"; + // + // pictureBoxObject + // + this.pictureBoxObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.pictureBoxObject.Location = new System.Drawing.Point(35, 84); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(327, 205); + this.pictureBoxObject.TabIndex = 1; + this.pictureBoxObject.TabStop = false; + // + // panelObject + // + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.labelAdditionalColor); + this.panelObject.Controls.Add(this.labelMainColor); + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Location = new System.Drawing.Point(613, 29); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(401, 301); + this.panelObject.TabIndex = 2; + this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); + // + // labelAdditionalColor + // + this.labelAdditionalColor.AllowDrop = true; + this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAdditionalColor.Location = new System.Drawing.Point(233, 19); + this.labelAdditionalColor.Name = "labelAdditionalColor"; + this.labelAdditionalColor.Size = new System.Drawing.Size(90, 50); + this.labelAdditionalColor.TabIndex = 3; + this.labelAdditionalColor.Text = "Доп. цвет"; + this.labelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAdditionalColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAdditionalColor_DragDrop); + this.labelAdditionalColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelAdditionalColor_DragEnter); + // + // labelMainColor + // + this.labelMainColor.AllowDrop = true; + this.labelMainColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelMainColor.Location = new System.Drawing.Point(77, 19); + this.labelMainColor.Name = "labelMainColor"; + this.labelMainColor.Size = new System.Drawing.Size(90, 50); + this.labelMainColor.TabIndex = 2; + this.labelMainColor.Text = "Цвет"; + this.labelMainColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelMainColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelMainColor_DragDrop); + this.labelMainColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelMainColor_DragEnter); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(689, 337); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 3; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(846, 339); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // FormTruckConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1032, 383); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxConfig); + this.Name = "FormTruckConfig"; + this.Text = "FormTruckConfig"; + this.groupBoxConfig.ResumeLayout(false); + this.groupBoxConfig.PerformLayout(); + this.groupBoxColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.panelObject.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxConfig; + private NumericUpDown numericUpDownSpeed; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private Label labelSpeed; + private CheckBox checkBoxWheel; + private CheckBox checkBoxTanker; + private GroupBox groupBoxColor; + private Panel panelLightBlue; + private Panel panelBlue; + private Panel panelPurple; + private Panel panelGray; + private Panel panelGreen; + private Panel panelYellow; + private Panel panelOrange; + private Panel panelRed; + private Label labelAdvancedObject; + private Label labelSimpleObject; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelMainColor; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/GasolineTanker/ProjectGasolineTanker/FormTruckConfig.cs b/GasolineTanker/ProjectGasolineTanker/FormTruckConfig.cs new file mode 100644 index 0000000..b8e6ba6 --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/FormTruckConfig.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.Entities; + +namespace ProjectGasolineTanker +{ + public partial class FormTruckConfig : Form + { + + DrawingTruck? _truck = null; + + private event Action? EventAddTruck; + + + public FormTruckConfig() + { + InitializeComponent(); + panelRed.MouseDown += PanelColor_MouseDown; + panelOrange.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelLightBlue.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + buttonCancel.Click += (s, e) => Close(); + } + + private void DrawTruck() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _truck?.SetPosition(5, 5); + _truck?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + public void AddEvent(Action ev) + { + if (EventAddTruck == null) + { + EventAddTruck = ev; + } + else + { + EventAddTruck += ev; + } + } + + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, + DragDropEffects.Move | DragDropEffects.Copy); + } + + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _truck = new DrawingTruck( + (int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, + Color.White, + pictureBoxObject.Width, pictureBoxObject.Height); + break; + + case "labelAdvancedObject": + _truck = new DrawingGasolineTanker( + (int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, + Color.White, Color.Black, + checkBoxTanker.Checked, checkBoxWheel.Checked, + pictureBoxObject.Width, pictureBoxObject.Height); + break; + } + DrawTruck(); + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, + DragDropEffects.Move | DragDropEffects.Copy); + } + + private void LabelMainColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color)) && _truck != null) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void LabelMainColor_DragDrop(object sender, DragEventArgs e) + { + var color = (Color)e.Data.GetData(typeof(Color)); + _truck.EntityTruck.ChangeBodyColor(color); + DrawTruck(); + } + + private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color)) && _truck != null && _truck is DrawingGasolineTanker) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + var color = (Color)e.Data.GetData(typeof(Color)); + + EntityGasolineTanker? _gasolinetanker = _truck.EntityTruck as EntityGasolineTanker; + _gasolinetanker.ChangeAdditionalColor(color); + DrawTruck(); + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + EventAddTruck?.Invoke(_truck); + Close(); + } + } +} diff --git a/GasolineTanker/ProjectGasolineTanker/FormTruckConfig.resx b/GasolineTanker/ProjectGasolineTanker/FormTruckConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/FormTruckConfig.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/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs b/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs index 2375bf6..fec21af 100644 --- a/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs +++ b/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs @@ -26,18 +26,21 @@ namespace ProjectGasolineTanker.Generic _places.Insert(0, truck); return 0; } - + public bool Insert(T truck, int position) { + if (position < 0 || position >= Count || Count >= _maxCount) { return false; } + // TODO вставка по позиции _places.Insert(position, truck); return true; } + public bool Remove(int position) { if (position < 0 || position >= Count) diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs b/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs index f72cdb9..491127c 100644 --- a/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs +++ b/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs @@ -20,8 +20,6 @@ namespace ProjectGasolineTanker.Generic private readonly SetGeneric _collection; - - public TruckGenericCollection(int picWidth, int picHeight) { int width = picWidth / _placeSizeWidth; @@ -69,7 +67,6 @@ namespace ProjectGasolineTanker.Generic { for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) { - // линия разметки gr.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); gr.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); } diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericStorage.cs b/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericStorage.cs index 26f5f06..ad9f9f4 100644 --- a/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericStorage.cs +++ b/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericStorage.cs @@ -12,9 +12,7 @@ namespace ProjectGasolineTanker.Generic { readonly Dictionary> _TruckStorages; public List Keys => _TruckStorages.Keys.ToList(); - //Ширина окна отрисовки private readonly int _pictureWidth; - //Высота окна отрисовки private readonly int _pictureHeight; public TruckGenericStorage(int pictureWidth, int pictureHeight) @@ -26,7 +24,6 @@ namespace ProjectGasolineTanker.Generic public void AddSet(string name) { - foreach (string nameStorage in Keys) { if (nameStorage == name) @@ -52,6 +49,7 @@ namespace ProjectGasolineTanker.Generic { get { + // TODO Продумать логику получения набора if (_TruckStorages.ContainsKey(ind)) { return _TruckStorages[ind]; diff --git a/GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs index c0b8d05..f856d23 100644 --- a/GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs @@ -11,6 +11,7 @@ namespace ProjectGasolineTanker.MovementStratg { public abstract class AbstractStrategy { + private IMoveableObject? _moveableObject; private Status _state = Status.NotInit; @@ -20,7 +21,7 @@ namespace ProjectGasolineTanker.MovementStratg protected int FieldHeight { get; private set; } public Status GetStatus() { return _state; } - + public void SetData(IMoveableObject moveableObject, int width, int height) { if (moveableObject == null) @@ -53,9 +54,9 @@ namespace ProjectGasolineTanker.MovementStratg protected bool MoveRight() => MoveTo(DirectionType.Right); protected bool MoveUp() => MoveTo(DirectionType.Up); - + protected bool MoveDown() => MoveTo(DirectionType.Down); - + protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition; protected int? GetStep() diff --git a/GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs index e4cb7be..45ebdb1 100644 --- a/GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs @@ -17,6 +17,7 @@ namespace ProjectGasolineTanker.MovementStratg int GetStep { get; } bool CheckCanMove(DirectionType direction); + void MoveObject(DirectionType direction); } } diff --git a/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs index 082acc4..2038b2a 100644 --- a/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs @@ -6,9 +6,7 @@ using System.Threading.Tasks; namespace ProjectGasolineTanker.MovementStratg { - /// - /// Стратегия перемещения объекта в центр экрана - /// + public class MoveToCenter : AbstractStrategy { protected override bool IsTargetDestinaion()