diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..23479f1 --- /dev/null +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,69 @@ +using AccordionBus.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccordionBus.CollectionGenericObjects +{ + public abstract class AbstractCompany + { + protected readonly int _placeSizeWidth = 180; + + protected readonly int _placeSizeHeight = 60; + + protected readonly int _pictureWidth; + + protected readonly int _pictureHeight; + + protected ICollectionGenericObjects _collection = null; + + private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + + public AbstractCompany(int picWidth, int picHeigth, ICollectionGenericObjects collection) + { + _pictureWidth = picWidth; + _pictureHeight = picHeigth; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + + public static bool operator +(AbstractCompany company, DrawningBus bus) + { + return company._collection?.Insert(bus) ?? false; + } + + public static bool operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position) ?? false; + } + + public DrawningBus? GetRandomObject() + { + Random rnd = new(); + return _collection?.Get(rnd.Next(GetMaxCount)); + } + + public Bitmap? Show() + { + Bitmap bitmap = new(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackground(graphics); + + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + DrawningBus? obj = _collection?.Get(i); + SetObjectPosition(i, _collection?.Count ?? 0, obj); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + protected abstract void DrawBackground(Graphics g); + + protected abstract void SetObjectPosition(int position, int MaxPos, DrawningBus? bus); + } +} diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/BusStation.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/BusStation.cs new file mode 100644 index 0000000..fb5efcc --- /dev/null +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/BusStation.cs @@ -0,0 +1,47 @@ +using AccordionBus.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccordionBus.CollectionGenericObjects +{ + public class BusStation : AbstractCompany + { + public BusStation(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + Pen black = new Pen(Color.Black); + + protected override void DrawBackground(Graphics g) + { + for (int i = _pictureHeight - 1; i >= 0; i -= _placeSizeHeight) + { + g.DrawLine(black, _pictureWidth - ((int)(_pictureWidth / _placeSizeWidth) * _placeSizeWidth), i, _pictureWidth, i); + + for (int j = _pictureWidth - 1; j >= 0; j -= _placeSizeWidth) + { + g.DrawLine(black, j, i, j, i - _placeSizeHeight + 20); + } + } + } + + protected override void SetObjectPosition(int position, int MaxPos, DrawningBus? bus) + { + if (bus == null) return; + + int _levelOfPosition = 0; + int _countPositionInRange = _pictureWidth / _placeSizeWidth; + if (position >= _countPositionInRange) + { + _levelOfPosition = position / _countPositionInRange; + } + if (position >= _countPositionInRange) position %= _countPositionInRange; + + bus.SetPosition(_pictureWidth - position * _placeSizeWidth - bus.GetWidth() - (_placeSizeWidth - bus.GetWidth()) / 2, + _pictureHeight - _levelOfPosition * _placeSizeHeight - bus.GetHeigth() - (_placeSizeHeight - bus.GetHeigth()) / 2); + } + } +} diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..10b3762 --- /dev/null +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccordionBus.CollectionGenericObjects +{ + public interface ICollectionGenericObjects + where T : class + { + /// + /// кол-во элем + /// + int Count { get; } + /// + /// установить макс элем + /// + int SetMaxCount { set; } + /// + /// вставить + /// + /// добавляемый объект + /// + bool Insert(T obj); + /// + /// вставить по позиции + /// + /// добавляемый объект + /// индекс + /// + bool Insert(T obj, int position); + /// + /// удаление + /// + /// индекс + /// + bool Remove(int position); + /// + /// получение объекта по позиции + /// + /// индекс + /// + T? Get(int position); + } +} diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..4caf5c1 --- /dev/null +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccordionBus.CollectionGenericObjects +{ + public class MassiveGenericObjects : ICollectionGenericObjects + where T : class + { + private T?[] _collection; + + public int Count => _collection.Length; + + public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + + public T? Get(int position) + { + if (position < 0 || position >= _collection.Length) return null; + return _collection[position]; + } + + public bool Insert(T obj) + { + for (int i = 0; i < _collection.Length; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + return false; + } + + public bool Insert(T obj, int position) + { + if (position < 0 || position >= _collection.Length) { return false; } + + if (_collection[position] == null) + { + _collection[position] = obj; + return true; + } + else + { + for (int i = position + 1; i < _collection.Length; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + + for (int i = position - 1; i >= 0; i--) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + } + return false; + } + + public bool Remove(int position) + { + if (position < 0 || position >= _collection.Length) { return false;} + + _collection[position] = null; + return true; + } + } +} diff --git a/AccordionBus/AccordionBus/Drawnings/DrawningBus.cs b/AccordionBus/AccordionBus/Drawnings/DrawningBus.cs index 92cb343..982dde3 100644 --- a/AccordionBus/AccordionBus/Drawnings/DrawningBus.cs +++ b/AccordionBus/AccordionBus/Drawnings/DrawningBus.cs @@ -21,7 +21,7 @@ namespace AccordionBus.Drawnings /// /// Высота окна /// - private int? _pictureHeight; + private int? _pictureHeigth; /// /// Левая координата прорисовки авто /// @@ -37,7 +37,7 @@ namespace AccordionBus.Drawnings /// /// Высота прорисовки авто /// - private readonly int _drawningBusHeight = 20; + private readonly int _drawningBusHeigth = 20; /// /// Координата Х объекта /// @@ -57,14 +57,14 @@ namespace AccordionBus.Drawnings /// Высота объекта /// /// - public int GetHeight() => _drawningBusHeight; + public int GetHeigth() => _drawningBusHeigth; /// /// Пустой конструктор /// private DrawningBus() { _pictureWeight = null; - _pictureHeight = null; + _pictureHeigth = null; _startPosX = null; _startPosY = null; } @@ -76,7 +76,7 @@ namespace AccordionBus.Drawnings protected DrawningBus(int drawningBusWeight, int drawningBusHeight) : this() { _drawningBusWeight = drawningBusWeight; - _drawningBusHeight = drawningBusHeight; + _drawningBusHeigth = drawningBusHeight; } /// /// Конструктор пораметров @@ -92,26 +92,26 @@ namespace AccordionBus.Drawnings /// /// Установка границ поля /// - /// Ширина - /// Высота + /// Ширина + /// Высота /// true - границы заданы, false - проверка не пройдена - public bool SetPictureSize(int weight, int height) + public bool SetPictureSize(int width, int heigth) { - if (weight < _drawningBusWeight || height < _drawningBusHeight) + if (width < _drawningBusWeight || heigth < _drawningBusHeigth) { return false; } - _pictureWeight = weight; - _pictureHeight = height; + _pictureWeight = width; + _pictureHeigth = heigth; if (_startPosX.HasValue && _startPosX.Value + _drawningBusWeight > _pictureWeight) { _startPosX -= _startPosX.Value + _drawningBusWeight - _pictureWeight; } - else if (_startPosY.HasValue && _startPosY.Value + _drawningBusHeight > _pictureHeight) + else if (_startPosY.HasValue && _startPosY.Value + _drawningBusHeigth > _pictureHeigth) { - _startPosY -= _startPosY.Value + _drawningBusHeight - _pictureHeight; + _startPosY -= _startPosY.Value + _drawningBusHeigth - _pictureHeigth; } return true; @@ -124,7 +124,7 @@ namespace AccordionBus.Drawnings /// Координата Y public void SetPosition(int x, int y) { - if (!_pictureHeight.HasValue || !_pictureWeight.HasValue) + if (!_pictureHeigth.HasValue || !_pictureWeight.HasValue) { return; } @@ -142,9 +142,9 @@ namespace AccordionBus.Drawnings _startPosX = x; } - if (y + _drawningBusHeight > _pictureHeight) + if (y + _drawningBusHeigth > _pictureHeigth) { - _startPosY = y - (y + _drawningBusHeight - _pictureHeight); + _startPosY = y - (y + _drawningBusHeigth - _pictureHeigth); } else if (y < 0) { @@ -205,13 +205,13 @@ namespace AccordionBus.Drawnings return true; case DirectionType.Down: - if (_startPosY.Value + EntityBus.Step + _drawningBusHeight < _pictureHeight) + if (_startPosY.Value + EntityBus.Step + _drawningBusHeigth < _pictureHeigth) { _startPosY += (int)EntityBus.Step; } else { - _startPosY = _pictureHeight - _drawningBusHeight; + _startPosY = _pictureHeigth - _drawningBusHeigth; } return true; diff --git a/AccordionBus/AccordionBus/FormAccordionBus.Designer.cs b/AccordionBus/AccordionBus/FormAccordionBus.Designer.cs index d34b0f9..af4a19a 100644 --- a/AccordionBus/AccordionBus/FormAccordionBus.Designer.cs +++ b/AccordionBus/AccordionBus/FormAccordionBus.Designer.cs @@ -29,13 +29,11 @@ private void InitializeComponent() { pictureBoxAccordionBus = new PictureBox(); - buttonCreateAccordionBus = new Button(); ButtonUp = new Button(); ButtonRight = new Button(); ButtonLeft = new Button(); ButtonDown = new Button(); - buttonCreateBus = new Button(); - comboBoxStratregy = new ComboBox(); + comboBoxStrategy = new ComboBox(); buttonStrategyStap = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAccordionBus).BeginInit(); SuspendLayout(); @@ -45,29 +43,18 @@ pictureBoxAccordionBus.Dock = DockStyle.Fill; pictureBoxAccordionBus.Location = new Point(0, 0); pictureBoxAccordionBus.Name = "pictureBoxAccordionBus"; - pictureBoxAccordionBus.Size = new Size(882, 453); + pictureBoxAccordionBus.Size = new Size(1182, 653); pictureBoxAccordionBus.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxAccordionBus.TabIndex = 0; pictureBoxAccordionBus.TabStop = false; // - // buttonCreateAccordionBus - // - buttonCreateAccordionBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateAccordionBus.Location = new Point(12, 412); - buttonCreateAccordionBus.Name = "buttonCreateAccordionBus"; - buttonCreateAccordionBus.Size = new Size(235, 29); - buttonCreateAccordionBus.TabIndex = 1; - buttonCreateAccordionBus.Text = "создать автобус с гормошкой"; - buttonCreateAccordionBus.UseVisualStyleBackColor = true; - buttonCreateAccordionBus.Click += ButtonCreate_Click; - // // ButtonUp // ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; ButtonUp.BackgroundImage = Properties.Resources.buttUp; ButtonUp.BackgroundImageLayout = ImageLayout.Stretch; ButtonUp.ImageAlign = ContentAlignment.MiddleLeft; - ButtonUp.Location = new Point(773, 375); + ButtonUp.Location = new Point(1073, 575); ButtonUp.Name = "ButtonUp"; ButtonUp.Size = new Size(30, 30); ButtonUp.TabIndex = 2; @@ -80,7 +67,7 @@ ButtonRight.BackgroundImage = Properties.Resources.buttRIght; ButtonRight.BackgroundImageLayout = ImageLayout.Stretch; ButtonRight.ImageAlign = ContentAlignment.MiddleLeft; - ButtonRight.Location = new Point(809, 411); + ButtonRight.Location = new Point(1109, 611); ButtonRight.Name = "ButtonRight"; ButtonRight.Size = new Size(30, 30); ButtonRight.TabIndex = 3; @@ -93,7 +80,7 @@ ButtonLeft.BackgroundImage = Properties.Resources.buttLeft; ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch; ButtonLeft.ImageAlign = ContentAlignment.MiddleLeft; - ButtonLeft.Location = new Point(737, 411); + ButtonLeft.Location = new Point(1037, 611); ButtonLeft.Name = "ButtonLeft"; ButtonLeft.Size = new Size(30, 30); ButtonLeft.TabIndex = 4; @@ -106,37 +93,26 @@ ButtonDown.BackgroundImage = Properties.Resources.buttDown; ButtonDown.BackgroundImageLayout = ImageLayout.Stretch; ButtonDown.ImageAlign = ContentAlignment.MiddleLeft; - ButtonDown.Location = new Point(773, 411); + ButtonDown.Location = new Point(1073, 611); ButtonDown.Name = "ButtonDown"; ButtonDown.Size = new Size(30, 30); ButtonDown.TabIndex = 5; ButtonDown.UseVisualStyleBackColor = true; ButtonDown.Click += ButtonMove_Click; // - // buttonCreateBus + // comboBoxStrategy // - buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateBus.Location = new Point(253, 411); - buttonCreateBus.Name = "buttonCreateBus"; - buttonCreateBus.Size = new Size(235, 29); - buttonCreateBus.TabIndex = 6; - buttonCreateBus.Text = "создать автобус"; - buttonCreateBus.UseVisualStyleBackColor = true; - buttonCreateBus.Click += ButtonCreateBus_Click; - // - // comboBoxStratregy - // - comboBoxStratregy.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxStratregy.FormattingEnabled = true; - comboBoxStratregy.Items.AddRange(new object[] { "К центру", "К краю" }); - comboBoxStratregy.Location = new Point(688, 12); - comboBoxStratregy.Name = "comboBoxStratregy"; - comboBoxStratregy.Size = new Size(151, 28); - comboBoxStratregy.TabIndex = 7; + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" }); + comboBoxStrategy.Location = new Point(988, 12); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(151, 28); + comboBoxStrategy.TabIndex = 7; // // buttonStrategyStap // - buttonStrategyStap.Location = new Point(761, 46); + buttonStrategyStap.Location = new Point(1061, 46); buttonStrategyStap.Name = "buttonStrategyStap"; buttonStrategyStap.Size = new Size(78, 29); buttonStrategyStap.TabIndex = 8; @@ -148,15 +124,13 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(882, 453); + ClientSize = new Size(1182, 653); Controls.Add(buttonStrategyStap); - Controls.Add(comboBoxStratregy); - Controls.Add(buttonCreateBus); + Controls.Add(comboBoxStrategy); Controls.Add(ButtonDown); Controls.Add(ButtonLeft); Controls.Add(ButtonRight); Controls.Add(ButtonUp); - Controls.Add(buttonCreateAccordionBus); Controls.Add(pictureBoxAccordionBus); Name = "FormAccordionBus"; StartPosition = FormStartPosition.CenterScreen; @@ -169,13 +143,11 @@ #endregion private PictureBox pictureBoxAccordionBus; - private Button buttonCreateAccordionBus; private Button ButtonUp; private Button ButtonRight; private Button ButtonLeft; private Button ButtonDown; - private Button buttonCreateBus; - private ComboBox comboBoxStratregy; + private ComboBox comboBoxStrategy; private Button buttonStrategyStap; } } \ No newline at end of file diff --git a/AccordionBus/AccordionBus/FormAccordionBus.cs b/AccordionBus/AccordionBus/FormAccordionBus.cs index 4ec9bdf..715b9fb 100644 --- a/AccordionBus/AccordionBus/FormAccordionBus.cs +++ b/AccordionBus/AccordionBus/FormAccordionBus.cs @@ -16,6 +16,18 @@ namespace AccordionBus { private DrawningBus? _drawningBus; private AbstractStrategy? _strategy; + + public DrawningBus SetBus + { + set + { + _drawningBus = value; + _drawningBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } public FormAccordionBus() { InitializeComponent(); @@ -34,41 +46,6 @@ namespace AccordionBus pictureBoxAccordionBus.Image = bmp; } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningBus): - _drawningBus = new DrawningBus(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255))); - break; - case nameof(DrawningAccordionBus): - _drawningBus = new DrawningAccordionBus(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), - Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - - _drawningBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height); - _drawningBus.SetPosition(random.Next(50, 300), random.Next(50, 300)); - _strategy = null; - comboBoxStratregy.Enabled = true; - Draw(); - } - - private void ButtonCreate_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningAccordionBus)); - } - private void ButtonCreateBus_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningBus)); - } - private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningBus == null) @@ -103,9 +80,9 @@ namespace AccordionBus private void buttonStrategyStap_Click(object sender, EventArgs e) { if (_drawningBus == null) return; - if (comboBoxStratregy.Enabled) + if (comboBoxStrategy.Enabled) { - _strategy = comboBoxStratregy.SelectedIndex switch + _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), @@ -116,13 +93,13 @@ namespace AccordionBus } if (_strategy == null) return; - comboBoxStratregy.Enabled = false; + comboBoxStrategy.Enabled = false; _strategy.MakeStap(); Draw(); if (_strategy.GetStatus() == StrategyStatus.Finish) { - comboBoxStratregy.Enabled = true; + comboBoxStrategy.Enabled = true; _strategy = null; } } diff --git a/AccordionBus/AccordionBus/FormBusCollection.Designer.cs b/AccordionBus/AccordionBus/FormBusCollection.Designer.cs new file mode 100644 index 0000000..a7e37de --- /dev/null +++ b/AccordionBus/AccordionBus/FormBusCollection.Designer.cs @@ -0,0 +1,169 @@ +namespace AccordionBus +{ + partial class FormBusCollection + { + /// + /// 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() + { + groupBoxTools = new GroupBox(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonRemoveBus = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddAccordionBus = new Button(); + buttonAddBus = new Button(); + comboBoxSelectedCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonRemoveBus); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddAccordionBus); + groupBoxTools.Controls.Add(buttonAddBus); + groupBoxTools.Controls.Add(comboBoxSelectedCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(948, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(234, 653); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(15, 554); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(207, 54); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Location = new Point(15, 443); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(207, 54); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += buttonGoToCheck_Click; + // + // buttonRemoveBus + // + buttonRemoveBus.Location = new Point(15, 310); + buttonRemoveBus.Name = "buttonRemoveBus"; + buttonRemoveBus.Size = new Size(207, 54); + buttonRemoveBus.TabIndex = 4; + buttonRemoveBus.Text = "Удалить автобус"; + buttonRemoveBus.UseVisualStyleBackColor = true; + buttonRemoveBus.Click += buttonRemoveBus_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(15, 277); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(207, 27); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddAccordionBus + // + buttonAddAccordionBus.Location = new Point(15, 155); + buttonAddAccordionBus.Name = "buttonAddAccordionBus"; + buttonAddAccordionBus.Size = new Size(207, 54); + buttonAddAccordionBus.TabIndex = 2; + buttonAddAccordionBus.Text = "Добавить автобус с гормошкой"; + buttonAddAccordionBus.UseVisualStyleBackColor = true; + buttonAddAccordionBus.Click += buttonAddAccordionBus_Click; + // + // buttonAddBus + // + buttonAddBus.Location = new Point(15, 95); + buttonAddBus.Name = "buttonAddBus"; + buttonAddBus.Size = new Size(207, 54); + buttonAddBus.TabIndex = 1; + buttonAddBus.Text = "Добавить автобус"; + buttonAddBus.UseVisualStyleBackColor = true; + buttonAddBus.Click += buttonAddBus_Click; + // + // comboBoxSelectedCompany + // + comboBoxSelectedCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectedCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectedCompany.FormattingEnabled = true; + comboBoxSelectedCompany.Items.AddRange(new object[] { "Станция" }); + comboBoxSelectedCompany.Location = new Point(15, 40); + comboBoxSelectedCompany.Name = "comboBoxSelectedCompany"; + comboBoxSelectedCompany.Size = new Size(207, 28); + comboBoxSelectedCompany.TabIndex = 0; + comboBoxSelectedCompany.SelectedIndexChanged += comboBoxSelectedCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(948, 653); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormBusCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1182, 653); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormBusCollection"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Коллекция автобусов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectedCompany; + private Button buttonAddBus; + private Button buttonAddAccordionBus; + private PictureBox pictureBox; + private Button buttonRemoveBus; + private MaskedTextBox maskedTextBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/AccordionBus/AccordionBus/FormBusCollection.cs b/AccordionBus/AccordionBus/FormBusCollection.cs new file mode 100644 index 0000000..4873e21 --- /dev/null +++ b/AccordionBus/AccordionBus/FormBusCollection.cs @@ -0,0 +1,131 @@ +using AccordionBus.CollectionGenericObjects; +using AccordionBus.Drawnings; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics.Eventing.Reader; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AccordionBus +{ + public partial class FormBusCollection : Form + { + private AbstractCompany? _company; + + public FormBusCollection() + { + InitializeComponent(); + } + + private void comboBoxSelectedCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectedCompany.Text) + { + case "Станция": + _company = new BusStation(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + pictureBox.Image = _company.Show(); + break; + } + } + + private void CreateObject(string type) + { + if (_company == null) return; + + Random random = new(); + DrawningBus _drawningBus; + switch (type) + { + case nameof(DrawningBus): + _drawningBus = new DrawningBus(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + _drawningBus.SetPictureSize(pictureBox.Width, pictureBox.Height); + break; + case nameof(DrawningAccordionBus): + _drawningBus = new DrawningAccordionBus(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random), GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + _drawningBus.SetPictureSize(pictureBox.Width, pictureBox.Height); + break; + default: + return; + } + + if (_company + _drawningBus) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Объект не удалось добавить"); + } + } + + private static Color GetColor(Random rnd) + { + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + return color; + } + + private void buttonAddBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus)); + + private void buttonAddAccordionBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAccordionBus)); + + private void buttonRemoveBus_Click(object sender, EventArgs e) + { + if (_company == null || string.IsNullOrEmpty(maskedTextBox.Text)) return; + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; + + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_company - pos) + { + MessageBox.Show("Объект удалён"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void buttonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) return; + + DrawningBus? bus = null; + int counter = 100; + while (bus == null || counter > 0) + { + bus = _company.GetRandomObject(); + counter--; + } + + if (bus == null) return; + + FormAccordionBus form = new() + { + SetBus = bus + }; + form.ShowDialog(); + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) return; + + pictureBox.Image = _company.Show(); + } + } +} diff --git a/AccordionBus/AccordionBus/FormBusCollection.resx b/AccordionBus/AccordionBus/FormBusCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AccordionBus/AccordionBus/FormBusCollection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AccordionBus/AccordionBus/MovementStrategy/MoveableBus.cs b/AccordionBus/AccordionBus/MovementStrategy/MoveableBus.cs index 1d3cb65..cd7d23d 100644 --- a/AccordionBus/AccordionBus/MovementStrategy/MoveableBus.cs +++ b/AccordionBus/AccordionBus/MovementStrategy/MoveableBus.cs @@ -33,7 +33,7 @@ namespace AccordionBus.MovementStrategy { return null; } - return new ObjectParameters(_car.GetPosX().Value, _car.GetPosY().Value, _car.GetWidth(), _car.GetHeight()); + return new ObjectParameters(_car.GetPosX().Value, _car.GetPosY().Value, _car.GetWidth(), _car.GetHeigth()); } } diff --git a/AccordionBus/AccordionBus/Program.cs b/AccordionBus/AccordionBus/Program.cs index ae15180..c6b7d4c 100644 --- a/AccordionBus/AccordionBus/Program.cs +++ b/AccordionBus/AccordionBus/Program.cs @@ -11,7 +11,7 @@ namespace AccordionBus // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAccordionBus()); + Application.Run(new FormBusCollection()); } } } \ No newline at end of file