diff --git a/Bulldoser/Bulldoser/Drawings/DrawingTractor.cs b/Bulldoser/Bulldoser/Drawings/DrawingTractor.cs index c306959..7277bd4 100644 --- a/Bulldoser/Bulldoser/Drawings/DrawingTractor.cs +++ b/Bulldoser/Bulldoser/Drawings/DrawingTractor.cs @@ -1,5 +1,4 @@ using Bulldoser.Entities; -using Bulldoser.MovementStrategy; using System; using System.Collections.Generic; using System.Linq; @@ -29,8 +28,6 @@ namespace Bulldoser.Drawings 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) diff --git a/Bulldoser/Bulldoser/Form1.Designer.cs b/Bulldoser/Bulldoser/Form1.Designer.cs index 471b0aa..5e25e28 100644 --- a/Bulldoser/Bulldoser/Form1.Designer.cs +++ b/Bulldoser/Bulldoser/Form1.Designer.cs @@ -1,6 +1,6 @@ namespace Bulldoser { - partial class FormBulldoser + partial class Form1 { /// /// Required designer variable. @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBulldoser)); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); pictureBoxBulldoser = new PictureBox(); buttonCreateBulldoser = new Button(); buttonRight = new Button(); @@ -38,10 +38,7 @@ comboBoxStrategy = new ComboBox(); buttonCreateTractor = new Button(); buttonStep = new Button(); - fileSystemWatcher1 = new FileSystemWatcher(); - buttonSelectTransport = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxBulldoser).BeginInit(); - ((System.ComponentModel.ISupportInitialize)fileSystemWatcher1).BeginInit(); SuspendLayout(); // // pictureBoxBulldoser @@ -66,7 +63,7 @@ buttonCreateBulldoser.TabIndex = 1; buttonCreateBulldoser.Text = "Создать бульдозер"; buttonCreateBulldoser.UseVisualStyleBackColor = true; - buttonCreateBulldoser.Click += buttonCreateBulldozer_Click; + buttonCreateBulldoser.Click += buttonCreateBulldoser_Click; // // buttonRight // @@ -160,27 +157,11 @@ buttonStep.UseVisualStyleBackColor = true; buttonStep.Click += buttonStep_Click; // - // fileSystemWatcher1 - // - fileSystemWatcher1.EnableRaisingEvents = true; - fileSystemWatcher1.SynchronizingObject = this; - // - // buttonSelectTransport - // - buttonSelectTransport.Location = new Point(785, 78); - buttonSelectTransport.Name = "buttonSelectTransport"; - buttonSelectTransport.Size = new Size(88, 34); - buttonSelectTransport.TabIndex = 9; - buttonSelectTransport.Text = "Выбор"; - buttonSelectTransport.UseVisualStyleBackColor = true; - buttonSelectTransport.Click += ButtonSelect_Tractor_Click; - // - // FormBulldoser + // Form1 // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(884, 461); - Controls.Add(buttonSelectTransport); Controls.Add(buttonStep); Controls.Add(buttonCreateTractor); Controls.Add(comboBoxStrategy); @@ -190,11 +171,10 @@ Controls.Add(buttonRight); Controls.Add(buttonCreateBulldoser); Controls.Add(pictureBoxBulldoser); - Name = "FormBulldoser"; + Name = "Form1"; StartPosition = FormStartPosition.CenterScreen; - Text = "Создать транспорт"; + Text = "Form1"; ((System.ComponentModel.ISupportInitialize)pictureBoxBulldoser).EndInit(); - ((System.ComponentModel.ISupportInitialize)fileSystemWatcher1).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -210,7 +190,5 @@ private ComboBox comboBoxStrategy; private Button buttonCreateTractor; private Button buttonStep; - private FileSystemWatcher fileSystemWatcher1; - private Button buttonSelectTransport; } } \ No newline at end of file diff --git a/Bulldoser/Bulldoser/Form1.cs b/Bulldoser/Bulldoser/Form1.cs index 9a95dfc..3eb6caf 100644 --- a/Bulldoser/Bulldoser/Form1.cs +++ b/Bulldoser/Bulldoser/Form1.cs @@ -3,18 +3,18 @@ using Bulldoser.MovementStrategy; namespace Bulldoser { - public partial class FormBulldoser : Form + public partial class Form1 : Form { private DrawingTractor? _drawingTractor; + private AbstractStrategy? _abstractStrategy; - public DrawingTractor? SelectedTractor { get; private set; } - public FormBulldoser() + + public Form1() { InitializeComponent(); - _abstractStrategy = null; - SelectedTractor = null; } + private void Draw() { if (_drawingTractor == null) @@ -26,40 +26,29 @@ namespace Bulldoser _drawingTractor.DrawTransport(gr); pictureBoxBulldoser.Image = bmp; } - private void buttonCreateBulldozer_Click(object sender, EventArgs e) + + private void buttonCreateBulldoser_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 DrawingBulldoser(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, + _drawingTractor = new DrawingBulldoser(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)), pictureBoxBulldoser.Width, pictureBoxBulldoser.Height); _drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } + private void buttonCreateTractor_Click(object sender, EventArgs e) { Random rnd = new Random(); - 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, + _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)), pictureBoxBulldoser.Width, pictureBoxBulldoser.Height); _drawingTractor.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100)); Draw(); } + private void buttonMove_Click(object sender, EventArgs e) { if (_drawingTractor == null) @@ -84,6 +73,7 @@ namespace Bulldoser } Draw(); } + private void buttonStep_Click(object sender, EventArgs e) { if (_drawingTractor == null) @@ -102,14 +92,15 @@ namespace Bulldoser { return; } - _abstractStrategy.SetData(_drawingTractor.GetMoveableObject, pictureBoxBulldoser.Width, + _abstractStrategy.SetData(new + DrawingObjectTractor(_drawingTractor), pictureBoxBulldoser.Width, pictureBoxBulldoser.Height); + comboBoxStrategy.Enabled = false; } if (_abstractStrategy == null) { return; } - comboBoxStrategy.Enabled = false; _abstractStrategy.MakeStep(); Draw(); if (_abstractStrategy.GetStatus() == Status.Finish) @@ -118,10 +109,7 @@ namespace Bulldoser _abstractStrategy = null; } } - private void ButtonSelect_Tractor_Click(object sender, EventArgs e) - { - SelectedTractor = _drawingTractor; - DialogResult = DialogResult.OK; - } + + } } \ No newline at end of file diff --git a/Bulldoser/Bulldoser/Form1.resx b/Bulldoser/Bulldoser/Form1.resx index a1aba31..f1d9bd4 100644 --- a/Bulldoser/Bulldoser/Form1.resx +++ b/Bulldoser/Bulldoser/Form1.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object] @@ -406,7 +406,4 @@ SqQBINQfkf7yz6ev/zEzM7Ok/f7hf5jEhMkgDZ7VAAAAAElFTkSuQmCC - - 17, 17 - \ No newline at end of file diff --git a/Bulldoser/Bulldoser/Form2.Designer.cs b/Bulldoser/Bulldoser/Form2.Designer.cs deleted file mode 100644 index 397ad1f..0000000 --- a/Bulldoser/Bulldoser/Form2.Designer.cs +++ /dev/null @@ -1,125 +0,0 @@ -namespace Bulldoser -{ - partial class FormTractorCollection - { - /// - /// 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() - { - pictureBoxCollections = new PictureBox(); - groupBoxTools = new GroupBox(); - maskedTextBoxNumbers = new MaskedTextBox(); - buttonUpdateCollection = new Button(); - buttonRemoveTransport = new Button(); - buttonAddTransport = new Button(); - ((System.ComponentModel.ISupportInitialize)pictureBoxCollections).BeginInit(); - groupBoxTools.SuspendLayout(); - SuspendLayout(); - // - // pictureBoxCollections - // - pictureBoxCollections.Location = new Point(12, 6); - pictureBoxCollections.Name = "pictureBoxCollections"; - pictureBoxCollections.Size = new Size(570, 432); - pictureBoxCollections.TabIndex = 1; - pictureBoxCollections.TabStop = false; - // - // groupBoxTools - // - groupBoxTools.Controls.Add(maskedTextBoxNumbers); - groupBoxTools.Controls.Add(buttonUpdateCollection); - groupBoxTools.Controls.Add(buttonRemoveTransport); - groupBoxTools.Controls.Add(buttonAddTransport); - groupBoxTools.Location = new Point(588, 6); - groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(200, 432); - groupBoxTools.TabIndex = 2; - groupBoxTools.TabStop = false; - groupBoxTools.Text = "Инструменты"; - // - // maskedTextBoxNumbers - // - maskedTextBoxNumbers.Location = new Point(6, 106); - maskedTextBoxNumbers.Margin = new Padding(3, 2, 3, 2); - maskedTextBoxNumbers.Mask = "0"; - maskedTextBoxNumbers.Name = "maskedTextBoxNumbers"; - maskedTextBoxNumbers.Size = new Size(188, 23); - maskedTextBoxNumbers.TabIndex = 5; - // - // buttonUpdateCollection - // - buttonUpdateCollection.Location = new Point(6, 220); - buttonUpdateCollection.Name = "buttonUpdateCollection"; - buttonUpdateCollection.Size = new Size(188, 40); - buttonUpdateCollection.TabIndex = 3; - buttonUpdateCollection.Text = "Обновление коллекции"; - buttonUpdateCollection.UseVisualStyleBackColor = true; - buttonUpdateCollection.Click += ButtonRefreshCollection_Click; - // - // buttonRemoveTransport - // - buttonRemoveTransport.Location = new Point(6, 152); - buttonRemoveTransport.Name = "buttonRemoveTransport"; - buttonRemoveTransport.Size = new Size(188, 40); - buttonRemoveTransport.TabIndex = 2; - buttonRemoveTransport.Text = "Удалить транспорт"; - buttonRemoveTransport.UseVisualStyleBackColor = true; - buttonRemoveTransport.Click += ButtonRemoveTractor_Click; - // - // buttonAddTransport - // - buttonAddTransport.Location = new Point(6, 39); - buttonAddTransport.Name = "buttonAddTransport"; - buttonAddTransport.Size = new Size(188, 47); - buttonAddTransport.TabIndex = 0; - buttonAddTransport.Text = "Добавить транспорт"; - buttonAddTransport.UseVisualStyleBackColor = true; - buttonAddTransport.Click += ButtonAddTractor_Click; - // - // FormTractorCollection - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(groupBoxTools); - Controls.Add(pictureBoxCollections); - Name = "FormTractorCollection"; - Text = "Набор автомобилей"; - ((System.ComponentModel.ISupportInitialize)pictureBoxCollections).EndInit(); - groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); - ResumeLayout(false); - } - - #endregion - - private PictureBox pictureBoxCollections; - private GroupBox groupBoxTools; - private Button buttonUpdateCollection; - private Button buttonRemoveTransport; - private Button buttonAddTransport; - private MaskedTextBox maskedTextBoxNumbers; - } -} \ No newline at end of file diff --git a/Bulldoser/Bulldoser/Form2.cs b/Bulldoser/Bulldoser/Form2.cs deleted file mode 100644 index 7163f12..0000000 --- a/Bulldoser/Bulldoser/Form2.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Bulldoser.Drawings; -using Bulldoser.Generic; -using Bulldoser.MovementStrategy; -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; - -namespace Bulldoser -{ - public partial class FormTractorCollection : Form - { - private readonly TractorGenericCollection _Tractors; - public FormTractorCollection() - { - InitializeComponent(); - _Tractors = new TractorGenericCollection(pictureBoxCollections.Width, - pictureBoxCollections.Height); - } - private void ButtonAddTractor_Click(object sender, EventArgs e) - { - if (_Tractors == null) return; - FormBulldoser 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(maskedTextBoxNumbers.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(); - } - } -} diff --git a/Bulldoser/Bulldoser/Form2.resx b/Bulldoser/Bulldoser/Form2.resx deleted file mode 100644 index af32865..0000000 --- a/Bulldoser/Bulldoser/Form2.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Bulldoser/Bulldoser/Generic/BulldoserGenericCollection.cs b/Bulldoser/Bulldoser/Generic/BulldoserGenericCollection.cs deleted file mode 100644 index c62bfa5..0000000 --- a/Bulldoser/Bulldoser/Generic/BulldoserGenericCollection.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Bulldoser.Drawings; -using Bulldoser.MovementStrategy; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Bulldoser.Generic -{ - public 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 T? operator -(TractorGenericCollection collect, int - pos) - { - T obj = collect._collection.Get(pos); - if (obj != null) - { - return collect._collection.Remove(pos); - } - return obj; - } - // получение объекта 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/Bulldoser/Bulldoser/Generic/SetGeneric.cs b/Bulldoser/Bulldoser/Generic/SetGeneric.cs deleted file mode 100644 index 22ea4f6..0000000 --- a/Bulldoser/Bulldoser/Generic/SetGeneric.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Bulldoser.Generic -{ - public 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; - } - - public T? Remove(int position) - { - if (position >= Count || position < 0) - return null; - - T tmp = _places[position]; - _places[position] = null; - return tmp; - } - //Получение объекта из набора по позиции - public T? Get(int position) - { - if (position < 0 || position >= Count) return null; - return _places[position]; - } - } -} diff --git a/Bulldoser/Bulldoser/Program.cs b/Bulldoser/Bulldoser/Program.cs index 63fac9b..0666f96 100644 --- a/Bulldoser/Bulldoser/Program.cs +++ b/Bulldoser/Bulldoser/Program.cs @@ -11,7 +11,7 @@ namespace Bulldoser // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormTractorCollection()); + Application.Run(new Form1()); } } } \ No newline at end of file