ISEbd-12_Skvortsov-A.K._AccordionBus_Simple_Lab3 #4
@ -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<DrawningBus?> _collection = null;
|
||||
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
|
||||
public AbstractCompany(int picWidth, int picHeigth, ICollectionGenericObjects<DrawningBus> 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);
|
||||
}
|
||||
}
|
@ -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<DrawningBus> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// кол-во элем
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
/// <summary>
|
||||
/// установить макс элем
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
/// <summary>
|
||||
/// вставить
|
||||
/// </summary>
|
||||
/// <param name="obj">добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
bool Insert(T obj);
|
||||
/// <summary>
|
||||
/// вставить по позиции
|
||||
/// </summary>
|
||||
/// <param name="obj">добавляемый объект</param>
|
||||
/// <param name="position">индекс</param>
|
||||
/// <returns></returns>
|
||||
bool Insert(T obj, int position);
|
||||
/// <summary>
|
||||
/// удаление
|
||||
/// </summary>
|
||||
/// <param name="position">индекс</param>
|
||||
/// <returns></returns>
|
||||
bool Remove(int position);
|
||||
/// <summary>
|
||||
/// получение объекта по позиции
|
||||
/// </summary>
|
||||
/// <param name="position">индекс</param>
|
||||
/// <returns></returns>
|
||||
T? Get(int position);
|
||||
}
|
||||
}
|
@ -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<T> : ICollectionGenericObjects<T>
|
||||
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<T?>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ namespace AccordionBus.Drawnings
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
private int? _pictureHeigth;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки авто
|
||||
/// </summary>
|
||||
@ -37,7 +37,7 @@ namespace AccordionBus.Drawnings
|
||||
/// <summary>
|
||||
/// Высота прорисовки авто
|
||||
/// </summary>
|
||||
private readonly int _drawningBusHeight = 20;
|
||||
private readonly int _drawningBusHeigth = 20;
|
||||
/// <summary>
|
||||
/// Координата Х объекта
|
||||
/// </summary>
|
||||
@ -57,14 +57,14 @@ namespace AccordionBus.Drawnings
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetHeight() => _drawningBusHeight;
|
||||
public int GetHeigth() => _drawningBusHeigth;
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор пораметров
|
||||
@ -92,26 +92,26 @@ namespace AccordionBus.Drawnings
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="weight">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="heigth">Высота</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена</returns>
|
||||
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
|
||||
/// <param name="y">Координата Y</param>
|
||||
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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
169
AccordionBus/AccordionBus/FormBusCollection.Designer.cs
generated
Normal file
169
AccordionBus/AccordionBus/FormBusCollection.Designer.cs
generated
Normal file
@ -0,0 +1,169 @@
|
||||
namespace AccordionBus
|
||||
{
|
||||
partial class FormBusCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
131
AccordionBus/AccordionBus/FormBusCollection.cs
Normal file
131
AccordionBus/AccordionBus/FormBusCollection.cs
Normal file
@ -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<DrawningBus>());
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
120
AccordionBus/AccordionBus/FormBusCollection.resx
Normal file
120
AccordionBus/AccordionBus/FormBusCollection.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user