From 9e12aee1d5dc2dd885989a9bf7bb2b36f4f410f6 Mon Sep 17 00:00:00 2001 From: AparyanLuiza Date: Thu, 30 Nov 2023 01:42:41 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20SetGeneric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectBulldozer/FormBulldozer.cs | 1 + ProjectBulldozer/Generics/SetGeneric.cs | 72 +++++++++++++++++++ ProjectBulldozer/{ => Generics}/Status.cs | 3 +- .../MovementStrategy/AbstractStrategy.cs | 4 +- 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 ProjectBulldozer/Generics/SetGeneric.cs rename ProjectBulldozer/{ => Generics}/Status.cs (65%) diff --git a/ProjectBulldozer/FormBulldozer.cs b/ProjectBulldozer/FormBulldozer.cs index ff082ce..0e8aa72 100644 --- a/ProjectBulldozer/FormBulldozer.cs +++ b/ProjectBulldozer/FormBulldozer.cs @@ -1,5 +1,6 @@ using ProjectBulldozer; using ProjectBulldozer.Drawings; +using ProjectBulldozer.Generics; using ProjectBulldozer.MovementStrategy; using System; diff --git a/ProjectBulldozer/Generics/SetGeneric.cs b/ProjectBulldozer/Generics/SetGeneric.cs new file mode 100644 index 0000000..124c3d7 --- /dev/null +++ b/ProjectBulldozer/Generics/SetGeneric.cs @@ -0,0 +1,72 @@ + + +namespace ProjectBulldozer.Generics +{ + internal class SetGeneric where T : class + { + private readonly T[] _places; + public int Count => _places.Length; + public SetGeneric(int count) + { + _places = new T[count]; + } + + /// Добавление объекта в набор + public int Insert(T tract) + { + return Insert(tract, 0); + } + + public int Insert(T tract, int position) + { + int NoEmpty = 0, temp = 0; + for (int i = position; i < Count; i++) + { + if (_places[i] != null) NoEmpty++; + } + if (NoEmpty == Count - position - 1) return -1; + + if (position < Count && position >= 0) + { + for (int j = position; j < Count; j++) + { + if (_places[j] == null) + { + temp = j; + break; + } + } + // shift right + for (int i = temp; i > position; i--) + { + _places[i] = _places[i - 1]; + } + _places[position] = tract; + return position; + } + return -1; + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент // + } + + public T? Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + if (position >= Count || position < 0) + return null; + + T tmp = _places[position]; + _places[position] = null; + return tmp; + } + //Получение объекта из набора по позиции + public T? Get(int position) + { + // TODO проверка позиции + if (position < 0 || position >= Count) return null; + return _places[position]; + } + } +} diff --git a/ProjectBulldozer/Status.cs b/ProjectBulldozer/Generics/Status.cs similarity index 65% rename from ProjectBulldozer/Status.cs rename to ProjectBulldozer/Generics/Status.cs index 419da5e..9bdd170 100644 --- a/ProjectBulldozer/Status.cs +++ b/ProjectBulldozer/Generics/Status.cs @@ -1,5 +1,4 @@ - -namespace ProjectBulldozer.MovementStrategy +namespace ProjectBulldozer.Generics { public enum Status { diff --git a/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs b/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs index 6d0644d..db330ea 100644 --- a/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs +++ b/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs @@ -1,4 +1,6 @@ -namespace ProjectBulldozer.MovementStrategy +using ProjectBulldozer.Generics; + +namespace ProjectBulldozer.MovementStrategy { /// /// Абстрактный класс стратегии -- 2.25.1 From 90ecee77357f798e6900b28e8ead55573dd85b51 Mon Sep 17 00:00:00 2001 From: AparyanLuiza Date: Thu, 30 Nov 2023 02:09:48 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20BulldozerGeneri?= =?UTF-8?q?cCollection,=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=BE=D0=B2=20=D0=BF=D1=80=D0=BE=D1=80=D0=B8=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingBulldozer.cs} | 63 +++++++----- .../{Drawings => Drawning}/DrawingTractor.cs | 40 ++++---- ProjectBulldozer/FormBulldozer.Designer.cs | 59 ++++++----- ProjectBulldozer/FormBulldozer.cs | 51 +++++++--- .../Generics/BulldozerGenericCollection.cs | 99 +++++++++++++++++++ .../MovementStrategy/DrawingObjectTractor.cs | 3 +- .../MovementStrategy/IMoveableObject.cs | 5 +- .../MovementStrategy/ObjectsParameters.cs | 10 +- ProjectBulldozer/Program.cs | 4 +- 9 files changed, 235 insertions(+), 99 deletions(-) rename ProjectBulldozer/{Drawings/DrawningBulldozer.cs => Drawning/DrawingBulldozer.cs} (52%) rename ProjectBulldozer/{Drawings => Drawning}/DrawingTractor.cs (80%) create mode 100644 ProjectBulldozer/Generics/BulldozerGenericCollection.cs diff --git a/ProjectBulldozer/Drawings/DrawningBulldozer.cs b/ProjectBulldozer/Drawning/DrawingBulldozer.cs similarity index 52% rename from ProjectBulldozer/Drawings/DrawningBulldozer.cs rename to ProjectBulldozer/Drawning/DrawingBulldozer.cs index 6edc944..e64fbc0 100644 --- a/ProjectBulldozer/Drawings/DrawningBulldozer.cs +++ b/ProjectBulldozer/Drawning/DrawingBulldozer.cs @@ -1,17 +1,19 @@ using ProjectBulldozer.Entities; - -namespace ProjectBulldozer.Drawings +namespace ProjectBulldozer.Drawning { public class DrawingBulldozer : DrawingTractor { public DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor, - bool otval, bool seifBatteries, int width, int height) : base(speed, weight, bodyColor, width, height, 129, 120) + bool horns, bool seifBatteries, int width, int height) : base(speed, weight, bodyColor, width, height, 140, 130) { if (EntityTractor != null) { - EntityTractor = new EntityBulldozer(speed, width, bodyColor, additionalColor, otval, seifBatteries); + EntityTractor = new EntityBulldozer(speed, width, bodyColor, additionalColor, horns, seifBatteries); } } + + public object Otval { get; private set; } + public override void DrawTransport(Graphics g) { if (EntityTractor is not EntityBulldozer Bulldozer) @@ -20,56 +22,63 @@ namespace ProjectBulldozer.Drawings } Pen pen = new(Color.Black); + + Brush blackBrush = new SolidBrush(Color.Black); Brush windows = new SolidBrush(Color.LightBlue); Brush bodyColor = new SolidBrush(Bulldozer.BodyColor); - Brush additionalBrush = new SolidBrush(Bulldozer.AdditionalColor); + + Brush additionalColor = new SolidBrush(Bulldozer.AdditionalColor); + Brush grayBrush = new SolidBrush(Color.Gray); - if (Bulldozer.Otval) - { - //otval - Point[] Otval = - { - new Point(_startPosX + 122, _startPosY + 55), - new Point(_startPosX + 142, _startPosY + 115), - new Point(_startPosX+ 122, _startPosY + 115), + + //otval + Point[] Otval = + { + new Point(_startPosX + 118, _startPosY + 50), + new Point(_startPosX + 148, _startPosY + 111), + new Point(_startPosX+ 118, _startPosY + 111), }; - g.FillPolygon(blackBrush, Otval); - g.DrawPolygon(pen, Otval); - } + g.FillPolygon(additionalColor, Otval); + g.DrawPolygon(pen, Otval); + //гусеницы Brush gg = new SolidBrush(Color.LightGray); - g.FillEllipse(gg, _startPosX + 19, _startPosY + 62, 100, 65); - g.DrawEllipse(pen, _startPosX + 19, _startPosY + 62, 100, 65); + g.FillEllipse(gg, _startPosX + 16, _startPosY + 65, 101, 63); + g.DrawEllipse(pen, _startPosX + 16, _startPosY + 65, 101, 63); + + - - g.FillEllipse(grayBrush, _startPosX + 65, _startPosY + 100, 15, 15); - g.DrawEllipse(pen, _startPosX + 65, _startPosY + 100, 15, 15); + g.FillEllipse(grayBrush, _startPosX + 65, _startPosY + 100, 13, 13); + g.DrawEllipse(pen, _startPosX + 65, _startPosY + 100, 13, 13); Point[] Ttt = - { - new Point(_startPosX + 18 , _startPosY + 80), - new Point(_startPosX + 18, _startPosY + 110), - new Point(_startPosX, _startPosY + 50), + { + + new Point(_startPosX + 16, _startPosY + 79), + new Point(_startPosX + 16, _startPosY + 120), + new Point(_startPosX, _startPosY + 48), }; g.FillPolygon(blackBrush, Ttt); g.DrawPolygon(pen, Ttt); + + if (Bulldozer.SeifBatteries) { - g.FillRectangle(blackBrush, _startPosX + 78, _startPosY + 30, 10, 10); + g.FillRectangle(blackBrush, _startPosX + 110, _startPosY + 60, 5, 10); } base.DrawTransport(g); } } -} +} \ No newline at end of file diff --git a/ProjectBulldozer/Drawings/DrawingTractor.cs b/ProjectBulldozer/Drawning/DrawingTractor.cs similarity index 80% rename from ProjectBulldozer/Drawings/DrawingTractor.cs rename to ProjectBulldozer/Drawning/DrawingTractor.cs index 4c7366d..422e20d 100644 --- a/ProjectBulldozer/Drawings/DrawingTractor.cs +++ b/ProjectBulldozer/Drawning/DrawingTractor.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + using Bulldozer; using ProjectBulldozer.Entities; -using ProjectBulldozer.Properties; +using ProjectBulldozer.MovementStrategy; -namespace ProjectBulldozer.Drawings + +namespace ProjectBulldozer.Drawning { public class DrawingTractor { @@ -21,15 +18,15 @@ namespace ProjectBulldozer.Drawings protected int _startPosY; - private int tractWidth; - protected readonly int _tractWidth = 140; + protected readonly int _tractWidth = 120; - protected readonly int _tractHeight = 123; + protected readonly int _tractHeight = 110; public int GetPosX => _startPosX; public int GetPosY => _startPosY; public int GetWidth => _tractWidth; public int GetHeight => _tractHeight; + public IMoveableObject GetMoveableObject => new DrawingObjectTractor(this); public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth) { if (width < _tractWidth || heigth < _tractHeight) @@ -60,7 +57,7 @@ namespace ProjectBulldozer.Drawings { if (x < 0 || x + _tractWidth > _pictureWidth) { - x = _pictureWidth - tractWidth; + x = _pictureWidth - _tractWidth; } if (y < 0 || y + _tractHeight > _pictureHeight) { @@ -111,6 +108,7 @@ namespace ProjectBulldozer.Drawings if (EntityTractor == null) return; } + Pen pen = new(Color.Black); Brush brownBrush = new SolidBrush(Color.Brown); Brush windows = new SolidBrush(Color.LightYellow); @@ -119,30 +117,30 @@ namespace ProjectBulldozer.Drawings Brush grayBrush = new SolidBrush(Color.Gray); //основное тело - g.FillRectangle(bodyColor, _startPosX + 20, _startPosY + 40, 100, 60); - g.DrawRectangle(pen, _startPosX + 20, _startPosY + 40, 100, 60); + g.FillRectangle(bodyColor, _startPosX + 18, _startPosY + 42, 99, 56); + g.DrawRectangle(pen, _startPosX + 18, _startPosY + 42, 99, 56); //кабина водителя - g.FillRectangle(windows, _startPosX + 20, _startPosY, 40, 40); - g.DrawRectangle(pen, _startPosX + 20, _startPosY, 40, 40); + g.FillRectangle(windows, _startPosX + 18, _startPosY + 4 , 37, 37); + g.DrawRectangle(pen, _startPosX + 18, _startPosY +4 , 37, 37); //колеса - g.FillEllipse(grayBrush, _startPosX + 20, _startPosY + 74, 47, 47); - g.DrawEllipse(pen, _startPosX + 20, _startPosY + 74, 47, 47); + g.FillEllipse(grayBrush, _startPosX + 19, _startPosY + 76, 45, 45); + g.DrawEllipse(pen, _startPosX + 19, _startPosY + 76, 45, 45); - g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 85, 35, 35); - g.DrawEllipse(pen, _startPosX + 80, _startPosY + 85, 35, 35); + g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 87, 33, 33); + g.DrawEllipse(pen, _startPosX + 80, _startPosY + 87, 33, 33); //выхлопная труба - g.FillRectangle(brownBrush, _startPosX + 90, _startPosY, 15, 40); - g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, 40); + g.FillRectangle(brownBrush, _startPosX + 88, _startPosY+ 6, 14, 35); + g.DrawRectangle(pen, _startPosX + 88, _startPosY + 6, 14, 35); } diff --git a/ProjectBulldozer/FormBulldozer.Designer.cs b/ProjectBulldozer/FormBulldozer.Designer.cs index d69ea4c..aabda7f 100644 --- a/ProjectBulldozer/FormBulldozer.Designer.cs +++ b/ProjectBulldozer/FormBulldozer.Designer.cs @@ -1,6 +1,6 @@ namespace Bulldozer { - partial class Bulldozer + partial class FormBulldozer { /// /// Required designer variable. @@ -37,6 +37,7 @@ comboBoxStrategy = new ComboBox(); buttonCreateTractor = new Button(); buttonStep = new Button(); + ButtonSelect_Tractor = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit(); SuspendLayout(); // @@ -46,7 +47,7 @@ pictureBoxBulldozer.Location = new Point(0, 0); pictureBoxBulldozer.Margin = new Padding(2); pictureBoxBulldozer.Name = "pictureBoxBulldozer"; - pictureBoxBulldozer.Size = new Size(869, 307); + pictureBoxBulldozer.Size = new Size(870, 390); pictureBoxBulldozer.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxBulldozer.TabIndex = 0; pictureBoxBulldozer.TabStop = false; @@ -54,11 +55,10 @@ // buttonCreateBulldozer // buttonCreateBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateBulldozer.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point); - buttonCreateBulldozer.Location = new Point(131, 249); + buttonCreateBulldozer.Location = new Point(11, 332); buttonCreateBulldozer.Margin = new Padding(2); buttonCreateBulldozer.Name = "buttonCreateBulldozer"; - buttonCreateBulldozer.Size = new Size(100, 47); + buttonCreateBulldozer.Size = new Size(95, 48); buttonCreateBulldozer.TabIndex = 1; buttonCreateBulldozer.Text = "Создать булльдозер"; buttonCreateBulldozer.UseVisualStyleBackColor = true; @@ -69,10 +69,10 @@ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = ProjectBulldozer.Properties.Resources.left1; buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; - buttonLeft.Location = new Point(764, 271); + buttonLeft.Location = new Point(767, 353); buttonLeft.Margin = new Padding(2); buttonLeft.Name = "buttonLeft"; - buttonLeft.Size = new Size(26, 25); + buttonLeft.Size = new Size(30, 27); buttonLeft.TabIndex = 2; buttonLeft.UseVisualStyleBackColor = true; buttonLeft.Click += buttonMove_Click; @@ -82,10 +82,10 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = ProjectBulldozer.Properties.Resources.up1; buttonUp.BackgroundImageLayout = ImageLayout.Zoom; - buttonUp.Location = new Point(792, 240); + buttonUp.Location = new Point(801, 320); buttonUp.Margin = new Padding(2); buttonUp.Name = "buttonUp"; - buttonUp.Size = new Size(30, 27); + buttonUp.Size = new Size(34, 28); buttonUp.TabIndex = 3; buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += buttonMove_Click; @@ -95,10 +95,10 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = ProjectBulldozer.Properties.Resources.right1; buttonRight.BackgroundImageLayout = ImageLayout.Zoom; - buttonRight.Location = new Point(826, 271); + buttonRight.Location = new Point(837, 353); buttonRight.Margin = new Padding(2); buttonRight.Name = "buttonRight"; - buttonRight.Size = new Size(27, 25); + buttonRight.Size = new Size(28, 26); buttonRight.TabIndex = 4; buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += buttonMove_Click; @@ -108,10 +108,10 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = ProjectBulldozer.Properties.Resources.down1; buttonDown.BackgroundImageLayout = ImageLayout.Zoom; - buttonDown.Location = new Point(794, 271); + buttonDown.Location = new Point(801, 353); buttonDown.Margin = new Padding(2); buttonDown.Name = "buttonDown"; - buttonDown.Size = new Size(30, 25); + buttonDown.Size = new Size(32, 27); buttonDown.TabIndex = 5; buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += buttonMove_Click; @@ -120,24 +120,22 @@ // comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxStrategy.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point); comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "К центру", "В угол" }); - comboBoxStrategy.Location = new Point(693, 10); + comboBoxStrategy.Location = new Point(740, 8); comboBoxStrategy.Margin = new Padding(2); comboBoxStrategy.Name = "comboBoxStrategy"; - comboBoxStrategy.Size = new Size(150, 25); + comboBoxStrategy.Size = new Size(113, 23); comboBoxStrategy.TabIndex = 6; comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged; // // buttonCreateTractor // buttonCreateTractor.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateTractor.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point); - buttonCreateTractor.Location = new Point(11, 249); + buttonCreateTractor.Location = new Point(122, 332); buttonCreateTractor.Margin = new Padding(2); buttonCreateTractor.Name = "buttonCreateTractor"; - buttonCreateTractor.Size = new Size(106, 47); + buttonCreateTractor.Size = new Size(81, 47); buttonCreateTractor.TabIndex = 7; buttonCreateTractor.Text = "Создать трактор"; buttonCreateTractor.UseVisualStyleBackColor = true; @@ -146,21 +144,33 @@ // buttonStep // buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonStep.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point); buttonStep.Location = new Point(755, 39); buttonStep.Margin = new Padding(2); buttonStep.Name = "buttonStep"; - buttonStep.Size = new Size(88, 34); + buttonStep.Size = new Size(88, 20); buttonStep.TabIndex = 8; buttonStep.Text = "Шаг"; buttonStep.UseVisualStyleBackColor = true; buttonStep.Click += buttonStep_Click; // - // Bulldozer + // ButtonSelect_Tractor + // + ButtonSelect_Tractor.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonSelect_Tractor.Location = new Point(755, 63); + ButtonSelect_Tractor.Margin = new Padding(2); + ButtonSelect_Tractor.Name = "ButtonSelect_Tractor"; + ButtonSelect_Tractor.Size = new Size(88, 23); + ButtonSelect_Tractor.TabIndex = 9; + ButtonSelect_Tractor.Text = "Выбрать"; + ButtonSelect_Tractor.UseVisualStyleBackColor = true; + ButtonSelect_Tractor.Click += ButtonSelect_Tractor_Click; + // + // FormBulldozer // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(869, 307); + ClientSize = new Size(870, 390); + Controls.Add(ButtonSelect_Tractor); Controls.Add(buttonStep); Controls.Add(buttonCreateTractor); Controls.Add(comboBoxStrategy); @@ -171,7 +181,7 @@ Controls.Add(buttonCreateBulldozer); Controls.Add(pictureBoxBulldozer); Margin = new Padding(2); - Name = "Bulldozer"; + Name = "FormBulldozer"; StartPosition = FormStartPosition.CenterScreen; Text = "Bulldozer"; ((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).EndInit(); @@ -190,5 +200,6 @@ private ComboBox comboBoxStrategy; private Button buttonCreateTractor; private Button buttonStep; + private Button ButtonSelect_Tractor; } } \ No newline at end of file diff --git a/ProjectBulldozer/FormBulldozer.cs b/ProjectBulldozer/FormBulldozer.cs index 0e8aa72..9a4325d 100644 --- a/ProjectBulldozer/FormBulldozer.cs +++ b/ProjectBulldozer/FormBulldozer.cs @@ -1,21 +1,23 @@ using ProjectBulldozer; -using ProjectBulldozer.Drawings; +using ProjectBulldozer.Drawning; using ProjectBulldozer.Generics; using ProjectBulldozer.MovementStrategy; -using System; namespace Bulldozer { - public partial class Bulldozer : Form + public partial class FormBulldozer : Form { private DrawingTractor? _drawingTractor; private AbstractStrategy? _abstractStrategy; + public DrawingTractor? SelectedTractor { get; private set; } - public Bulldozer() + public FormBulldozer() { InitializeComponent(); + _abstractStrategy = null; + SelectedTractor = null; } private void Draw() @@ -33,9 +35,24 @@ namespace Bulldozer private void buttonCreateBulldozer_Click(object sender, EventArgs e) { Random random = new Random(); - _drawingTractor = new DrawingBulldozer(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)), + + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + + ColorDialog colorDialog = new ColorDialog(); + + if (colorDialog.ShowDialog() == DialogResult.OK) + { + color = colorDialog.Color; + } + + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + + if (colorDialog.ShowDialog() == DialogResult.OK) + { + dopColor = colorDialog.Color; + } + + _drawingTractor = new DrawingBulldozer(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); _drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100)); @@ -45,8 +62,13 @@ namespace Bulldozer private void buttonCreateTractor_Click(object sender, EventArgs e) { Random rnd = new Random(); - _drawingTractor = new DrawingTractor(rnd.Next(100, 300), rnd.Next(1000, 3000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog colorDialog = new ColorDialog(); + if (colorDialog.ShowDialog() == DialogResult.OK) + { + color = colorDialog.Color; + } + _drawingTractor = new DrawingTractor(rnd.Next(100, 300), rnd.Next(1000, 3000), color, pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); _drawingTractor.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100)); Draw(); @@ -95,15 +117,14 @@ namespace Bulldozer { return; } - _abstractStrategy.SetData(new - DrawingObjectTractor(_drawingTractor), pictureBoxBulldozer.Width, + _abstractStrategy.SetData(_drawingTractor.GetMoveableObject, pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); - comboBoxStrategy.Enabled = false; } if (_abstractStrategy == null) { return; } + comboBoxStrategy.Enabled = false; _abstractStrategy.MakeStep(); Draw(); if (_abstractStrategy.GetStatus() == Status.Finish) @@ -113,6 +134,12 @@ namespace Bulldozer } } + private void ButtonSelect_Tractor_Click(object sender, EventArgs e) + { + SelectedTractor = _drawingTractor; + DialogResult = DialogResult.OK; + } + private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e) { diff --git a/ProjectBulldozer/Generics/BulldozerGenericCollection.cs b/ProjectBulldozer/Generics/BulldozerGenericCollection.cs new file mode 100644 index 0000000..29fc021 --- /dev/null +++ b/ProjectBulldozer/Generics/BulldozerGenericCollection.cs @@ -0,0 +1,99 @@ +using ProjectBulldozer.MovementStrategy; +using ProjectBulldozer.Drawning; +namespace ProjectBulldozer.Generics +{ + internal class TractorGenericCollection where T : DrawingTractor where U : IMoveableObject + { + //ширина /высота окна + private readonly int _pictureWidth; + private readonly int _pictureHeight; + //ширина /высота занимаемого места + private readonly int _placeSizeWidth = 170; + private readonly int _placeSizeHeight = 130; + /// Набор объектов + private readonly SetGeneric _collection; + public TractorGenericCollection(int picWidth, int picHeight) + { + + // высчитываем размер массива для setgeneric + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + /// Перегрузка оператора сложения + public static int operator +(TractorGenericCollection collect, T tract) + { + if (tract == null) + { + return -1; + } + return collect._collection.Insert(tract); + } + /// Перегрузка оператора вычитания + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static bool operator -(TractorGenericCollection collect, int + pos) + { + T obj = collect._collection.Get(pos); + if (obj != null) + { + return collect.Remove(pos); + } + return false; + } + private bool Remove(int pos) + { + throw new NotImplementedException(); + } + // получение объекта imoveableObj + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + /// Вывод всего набора объектов + public Bitmap ShowTractors() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + 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 / 3, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + private void DrawObjects(Graphics g) + { + int HeightObjCount = _pictureHeight / _placeSizeHeight; + int WidthObjCount = _pictureWidth / _placeSizeWidth; + for (int i = 0; i < _collection.Count; i++) + { + T t = _collection.Get(i); + if (t != null) + { + { + t.SetPosition(((_collection.Count - i - 1) % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (_collection.Count - i - 1) / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight); + t.DrawTransport(g); + } + } + } + } + } +} diff --git a/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs b/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs index 8df4ffe..7f2d576 100644 --- a/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs +++ b/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs @@ -1,6 +1,5 @@  -using ProjectBulldozer.Drawings; - +using ProjectBulldozer.Drawning; namespace ProjectBulldozer.MovementStrategy { public class DrawingObjectTractor : IMoveableObject diff --git a/ProjectBulldozer/MovementStrategy/IMoveableObject.cs b/ProjectBulldozer/MovementStrategy/IMoveableObject.cs index 4a1315e..02745d7 100644 --- a/ProjectBulldozer/MovementStrategy/IMoveableObject.cs +++ b/ProjectBulldozer/MovementStrategy/IMoveableObject.cs @@ -1,12 +1,11 @@ - +using Bulldozer; + namespace ProjectBulldozer.MovementStrategy { public interface IMoveableObject { ObjectParameters? GetObjectPosition { get; } - int GetStep { get; } - bool CheckCanMove(DirectionType direction); void MoveObject(DirectionType direction); } diff --git a/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs b/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs index d0ce8f9..c4fc5af 100644 --- a/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs +++ b/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs @@ -1,6 +1,4 @@ - - -namespace ProjectBulldozer.MovementStrategy +namespace ProjectBulldozer.MovementStrategy { public class ObjectParameters { @@ -8,22 +6,16 @@ namespace ProjectBulldozer.MovementStrategy private readonly int _y; private readonly int _width; private readonly int _height; - /// Левая граница public int LeftBorder => _x; - /// Верхняя граница public int TopBorder => _y; - /// Правая граница public int RightBorder => _x + _width; - /// Нижняя граница public int DownBorder => _y + _height; - /// Середина объекта по горизонтали public int ObjectMiddleHorizontal => _x + _width / 2; - /// Середина объекта по вертикали public int ObjectMiddleVertical => _y + _height / 2; diff --git a/ProjectBulldozer/Program.cs b/ProjectBulldozer/Program.cs index b800f23..f2fd2cc 100644 --- a/ProjectBulldozer/Program.cs +++ b/ProjectBulldozer/Program.cs @@ -1,3 +1,5 @@ +using ProjectBulldozer; + namespace Bulldozer { internal static class Program @@ -11,7 +13,7 @@ namespace Bulldozer // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Bulldozer()); + Application.Run(new FormTractorCollections()); } } } \ No newline at end of file -- 2.25.1 From 2a3a472f5cf30f5f8543de29fe3d2d80732956ba Mon Sep 17 00:00:00 2001 From: AparyanLuiza Date: Thu, 30 Nov 2023 02:11:18 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D1=8B=20FormBulldozerCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormBulldozerCollections.Designer.cs | 137 ++++++++++++++++++ ProjectBulldozer/FormBulldozerCollections.cs | 65 +++++++++ .../FormBulldozerCollections.resx | 122 ++++++++++++++++ 3 files changed, 324 insertions(+) create mode 100644 ProjectBulldozer/FormBulldozerCollections.Designer.cs create mode 100644 ProjectBulldozer/FormBulldozerCollections.cs create mode 100644 ProjectBulldozer/FormBulldozerCollections.resx diff --git a/ProjectBulldozer/FormBulldozerCollections.Designer.cs b/ProjectBulldozer/FormBulldozerCollections.Designer.cs new file mode 100644 index 0000000..43f5cf3 --- /dev/null +++ b/ProjectBulldozer/FormBulldozerCollections.Designer.cs @@ -0,0 +1,137 @@ +namespace ProjectBulldozer +{ + partial class FormTractorCollections + { + /// + /// 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() + { + Instruments = new Panel(); + maskedTextBoxNumber = new MaskedTextBox(); + ButtonRefreshCollection = new Button(); + ButtonRemoveTractor = new Button(); + ButtonAddTractor = new Button(); + pictureBoxCollections = new PictureBox(); + Instruments.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollections).BeginInit(); + SuspendLayout(); + // + // Instruments + // + Instruments.Anchor = AnchorStyles.Right; + Instruments.AutoSize = true; + Instruments.Controls.Add(maskedTextBoxNumber); + Instruments.Controls.Add(ButtonRefreshCollection); + Instruments.Controls.Add(ButtonAddTractor); + Instruments.Controls.Add(ButtonRemoveTractor); + Instruments.Location = new Point(588, 11); + Instruments.Margin = new Padding(3, 2, 3, 2); + Instruments.Name = "Instruments"; + Instruments.Size = new Size(150, 456); + Instruments.TabIndex = 0; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Location = new Point(15, 51); + maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2); + maskedTextBoxNumber.Mask = "0"; + maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + maskedTextBoxNumber.Size = new Size(119, 23); + maskedTextBoxNumber.TabIndex = 4; + // + // ButtonRefreshCollection + // + ButtonRefreshCollection.Anchor = AnchorStyles.Right; + ButtonRefreshCollection.Location = new Point(3, 175); + ButtonRefreshCollection.Margin = new Padding(3, 2, 3, 2); + ButtonRefreshCollection.Name = "ButtonRefreshCollection"; + ButtonRefreshCollection.Size = new Size(131, 27); + ButtonRefreshCollection.TabIndex = 2; + ButtonRefreshCollection.Text = "Обновить "; + ButtonRefreshCollection.UseVisualStyleBackColor = true; + ButtonRefreshCollection.Click += ButtonRefreshCollection_Click; + // + // ButtonRemoveTractor + // + ButtonRemoveTractor.Anchor = AnchorStyles.Right; + ButtonRemoveTractor.Location = new Point(3, 133); + ButtonRemoveTractor.Margin = new Padding(3, 2, 3, 2); + ButtonRemoveTractor.Name = "ButtonRemoveTractor"; + ButtonRemoveTractor.Size = new Size(131, 27); + ButtonRemoveTractor.TabIndex = 1; + ButtonRemoveTractor.Text = "Удалить объект"; + ButtonRemoveTractor.UseVisualStyleBackColor = true; + ButtonRemoveTractor.Click += ButtonRemoveTractor_Click; + // + // ButtonAddTractor + // + ButtonAddTractor.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonAddTractor.Location = new Point(6, 20); + ButtonAddTractor.Margin = new Padding(3, 2, 3, 2); + ButtonAddTractor.Name = "ButtonAddTractor"; + ButtonAddTractor.Size = new Size(128, 27); + ButtonAddTractor.TabIndex = 0; + ButtonAddTractor.Text = "Добавить объект"; + ButtonAddTractor.UseVisualStyleBackColor = true; + ButtonAddTractor.Click += ButtonAddTractor_Click; + // + // pictureBoxCollections + // + pictureBoxCollections.Anchor = AnchorStyles.Left; + pictureBoxCollections.Location = new Point(12, 11); + pictureBoxCollections.Margin = new Padding(3, 2, 3, 2); + pictureBoxCollections.Name = "pictureBoxCollections"; + pictureBoxCollections.Size = new Size(570, 456); + pictureBoxCollections.TabIndex = 1; + pictureBoxCollections.TabStop = false; + pictureBoxCollections.Click += pictureBoxCollections_Click; + // + // FormTractorCollections + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(748, 478); + Controls.Add(pictureBoxCollections); + Controls.Add(Instruments); + Margin = new Padding(3, 2, 3, 2); + Name = "FormTractorCollections"; + Text = "Набор трактороов"; + Instruments.ResumeLayout(false); + Instruments.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollections).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Panel Instruments; + private Button ButtonRefreshCollection; + private Button ButtonRemoveTractor; + private Button ButtonAddTractor; + private PictureBox pictureBoxCollections; + private MaskedTextBox maskedTextBoxNumber; + } +} \ No newline at end of file diff --git a/ProjectBulldozer/FormBulldozerCollections.cs b/ProjectBulldozer/FormBulldozerCollections.cs new file mode 100644 index 0000000..e7e4703 --- /dev/null +++ b/ProjectBulldozer/FormBulldozerCollections.cs @@ -0,0 +1,65 @@ +using Bulldozer; +using ProjectBulldozer.Drawning; +using ProjectBulldozer.Generics; +using ProjectBulldozer.MovementStrategy; + +namespace ProjectBulldozer +{ + public partial class FormTractorCollections : Form + { + private readonly TractorGenericCollection _Tractors; + public FormTractorCollections() + { + InitializeComponent(); + _Tractors = new TractorGenericCollection(pictureBoxCollections.Width, + pictureBoxCollections.Height); + } + + private void ButtonAddTractor_Click(object sender, EventArgs e) + { + if (_Tractors == null) return; + FormBulldozer form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + //проверяем, удалось ли нам загрузить объект + if (_Tractors + form.SelectedTractor != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollections.Image = _Tractors.ShowTractors(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + private void ButtonRemoveTractor_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_Tractors - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollections.Image = _Tractors.ShowTractors(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void ButtonRefreshCollection_Click(object sender, EventArgs e) + { + pictureBoxCollections.Image = _Tractors.ShowTractors(); + } + + private void pictureBoxCollections_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/ProjectBulldozer/FormBulldozerCollections.resx b/ProjectBulldozer/FormBulldozerCollections.resx new file mode 100644 index 0000000..1c86d73 --- /dev/null +++ b/ProjectBulldozer/FormBulldozerCollections.resx @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 -- 2.25.1 From 7a993d4956a49d6da0177a3f3300d17e270edbcc Mon Sep 17 00:00:00 2001 From: AparyanLuiza Date: Thu, 30 Nov 2023 02:23:07 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=20=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B0=D1=85=20=D0=B8=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=B0=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectBulldozer/DirectionType.cs | 4 +-- ProjectBulldozer/Drawning/DrawingBulldozer.cs | 25 --------------- ProjectBulldozer/Drawning/DrawingTractor.cs | 32 +------------------ ProjectBulldozer/Entities/EntityBulldozer.cs | 5 --- ProjectBulldozer/Entities/EntityTractor.cs | 8 +---- ProjectBulldozer/FormBulldozer.Designer.cs | 22 ++++--------- ProjectBulldozer/FormBulldozer.cs | 21 ------------ .../FormBulldozerCollections.Designer.cs | 19 +++-------- ProjectBulldozer/FormBulldozerCollections.cs | 9 ------ .../Generics/BulldozerGenericCollection.cs | 7 ---- ProjectBulldozer/Generics/SetGeneric.cs | 13 ++------ .../MovementStrategy/AbstractStrategy.cs | 12 ------- .../MovementStrategy/DrawingObjectTractor.cs | 4 +-- .../MovementStrategy/IMoveableObject.cs | 4 +-- .../MovementStrategy/MoveToCenter.cs | 5 +-- .../MovementStrategy/MoveToRightCorner.cs | 6 +--- .../MovementStrategy/ObjectsParameters.cs | 1 - ProjectBulldozer/Program.cs | 7 +--- 18 files changed, 20 insertions(+), 184 deletions(-) diff --git a/ProjectBulldozer/DirectionType.cs b/ProjectBulldozer/DirectionType.cs index e37c505..5d06a43 100644 --- a/ProjectBulldozer/DirectionType.cs +++ b/ProjectBulldozer/DirectionType.cs @@ -1,6 +1,4 @@ - - -namespace ProjectBulldozer +namespace ProjectBulldozer { public enum DirectionType { diff --git a/ProjectBulldozer/Drawning/DrawingBulldozer.cs b/ProjectBulldozer/Drawning/DrawingBulldozer.cs index e64fbc0..7525965 100644 --- a/ProjectBulldozer/Drawning/DrawingBulldozer.cs +++ b/ProjectBulldozer/Drawning/DrawingBulldozer.cs @@ -11,9 +11,7 @@ namespace ProjectBulldozer.Drawning EntityTractor = new EntityBulldozer(speed, width, bodyColor, additionalColor, horns, seifBatteries); } } - public object Otval { get; private set; } - public override void DrawTransport(Graphics g) { if (EntityTractor is not EntityBulldozer Bulldozer) @@ -22,48 +20,28 @@ namespace ProjectBulldozer.Drawning } Pen pen = new(Color.Black); - - Brush blackBrush = new SolidBrush(Color.Black); Brush windows = new SolidBrush(Color.LightBlue); Brush bodyColor = new SolidBrush(Bulldozer.BodyColor); - Brush additionalColor = new SolidBrush(Bulldozer.AdditionalColor); - Brush grayBrush = new SolidBrush(Color.Gray); - //otval Point[] Otval = { new Point(_startPosX + 118, _startPosY + 50), new Point(_startPosX + 148, _startPosY + 111), new Point(_startPosX+ 118, _startPosY + 111), - - }; - g.FillPolygon(additionalColor, Otval); g.DrawPolygon(pen, Otval); - - - //гусеницы Brush gg = new SolidBrush(Color.LightGray); g.FillEllipse(gg, _startPosX + 16, _startPosY + 65, 101, 63); g.DrawEllipse(pen, _startPosX + 16, _startPosY + 65, 101, 63); - - - - g.FillEllipse(grayBrush, _startPosX + 65, _startPosY + 100, 13, 13); g.DrawEllipse(pen, _startPosX + 65, _startPosY + 100, 13, 13); - - - - Point[] Ttt = { - new Point(_startPosX + 16, _startPosY + 79), new Point(_startPosX + 16, _startPosY + 120), new Point(_startPosX, _startPosY + 48), @@ -71,9 +49,6 @@ namespace ProjectBulldozer.Drawning }; g.FillPolygon(blackBrush, Ttt); g.DrawPolygon(pen, Ttt); - - - if (Bulldozer.SeifBatteries) { g.FillRectangle(blackBrush, _startPosX + 110, _startPosY + 60, 5, 10); diff --git a/ProjectBulldozer/Drawning/DrawingTractor.cs b/ProjectBulldozer/Drawning/DrawingTractor.cs index 422e20d..033187b 100644 --- a/ProjectBulldozer/Drawning/DrawingTractor.cs +++ b/ProjectBulldozer/Drawning/DrawingTractor.cs @@ -1,31 +1,21 @@ - -using Bulldozer; -using ProjectBulldozer.Entities; +using ProjectBulldozer.Entities; using ProjectBulldozer.MovementStrategy; - namespace ProjectBulldozer.Drawning { public class DrawingTractor { public EntityTractor? EntityTractor { get; protected set; } - protected int _pictureWidth; - protected int _pictureHeight; - protected int _startPosX; - protected int _startPosY; - protected readonly int _tractWidth = 120; - protected readonly int _tractHeight = 110; public int GetPosX => _startPosX; public int GetPosY => _startPosY; public int GetWidth => _tractWidth; public int GetHeight => _tractHeight; - public IMoveableObject GetMoveableObject => new DrawingObjectTractor(this); public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth) { @@ -37,7 +27,6 @@ namespace ProjectBulldozer.Drawning _pictureHeight = heigth; EntityTractor = new EntityTractor(speed, weight, bodyColor); } - protected DrawingTractor(int speed, double weight, Color bodyColor, int width, int height, int tractWidth, int tractHeight) { @@ -51,7 +40,6 @@ namespace ProjectBulldozer.Drawning _tractHeight = tractHeight; EntityTractor = new EntityTractor(speed, weight, bodyColor); } - //Установка позиции public void SetPosition(int x, int y) { @@ -107,44 +95,26 @@ namespace ProjectBulldozer.Drawning { if (EntityTractor == null) return; } - - Pen pen = new(Color.Black); Brush brownBrush = new SolidBrush(Color.Brown); Brush windows = new SolidBrush(Color.LightYellow); Brush bodyColor = new SolidBrush(EntityTractor.BodyColor); - Brush grayBrush = new SolidBrush(Color.Gray); - //основное тело g.FillRectangle(bodyColor, _startPosX + 18, _startPosY + 42, 99, 56); g.DrawRectangle(pen, _startPosX + 18, _startPosY + 42, 99, 56); - - - //кабина водителя g.FillRectangle(windows, _startPosX + 18, _startPosY + 4 , 37, 37); g.DrawRectangle(pen, _startPosX + 18, _startPosY +4 , 37, 37); - - - //колеса - g.FillEllipse(grayBrush, _startPosX + 19, _startPosY + 76, 45, 45); g.DrawEllipse(pen, _startPosX + 19, _startPosY + 76, 45, 45); - - g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 87, 33, 33); g.DrawEllipse(pen, _startPosX + 80, _startPosY + 87, 33, 33); - - //выхлопная труба g.FillRectangle(brownBrush, _startPosX + 88, _startPosY+ 6, 14, 35); g.DrawRectangle(pen, _startPosX + 88, _startPosY + 6, 14, 35); - - } - public bool CanMove(DirectionType direction) { if (EntityTractor == null) diff --git a/ProjectBulldozer/Entities/EntityBulldozer.cs b/ProjectBulldozer/Entities/EntityBulldozer.cs index f65c2a9..78c1da4 100644 --- a/ProjectBulldozer/Entities/EntityBulldozer.cs +++ b/ProjectBulldozer/Entities/EntityBulldozer.cs @@ -1,9 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace ProjectBulldozer.Entities { public class EntityBulldozer : EntityTractor diff --git a/ProjectBulldozer/Entities/EntityTractor.cs b/ProjectBulldozer/Entities/EntityTractor.cs index 2db9318..a3a85d4 100644 --- a/ProjectBulldozer/Entities/EntityTractor.cs +++ b/ProjectBulldozer/Entities/EntityTractor.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectBulldozer.Entities +namespace ProjectBulldozer.Entities { public class EntityTractor { diff --git a/ProjectBulldozer/FormBulldozer.Designer.cs b/ProjectBulldozer/FormBulldozer.Designer.cs index aabda7f..d314ac0 100644 --- a/ProjectBulldozer/FormBulldozer.Designer.cs +++ b/ProjectBulldozer/FormBulldozer.Designer.cs @@ -1,16 +1,9 @@ -namespace Bulldozer + +namespace Bulldozer { partial class FormBulldozer { - /// - /// 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)) @@ -19,13 +12,7 @@ } 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() { pictureBoxBulldozer = new PictureBox(); @@ -188,9 +175,12 @@ ResumeLayout(false); PerformLayout(); } + private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e) + { + throw new NotImplementedException(); + } #endregion - private PictureBox pictureBoxBulldozer; private Button buttonCreateBulldozer; private Button buttonLeft; diff --git a/ProjectBulldozer/FormBulldozer.cs b/ProjectBulldozer/FormBulldozer.cs index 9a4325d..c3156d6 100644 --- a/ProjectBulldozer/FormBulldozer.cs +++ b/ProjectBulldozer/FormBulldozer.cs @@ -2,24 +2,19 @@ using ProjectBulldozer; using ProjectBulldozer.Drawning; using ProjectBulldozer.Generics; using ProjectBulldozer.MovementStrategy; - namespace Bulldozer { public partial class FormBulldozer : Form { - private DrawingTractor? _drawingTractor; - private AbstractStrategy? _abstractStrategy; public DrawingTractor? SelectedTractor { get; private set; } - public FormBulldozer() { InitializeComponent(); _abstractStrategy = null; SelectedTractor = null; } - private void Draw() { if (_drawingTractor == null) @@ -31,34 +26,26 @@ namespace Bulldozer _drawingTractor.DrawTransport(gr); pictureBoxBulldozer.Image = bmp; } - private void buttonCreateBulldozer_Click(object sender, EventArgs e) { Random random = new Random(); - Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - ColorDialog colorDialog = new ColorDialog(); - if (colorDialog.ShowDialog() == DialogResult.OK) { color = colorDialog.Color; } - Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - if (colorDialog.ShowDialog() == DialogResult.OK) { dopColor = colorDialog.Color; } - _drawingTractor = new DrawingBulldozer(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); _drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } - private void buttonCreateTractor_Click(object sender, EventArgs e) { Random rnd = new Random(); @@ -73,7 +60,6 @@ namespace Bulldozer _drawingTractor.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100)); Draw(); } - private void buttonMove_Click(object sender, EventArgs e) { if (_drawingTractor == null) @@ -98,7 +84,6 @@ namespace Bulldozer } Draw(); } - private void buttonStep_Click(object sender, EventArgs e) { if (_drawingTractor == null) @@ -133,16 +118,10 @@ namespace Bulldozer _abstractStrategy = null; } } - private void ButtonSelect_Tractor_Click(object sender, EventArgs e) { SelectedTractor = _drawingTractor; DialogResult = DialogResult.OK; } - - private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e) - { - - } } } \ No newline at end of file diff --git a/ProjectBulldozer/FormBulldozerCollections.Designer.cs b/ProjectBulldozer/FormBulldozerCollections.Designer.cs index 43f5cf3..c2d85cc 100644 --- a/ProjectBulldozer/FormBulldozerCollections.Designer.cs +++ b/ProjectBulldozer/FormBulldozerCollections.Designer.cs @@ -2,15 +2,7 @@ { partial class FormTractorCollections { - /// - /// 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)) @@ -21,11 +13,6 @@ } #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() { Instruments = new Panel(); @@ -124,9 +111,11 @@ ResumeLayout(false); PerformLayout(); } - + private void pictureBoxCollections_Click(object sender, EventArgs e) + { + throw new NotImplementedException(); + } #endregion - private Panel Instruments; private Button ButtonRefreshCollection; private Button ButtonRemoveTractor; diff --git a/ProjectBulldozer/FormBulldozerCollections.cs b/ProjectBulldozer/FormBulldozerCollections.cs index e7e4703..7b080fa 100644 --- a/ProjectBulldozer/FormBulldozerCollections.cs +++ b/ProjectBulldozer/FormBulldozerCollections.cs @@ -2,7 +2,6 @@ using ProjectBulldozer.Drawning; using ProjectBulldozer.Generics; using ProjectBulldozer.MovementStrategy; - namespace ProjectBulldozer { public partial class FormTractorCollections : Form @@ -14,7 +13,6 @@ namespace ProjectBulldozer _Tractors = new TractorGenericCollection(pictureBoxCollections.Width, pictureBoxCollections.Height); } - private void ButtonAddTractor_Click(object sender, EventArgs e) { if (_Tractors == null) return; @@ -33,7 +31,6 @@ namespace ProjectBulldozer } } } - private void ButtonRemoveTractor_Click(object sender, EventArgs e) { if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) @@ -51,15 +48,9 @@ namespace ProjectBulldozer MessageBox.Show("Не удалось удалить объект"); } } - private void ButtonRefreshCollection_Click(object sender, EventArgs e) { pictureBoxCollections.Image = _Tractors.ShowTractors(); } - - private void pictureBoxCollections_Click(object sender, EventArgs e) - { - - } } } diff --git a/ProjectBulldozer/Generics/BulldozerGenericCollection.cs b/ProjectBulldozer/Generics/BulldozerGenericCollection.cs index 29fc021..e19cec2 100644 --- a/ProjectBulldozer/Generics/BulldozerGenericCollection.cs +++ b/ProjectBulldozer/Generics/BulldozerGenericCollection.cs @@ -31,13 +31,6 @@ namespace ProjectBulldozer.Generics } return collect._collection.Insert(tract); } - /// Перегрузка оператора вычитания - /// - /// Перегрузка оператора вычитания - /// - /// - /// - /// public static bool operator -(TractorGenericCollection collect, int pos) { diff --git a/ProjectBulldozer/Generics/SetGeneric.cs b/ProjectBulldozer/Generics/SetGeneric.cs index 124c3d7..fd209d9 100644 --- a/ProjectBulldozer/Generics/SetGeneric.cs +++ b/ProjectBulldozer/Generics/SetGeneric.cs @@ -1,6 +1,4 @@ - - -namespace ProjectBulldozer.Generics +namespace ProjectBulldozer.Generics { internal class SetGeneric where T : class { @@ -10,13 +8,11 @@ namespace ProjectBulldozer.Generics { _places = new T[count]; } - /// Добавление объекта в набор public int Insert(T tract) { return Insert(tract, 0); } - public int Insert(T tract, int position) { int NoEmpty = 0, temp = 0; @@ -44,16 +40,11 @@ namespace ProjectBulldozer.Generics _places[position] = tract; return position; } - return -1; - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент // + return -1; } public T? Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null if (position >= Count || position < 0) return null; diff --git a/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs b/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs index db330ea..d965778 100644 --- a/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs +++ b/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs @@ -2,9 +2,6 @@ namespace ProjectBulldozer.MovementStrategy { - /// - /// Абстрактный класс стратегии - /// public abstract class AbstractStrategy { private IMoveableObject? _moveableObject; @@ -13,7 +10,6 @@ namespace ProjectBulldozer.MovementStrategy protected int FieldWidth { get; private set; } protected int FieldHeight { get; private set; } public Status GetStatus() { return _state; } - public void SetData(IMoveableObject moveableObject, int width, int height) { if (moveableObject == null) @@ -40,18 +36,12 @@ namespace ProjectBulldozer.MovementStrategy } MoveToTarget(); } - protected bool MoveLeft() => MoveTo(DirectionType.Left); - 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() { if (_state != Status.InProgress) @@ -61,9 +51,7 @@ namespace ProjectBulldozer.MovementStrategy return _moveableObject?.GetStep; } protected abstract void MoveToTarget(); - protected abstract bool IsTargetDestinaion(); - private bool MoveTo(DirectionType directionType) { if (_state != Status.InProgress) diff --git a/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs b/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs index 7f2d576..58193b2 100644 --- a/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs +++ b/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs @@ -1,11 +1,9 @@ - -using ProjectBulldozer.Drawning; +using ProjectBulldozer.Drawning; namespace ProjectBulldozer.MovementStrategy { public class DrawingObjectTractor : IMoveableObject { private readonly DrawingTractor? _drawningTractor = null; - public DrawingObjectTractor(DrawingTractor drawningTractor) { _drawningTractor = drawningTractor; diff --git a/ProjectBulldozer/MovementStrategy/IMoveableObject.cs b/ProjectBulldozer/MovementStrategy/IMoveableObject.cs index 02745d7..139c7de 100644 --- a/ProjectBulldozer/MovementStrategy/IMoveableObject.cs +++ b/ProjectBulldozer/MovementStrategy/IMoveableObject.cs @@ -1,6 +1,4 @@ -using Bulldozer; - -namespace ProjectBulldozer.MovementStrategy +namespace ProjectBulldozer.MovementStrategy { public interface IMoveableObject { diff --git a/ProjectBulldozer/MovementStrategy/MoveToCenter.cs b/ProjectBulldozer/MovementStrategy/MoveToCenter.cs index d16d4a7..e53656d 100644 --- a/ProjectBulldozer/MovementStrategy/MoveToCenter.cs +++ b/ProjectBulldozer/MovementStrategy/MoveToCenter.cs @@ -1,6 +1,4 @@ - - -namespace ProjectBulldozer.MovementStrategy +namespace ProjectBulldozer.MovementStrategy { public class MoveToCenter : AbstractStrategy { @@ -13,7 +11,6 @@ namespace ProjectBulldozer.MovementStrategy + GetStep() >= FieldWidth / 2 && objParams.ObjectMiddleVertical <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2; } - protected override void MoveToTarget() { var objParams = GetObjectParameters; diff --git a/ProjectBulldozer/MovementStrategy/MoveToRightCorner.cs b/ProjectBulldozer/MovementStrategy/MoveToRightCorner.cs index 37ac745..fcd8cea 100644 --- a/ProjectBulldozer/MovementStrategy/MoveToRightCorner.cs +++ b/ProjectBulldozer/MovementStrategy/MoveToRightCorner.cs @@ -1,6 +1,4 @@ - - -namespace ProjectBulldozer.MovementStrategy +namespace ProjectBulldozer.MovementStrategy { public class MoveToRightCorner : AbstractStrategy { @@ -11,12 +9,10 @@ namespace ProjectBulldozer.MovementStrategy return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep(); } - protected override void MoveToTarget() { var objParams = GetObjectParameters; if (objParams == null) return; - if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight(); if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown(); diff --git a/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs b/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs index c4fc5af..439a349 100644 --- a/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs +++ b/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs @@ -18,7 +18,6 @@ public int ObjectMiddleHorizontal => _x + _width / 2; /// Середина объекта по вертикали public int ObjectMiddleVertical => _y + _height / 2; - public ObjectParameters(int x, int y, int width, int height) { _x = x; diff --git a/ProjectBulldozer/Program.cs b/ProjectBulldozer/Program.cs index f2fd2cc..075760c 100644 --- a/ProjectBulldozer/Program.cs +++ b/ProjectBulldozer/Program.cs @@ -1,17 +1,12 @@ using ProjectBulldozer; - namespace Bulldozer { internal static class Program { - /// - /// The main entry point for the application. - /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. + https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); Application.Run(new FormTractorCollections()); } -- 2.25.1