Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
17ea81733b | |||
36bd6dfbb9 | |||
4adc299af9 | |||
d1eb7efad4 | |||
ba50035c99 |
@ -8,4 +8,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
35
AccordionBus/AccordionBus/Drawnings/DirectionType.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление премещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
}
|
100
AccordionBus/AccordionBus/Drawnings/DrawningAccordionBus.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AccordionBus.Entities;
|
||||
|
||||
namespace AccordionBus.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за перемещение и прорисовку объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningAccordionBus : DrawningBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <param name="additionalColor"></param>
|
||||
/// <param name="onePart"></param>
|
||||
/// <param name="fiveDoors"></param>
|
||||
public DrawningAccordionBus(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool onePart, bool fiveDoors): base(130, 20)
|
||||
{
|
||||
EntityBus = new EntityAccordionBus(speed, weight, bodyColor, additionalColor, onePart, fiveDoors);
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовка транспорта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBus == null || EntityBus is not EntityAccordionBus accordionBus || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (!accordionBus.OnePart)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brWhite = new SolidBrush(Color.White);
|
||||
Brush br = new SolidBrush(accordionBus.BodyColor);
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
Brush additionalBrush = new SolidBrush(accordionBus.AdditionalColor);
|
||||
//корпус
|
||||
g.FillRectangle(br, _startPosX.Value + 70, _startPosY.Value, 60, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value, 60, 15);
|
||||
|
||||
//колёса
|
||||
g.FillEllipse(brWhite, _startPosX.Value + 75, _startPosY.Value + 10, 10, 10);
|
||||
g.FillEllipse(brWhite, _startPosX.Value + 110, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 110, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 10, 10, 10);
|
||||
|
||||
//стёкла
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 72, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 72, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 82, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 82, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 92, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 92, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 102, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 102, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 112, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 112, _startPosY.Value + 3, 5, 5);
|
||||
|
||||
//гормошка
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value, _startPosX.Value + 62, _startPosY.Value + 3);
|
||||
g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 3, _startPosX.Value + 65, _startPosY.Value);
|
||||
g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value, _startPosX.Value + 67, _startPosY.Value + 3);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 3, _startPosX.Value + 70, _startPosY.Value);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 15, _startPosX.Value + 62, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 12, _startPosX.Value + 65, _startPosY.Value + 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value + 15, _startPosX.Value + 67, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 12, _startPosX.Value + 70, _startPosY.Value + 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 3, _startPosX.Value + 62, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 3, _startPosX.Value + 67, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value, _startPosX.Value + 65, _startPosY.Value + 15);
|
||||
|
||||
//двери
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 123, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 123, _startPosY.Value + 5, 5, 10);
|
||||
if (accordionBus.FiveDoors)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 87, _startPosY.Value + 9, 21, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 87, _startPosY.Value + 9, 21, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 53, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 53, _startPosY.Value + 5, 5, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 27, _startPosY.Value + 9, 11, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 27, _startPosY.Value + 9, 11, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
265
AccordionBus/AccordionBus/Drawnings/DrawningBus.cs
Normal file
@ -0,0 +1,265 @@
|
||||
using AccordionBus.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.Drawnings
|
||||
{
|
||||
public class DrawningBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBus? EntityBus { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWeight;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки авто
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя координата прорисовки авто
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки авто
|
||||
/// </summary>
|
||||
private readonly int _drawningBusWeight = 60;
|
||||
/// <summary>
|
||||
/// Высота прорисовки авто
|
||||
/// </summary>
|
||||
private readonly int _drawningBusHeight = 20;
|
||||
/// <summary>
|
||||
/// Координата Х объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int? GetPosX() => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int? GetPosY() => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetWidth() => _drawningBusWeight;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetHeight() => _drawningBusHeight;
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningBus()
|
||||
{
|
||||
_pictureWeight = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор границ объекта
|
||||
/// </summary>
|
||||
/// <param name="drawningBusWeight">Ширина</param>
|
||||
/// <param name="drawningBusHeight">Высота</param>
|
||||
protected DrawningBus(int drawningBusWeight, int drawningBusHeight) : this()
|
||||
{
|
||||
_drawningBusWeight = drawningBusWeight;
|
||||
_drawningBusHeight = drawningBusHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор пораметров
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningBus(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityBus = new EntityBus(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="weight">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена</returns>
|
||||
public bool SetPictureSize(int weight, int height)
|
||||
{
|
||||
if (weight < _drawningBusWeight || height < _drawningBusHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_pictureWeight = weight;
|
||||
_pictureHeight = height;
|
||||
|
||||
if (_startPosX.HasValue && _startPosX.Value + _drawningBusWeight > _pictureWeight)
|
||||
{
|
||||
_startPosX -= _startPosX.Value + _drawningBusWeight - _pictureWeight;
|
||||
}
|
||||
else if (_startPosY.HasValue && _startPosY.Value + _drawningBusHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY -= _startPosY.Value + _drawningBusHeight - _pictureHeight;
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWeight.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (x + _drawningBusWeight > _pictureWeight)
|
||||
{
|
||||
_startPosX = x - (x + _drawningBusWeight - _pictureWeight);
|
||||
}
|
||||
else if (x < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
}
|
||||
|
||||
if (y + _drawningBusHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = y - (y + _drawningBusHeight - _pictureHeight);
|
||||
}
|
||||
else if (y < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = y;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещение выполнено, false - перемещение невозможнор</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityBus == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityBus.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityBus.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
return true;
|
||||
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityBus.Step + _drawningBusWeight < _pictureWeight)
|
||||
{
|
||||
_startPosX += (int)EntityBus.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = _pictureWeight - _drawningBusWeight;
|
||||
}
|
||||
return true;
|
||||
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityBus.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityBus.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
return true;
|
||||
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityBus.Step + _drawningBusHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityBus.Step;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningBusHeight;
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовка транспорта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBus == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brDoor = new SolidBrush(Color.Gray);
|
||||
|
||||
//корпус
|
||||
Brush br = new SolidBrush(EntityBus.BodyColor);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value, 60, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 60, 15);
|
||||
|
||||
//колёса
|
||||
Brush brWhite = new SolidBrush(Color.White);
|
||||
g.FillEllipse(brWhite, _startPosX.Value + 5, _startPosY.Value + 10, 10, 10);
|
||||
g.FillEllipse(brWhite, _startPosX.Value + 40, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 10, 10, 10);
|
||||
|
||||
//стёкла
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 2, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 12, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 12, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 32, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 32, _startPosY.Value + 3, 5, 5);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 42, _startPosY.Value + 3, 5, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value + 3, 5, 5);
|
||||
|
||||
//дверь
|
||||
g.FillRectangle(brDoor, _startPosX.Value + 20, _startPosY.Value + 5, 5, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 5, 5, 10);
|
||||
}
|
||||
}
|
||||
}
|
43
AccordionBus/AccordionBus/Entities/EntityAccordionBus.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// класс-сущность "автобус с гормошкой"
|
||||
/// </summary>
|
||||
public class EntityAccordionBus : EntityBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; set; }
|
||||
/// <summary>
|
||||
/// Одна часть
|
||||
/// </summary>
|
||||
public bool OnePart { get; set; }
|
||||
/// <summary>
|
||||
/// 5 дверей
|
||||
/// </summary>
|
||||
public bool FiveDoors { get; set; }
|
||||
/// <summary>
|
||||
/// инициализация полей объекта-класса
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="onePart">1 часть</param>
|
||||
/// <param name="fiveDoors">5 дверей</param>
|
||||
public EntityAccordionBus(int speed, double weight, Color bodyColor,
|
||||
Color additionalColor, bool onePart, bool fiveDoors) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
OnePart = onePart;
|
||||
FiveDoors = fiveDoors;
|
||||
}
|
||||
}
|
||||
}
|
43
AccordionBus/AccordionBus/Entities/EntityBus.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// класс-сущность "Автобус"
|
||||
/// </summary>
|
||||
public class EntityBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; set; }
|
||||
/// <summary>
|
||||
/// Шаг
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityBus(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
39
AccordionBus/AccordionBus/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace AccordionBus
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace AccordionBus
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
181
AccordionBus/AccordionBus/FormAccordionBus.Designer.cs
generated
Normal file
@ -0,0 +1,181 @@
|
||||
namespace AccordionBus
|
||||
{
|
||||
partial class FormAccordionBus
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
pictureBoxAccordionBus = new PictureBox();
|
||||
buttonCreateAccordionBus = new Button();
|
||||
ButtonUp = new Button();
|
||||
ButtonRight = new Button();
|
||||
ButtonLeft = new Button();
|
||||
ButtonDown = new Button();
|
||||
buttonCreateBus = new Button();
|
||||
comboBoxStratregy = new ComboBox();
|
||||
buttonStrategyStap = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAccordionBus).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxAccordionBus
|
||||
//
|
||||
pictureBoxAccordionBus.Dock = DockStyle.Fill;
|
||||
pictureBoxAccordionBus.Location = new Point(0, 0);
|
||||
pictureBoxAccordionBus.Name = "pictureBoxAccordionBus";
|
||||
pictureBoxAccordionBus.Size = new Size(882, 453);
|
||||
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.Name = "ButtonUp";
|
||||
ButtonUp.Size = new Size(30, 30);
|
||||
ButtonUp.TabIndex = 2;
|
||||
ButtonUp.UseVisualStyleBackColor = true;
|
||||
ButtonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// ButtonRight
|
||||
//
|
||||
ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonRight.BackgroundImage = Properties.Resources.buttRIght;
|
||||
ButtonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonRight.ImageAlign = ContentAlignment.MiddleLeft;
|
||||
ButtonRight.Location = new Point(809, 411);
|
||||
ButtonRight.Name = "ButtonRight";
|
||||
ButtonRight.Size = new Size(30, 30);
|
||||
ButtonRight.TabIndex = 3;
|
||||
ButtonRight.UseVisualStyleBackColor = true;
|
||||
ButtonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// ButtonLeft
|
||||
//
|
||||
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonLeft.BackgroundImage = Properties.Resources.buttLeft;
|
||||
ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonLeft.ImageAlign = ContentAlignment.MiddleLeft;
|
||||
ButtonLeft.Location = new Point(737, 411);
|
||||
ButtonLeft.Name = "ButtonLeft";
|
||||
ButtonLeft.Size = new Size(30, 30);
|
||||
ButtonLeft.TabIndex = 4;
|
||||
ButtonLeft.UseVisualStyleBackColor = true;
|
||||
ButtonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// ButtonDown
|
||||
//
|
||||
ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonDown.BackgroundImage = Properties.Resources.buttDown;
|
||||
ButtonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonDown.ImageAlign = ContentAlignment.MiddleLeft;
|
||||
ButtonDown.Location = new Point(773, 411);
|
||||
ButtonDown.Name = "ButtonDown";
|
||||
ButtonDown.Size = new Size(30, 30);
|
||||
ButtonDown.TabIndex = 5;
|
||||
ButtonDown.UseVisualStyleBackColor = true;
|
||||
ButtonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateBus
|
||||
//
|
||||
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;
|
||||
//
|
||||
// buttonStrategyStap
|
||||
//
|
||||
buttonStrategyStap.Location = new Point(761, 46);
|
||||
buttonStrategyStap.Name = "buttonStrategyStap";
|
||||
buttonStrategyStap.Size = new Size(78, 29);
|
||||
buttonStrategyStap.TabIndex = 8;
|
||||
buttonStrategyStap.Text = "Шаг";
|
||||
buttonStrategyStap.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStap.Click += buttonStrategyStap_Click;
|
||||
//
|
||||
// FormAccordionBus
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
Controls.Add(buttonStrategyStap);
|
||||
Controls.Add(comboBoxStratregy);
|
||||
Controls.Add(buttonCreateBus);
|
||||
Controls.Add(ButtonDown);
|
||||
Controls.Add(ButtonLeft);
|
||||
Controls.Add(ButtonRight);
|
||||
Controls.Add(ButtonUp);
|
||||
Controls.Add(buttonCreateAccordionBus);
|
||||
Controls.Add(pictureBoxAccordionBus);
|
||||
Name = "FormAccordionBus";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Автобус с гормошкой";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAccordionBus).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#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 Button buttonStrategyStap;
|
||||
}
|
||||
}
|
130
AccordionBus/AccordionBus/FormAccordionBus.cs
Normal file
@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using AccordionBus.Drawnings;
|
||||
using AccordionBus.MovementStrategy;
|
||||
|
||||
namespace AccordionBus
|
||||
{
|
||||
public partial class FormAccordionBus : Form
|
||||
{
|
||||
private DrawningBus? _drawningBus;
|
||||
private AbstractStrategy? _strategy;
|
||||
public FormAccordionBus()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningBus.DrawTransport(gr);
|
||||
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)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "ButtonUp":
|
||||
result = _drawningBus.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "ButtonDown":
|
||||
result = _drawningBus.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "ButtonLeft":
|
||||
result = _drawningBus.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "ButtonRight":
|
||||
result = _drawningBus.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonStrategyStap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBus == null) return;
|
||||
if (comboBoxStratregy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStratregy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null
|
||||
};
|
||||
if (_strategy == null) return;
|
||||
_strategy.SetData(new MoveableBus(_drawningBus), pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null) return;
|
||||
comboBoxStratregy.Enabled = false;
|
||||
_strategy.MakeStap();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStratregy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
<?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
|
||||
|
||||
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>
|
||||
@ -26,36 +26,36 @@
|
||||
<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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
125
AccordionBus/AccordionBus/MovementStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект
|
||||
/// </summary>
|
||||
private IMoveableObjects? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус стратегии
|
||||
/// </summary>
|
||||
private StrategyStatus? _state = StrategyStatus.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Получение статуса
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public StrategyStatus? GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Инициализация полей
|
||||
/// </summary>
|
||||
/// <param name="moveableObject"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public void SetData(IMoveableObjects moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Напавление
|
||||
/// </summary>
|
||||
public void MakeStap()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress) return;
|
||||
if (IsTargetDestination())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг влево
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
/// <summary>
|
||||
/// Шаг вправо
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
/// <summary>
|
||||
/// Шаг вверх
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
/// <summary>
|
||||
/// Шаг вниз
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
/// <summary>
|
||||
/// Получение параметров
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected ObjectParameters? GetObjectParameters() => _moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Получение шага
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStap()
|
||||
{
|
||||
if(_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достижение цели
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestination();
|
||||
/// <summary>
|
||||
/// Сделать шаг
|
||||
/// </summary>
|
||||
/// <param name="movementDirection"></param>
|
||||
/// <returns></returns>
|
||||
private bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if(_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с пперемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// попытка переместить объект в указаном направлении
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещение удалось false - перемещение невозможно</returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
||||
}
|
33
AccordionBus/AccordionBus/MovementStrategy/MoveToBorder.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.MovementStrategy
|
||||
{
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestination()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder() == FieldWidth && objParams.DownBorder() == FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (objParams.RightBorder() < FieldWidth) MoveRight();
|
||||
if (objParams.DownBorder() < FieldHeight) MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
56
AccordionBus/AccordionBus/MovementStrategy/MoveToCenter.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.MovementStrategy
|
||||
{
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestination()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal() - GetStap() <= FieldWidth / 2
|
||||
&& objParams.ObjectMiddleHorizontal() + GetStap() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical() - GetStap() <= FieldHeight / 2
|
||||
&& objParams.ObjectMiddleVertical() + GetStap() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStap())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStap())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
AccordionBus/AccordionBus/MovementStrategy/MoveableBus.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using AccordionBus.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-реализация IMoveableObjects с использованием DrawningBus
|
||||
/// </summary>
|
||||
public class MoveableBus : IMoveableObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект DrawningBus
|
||||
/// </summary>
|
||||
private readonly DrawningBus? _car;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="car">Объект класса DrawningBus</param>
|
||||
public MoveableBus(DrawningBus? car)
|
||||
{
|
||||
_car = car;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_car == null || _car.EntityBus == null || _car.GetPosX() == null || _car.GetPosY() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_car.GetPosX().Value, _car.GetPosY().Value, _car.GetWidth(), _car.GetHeight());
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_car?.EntityBus?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_car == null || _car.EntityBus == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _car.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
MovementDirection.Left => DirectionType.Left,
|
||||
MovementDirection.Right => DirectionType.Right,
|
||||
MovementDirection.Up => DirectionType.Up,
|
||||
MovementDirection.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknow,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.MovementStrategy
|
||||
{
|
||||
public enum MovementDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
/// </summary>
|
||||
public class ObjectParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Координата Х
|
||||
/// </summary>
|
||||
private readonly int _x;
|
||||
/// <summary>
|
||||
/// Координата Y
|
||||
/// </summary>
|
||||
private readonly int _y;
|
||||
/// <summary>
|
||||
/// Ширина
|
||||
/// </summary>
|
||||
private readonly int _width;
|
||||
/// <summary>
|
||||
/// Высота
|
||||
/// </summary>
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int LeftBorder() => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int TopBorder() => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RightBorder() => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int DownBorder() => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int ObjectMiddleHorizontal() => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int ObjectMiddleVertical() => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата Х</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width"Ширина></param>
|
||||
/// <param name="height">Высота</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
24
AccordionBus/AccordionBus/MovementStrategy/StrategyStatus.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccordionBus.MovementStrategy
|
||||
{
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// всё готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
/// <summary>
|
||||
/// В процессе
|
||||
/// </summary>
|
||||
InProgress,
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
||||
}
|
@ -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 Form1());
|
||||
Application.Run(new FormAccordionBus());
|
||||
}
|
||||
}
|
||||
}
|
103
AccordionBus/AccordionBus/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace AccordionBus.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AccordionBus.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap buttDown {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("buttDown", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap buttLeft {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("buttLeft", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap buttRIght {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("buttRIght", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap buttUp {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("buttUp", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
133
AccordionBus/AccordionBus/Properties/Resources.resx
Normal file
@ -0,0 +1,133 @@
|
||||
<?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>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="buttDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\buttDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="buttLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\buttLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="buttRIght" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\buttRIght.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="buttUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\buttUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
BIN
AccordionBus/AccordionBus/Resources/buttDown.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
AccordionBus/AccordionBus/Resources/buttLeft.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
AccordionBus/AccordionBus/Resources/buttRIght.png
Normal file
After Width: | Height: | Size: 8.0 KiB |
BIN
AccordionBus/AccordionBus/Resources/buttUp.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
AccordionBus/Graphics/buttDown.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
AccordionBus/Graphics/buttLeft.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
AccordionBus/Graphics/buttRIght.png
Normal file
After Width: | Height: | Size: 8.0 KiB |
BIN
AccordionBus/Graphics/buttUp.png
Normal file
After Width: | Height: | Size: 8.5 KiB |