Compare commits

...

4 Commits
main ... lab_4

Author SHA1 Message Date
sardq
2523d4f151 лабораторная 4 2023-11-12 11:51:51 +04:00
sardq
0a16b54539 3 лабораторная 2023-11-12 10:47:58 +04:00
sardq
467726e7d3 2 лабораторная 2023-10-21 21:47:58 +04:00
sardq
05d5b82867 1 лабораторная 2023-10-20 21:54:03 +04:00
25 changed files with 3849 additions and 170 deletions

View File

@ -0,0 +1,88 @@
namespace HoistingCrane.MovementStrategy
{
public abstract class AbstractStrategy
{
// Перемещаемый объект
private IMoveableObject? _moveableObject;
// Статус перемещения
private Status _state = Status.NotInit;
// Ширина поля
protected int FieldWidth { get; private set; }
// Высота поля
protected int FieldHeight { get; private set; }
// Статус перемещения
public Status GetStatus() { return _state; }
/// <param name="moveableObject">Перемещаемый объект</param>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
// Шаг перемещения
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
// Перемещение влевo
// <returns>Результат перемещения (true - удалось переместиться, false -неудача)</returns>
protected bool MoveLeft() => MoveTo(DirectionType.Left);
// Перемещение вправо false - неудача)</returns>
protected bool MoveRight() => MoveTo(DirectionType.Right);
// Перемещение вверх
// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveUp() => MoveTo(DirectionType.Up);
// Перемещение вниз
// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
protected bool MoveDown() => MoveTo(DirectionType.Down);
// Параметры объекта
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
// Шаг объекта
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
// Перемещение к цели
protected abstract void MoveToTarget();
// Достигнута ли цель
protected abstract bool IsTargetDestinaion();
// Попытка перемещения в требуемом направлении
// <param name="directionType">Направление</param>
// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,18 @@
namespace HoistingCrane.Entities
{
public class AdditionEntityCrane : EntityCrane
{
//дополнительный
public Color AdditionalColor { get; private set; }
//противовес
public bool CounterWeight { get; private set; }
//кран
public bool Crane { get; private set; }
public AdditionEntityCrane(int speed, double weight, Color bodyColor, Color additionalColor, bool counterWeight, bool crane) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
CounterWeight = counterWeight;
Crane = crane;
}
}
}

View File

@ -0,0 +1,41 @@
using HoistingCrane.Entities;
namespace HoistingCrane.DrawningObjects
{
public class AdditionalDrawingCrane : DrawingCrane
{
// Конструктор
public AdditionalDrawingCrane(int speed, double weight, Color bodyColor, Color additionalColor, bool counterWeight, bool crane, int width, int height) : base(speed, weight, bodyColor, width, height)
{
if (EntityCrane != null)
{
EntityCrane = new AdditionEntityCrane(speed, weight, bodyColor, additionalColor, counterWeight, crane);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityCrane is not AdditionEntityCrane transportCrane)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(transportCrane.AdditionalColor);
//противовес
if (transportCrane.CounterWeight)
{
g.DrawRectangle(pen, _startPositionX + 185, _startPositionY + 20, 15, 45);
}
//кран
if (transportCrane.Crane)
{
g.DrawRectangle(pen, _startPositionX + 20, _startPositionY, 30, 65);
g.DrawRectangle(pen, _startPositionX, _startPositionY, 20, 30);
g.FillRectangle(additionalBrush, _startPositionX + 20, _startPositionY, 30, 65);
g.FillRectangle(additionalBrush, _startPositionX, _startPositionY, 20, 30);
}
base.DrawTransport(g);
}
}
}

View File

@ -0,0 +1,194 @@
namespace HoistingCrane
{
partial class CraneVisual
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CraneVisual));
this.pictureBoxCrane = new System.Windows.Forms.PictureBox();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonStep = new System.Windows.Forms.Button();
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.buttonCreateAdditional = new System.Windows.Forms.Button();
this.buttonChoose = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCrane)).BeginInit();
this.SuspendLayout();
//
// pictureBoxCrane
//
this.pictureBoxCrane.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCrane.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCrane.Name = "pictureBoxCrane";
this.pictureBoxCrane.Size = new System.Drawing.Size(878, 444);
this.pictureBoxCrane.TabIndex = 0;
this.pictureBoxCrane.TabStop = false;
//
// buttonCreate
//
this.buttonCreate.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCreate.Location = new System.Drawing.Point(254, 378);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(170, 59);
this.buttonCreate.TabIndex = 24;
this.buttonCreate.Text = "создать кран";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonDown
//
this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage")));
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonDown.Location = new System.Drawing.Point(811, 414);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 23;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage")));
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonRight.Location = new System.Drawing.Point(847, 414);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 22;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage")));
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonLeft.Location = new System.Drawing.Point(775, 414);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 21;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUp
//
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonUp.Location = new System.Drawing.Point(811, 378);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 20;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonStep
//
this.buttonStep.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonStep.Location = new System.Drawing.Point(787, 45);
this.buttonStep.Name = "buttonStep";
this.buttonStep.Size = new System.Drawing.Size(80, 35);
this.buttonStep.TabIndex = 27;
this.buttonStep.Text = "шаг";
this.buttonStep.UseVisualStyleBackColor = true;
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
//
// comboBoxStrategy
//
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxStrategy.FormattingEnabled = true;
this.comboBoxStrategy.Items.AddRange(new object[] {
"0",
"1"});
this.comboBoxStrategy.Location = new System.Drawing.Point(695, 6);
this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(182, 33);
this.comboBoxStrategy.TabIndex = 26;
//
// buttonCreateAdditional
//
this.buttonCreateAdditional.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonCreateAdditional.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCreateAdditional.Location = new System.Drawing.Point(0, 378);
this.buttonCreateAdditional.Name = "buttonCreateAdditional";
this.buttonCreateAdditional.Size = new System.Drawing.Size(248, 59);
this.buttonCreateAdditional.TabIndex = 25;
this.buttonCreateAdditional.Text = "создать кран с утяжелителем и краном";
this.buttonCreateAdditional.UseVisualStyleBackColor = true;
this.buttonCreateAdditional.Click += new System.EventHandler(this.ButtonCreateAdditional_Click);
//
// buttonChoose
//
this.buttonChoose.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonChoose.Location = new System.Drawing.Point(430, 378);
this.buttonChoose.Name = "buttonChoose";
this.buttonChoose.Size = new System.Drawing.Size(170, 59);
this.buttonChoose.TabIndex = 28;
this.buttonChoose.Text = "Выбрать";
this.buttonChoose.UseVisualStyleBackColor = true;
this.buttonChoose.Click += new System.EventHandler(this.buttonChoose_Click);
//
// CraneVisual
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(878, 444);
this.Controls.Add(this.buttonChoose);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.buttonCreateAdditional);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.pictureBoxCrane);
this.Name = "CraneVisual";
this.Text = "HoistingCrane";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCrane)).EndInit();
this.ResumeLayout(false);
}
#endregion
private PictureBox pictureBoxCrane;
private Button buttonCreate;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private Button buttonUp;
private Button buttonStep;
private ComboBox comboBoxStrategy;
private Button buttonCreateAdditional;
private Button buttonChoose;
}
}

View File

@ -0,0 +1,120 @@
using HoistingCrane.DrawningObjects;
using HoistingCrane.MovementStrategy;
namespace HoistingCrane
{
public partial class CraneVisual : Form
{
private DrawingCrane? _drawingCrane;
private AbstractStrategy? _abstractStrategy;
public DrawingCrane? SelectedCrane { get; private set; }
public CraneVisual()
{
InitializeComponent();
}
private void Draw()
{
if (_drawingCrane == null) return;
Bitmap btm = new(pictureBoxCrane.Width, pictureBoxCrane.Height);
Graphics gr = Graphics.FromImage(btm);
_drawingCrane.DrawTransport(gr);
pictureBoxCrane.Image = btm;
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_drawingCrane = new DrawingCrane(random.Next(100, 300),
random.Next(1000, 3000),
color, pictureBoxCrane.Width, pictureBoxCrane.Height);
_drawingCrane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonCreateAdditional_Click(object sender, EventArgs e)
{
Random random = new Random();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color Additionalcolor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
Additionalcolor = dialog.Color;
}
_drawingCrane = new AdditionalDrawingCrane(random.Next(100, 300), random.Next(1000, 3000), color, Additionalcolor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxCrane.Width, pictureBoxCrane.Height);
_drawingCrane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingCrane == null) return;
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingCrane.MoveCrane(DirectionType.Up);
break;
case "buttonDown":
_drawingCrane.MoveCrane(DirectionType.Down);
break;
case "buttonRight":
_drawingCrane.MoveCrane(DirectionType.Right);
break;
case "buttonLeft":
_drawingCrane.MoveCrane(DirectionType.Left);
break;
}
Draw();
}
private void buttonChoose_Click(object sender, EventArgs e)
{
SelectedCrane = _drawingCrane;
DialogResult = DialogResult.OK;
}
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawingCrane == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawningObjectsCrane(_drawingCrane), pictureBoxCrane.Width,
pictureBoxCrane.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,101 @@
using HoistingCrane.DrawningObjects;
using HoistingCrane.MovementStrategy;
namespace HoistingCrane.Generics
{
/// Параметризованный класс для набора объектов DrawningCar
internal class CranesGenericCollection<T, U>
where T : DrawingCrane
where U : IMoveableObject
{
/// Ширина окна прорисовки
private readonly int _pictureWidth;
/// Высота окна прорисовки
private readonly int _pictureHeight;
/// Размер занимаемого объектом места (ширина)
private readonly int _placeSizeWidth = 200;
/// Размер занимаемого объектом места (высота)
private readonly int _placeSizeHeight = 150;
/// Набор объектов
private readonly SetGeneric<T> _collection;
/// Конструктор
public CranesGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// Перегрузка оператора сложения
public static int operator +(CranesGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return -1;
}
return collect._collection.Insert(obj);
}
/// Перегрузка оператора вычитания
public static bool operator -(CranesGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj == null)
{
return false;
}
return collect?._collection.Remove(pos) ?? false;
}
/// Получение объекта IMoveableObject
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
/// Вывод всего набора объектов
public Bitmap ShowCars()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
/// Метод отрисовки фона
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{//линия разетки места
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// Метод прорисовки объектов
private void DrawObjects(Graphics g)
{
T? obj;
int j = _pictureWidth/_placeSizeWidth-1;
int k = _pictureHeight/_placeSizeHeight-1;
foreach (var crane in _collection.GetCranes())
{
if (crane != null)
{
if (j < 0)
{
j += _pictureWidth / _placeSizeWidth;
k--;
}
obj = crane;
obj.SetPosition(_placeSizeWidth * j, _placeSizeHeight * k);
obj.DrawTransport(g);
j--;
}
}
}
}
}

View File

@ -0,0 +1,52 @@
using HoistingCrane.DrawningObjects;
using HoistingCrane.Generics;
using HoistingCrane.MovementStrategy;
namespace HoistingCrane
{
internal class CranesGenericStorage
{
/// Словарь (хранилище)
readonly Dictionary<string, CranesGenericCollection<DrawingCrane, DrawningObjectsCrane>> _craneStorages;
/// Возвращение списка названий наборов
public List<string> Keys => _craneStorages.Keys.ToList();
/// Ширина окна отрисовки
private readonly int _pictureWidth;
/// Высота окна отрисовки
private readonly int _pictureHeight;
/// Конструктор
public CranesGenericStorage(int pictureWidth, int pictureHeight)
{
_craneStorages = new Dictionary<string, CranesGenericCollection<DrawingCrane, DrawningObjectsCrane>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// Добавление набора
public void AddSet(string name)
{
if (_craneStorages.ContainsKey(name))
{
return;
}
_craneStorages.Add(name, new CranesGenericCollection<DrawingCrane, DrawningObjectsCrane>(_pictureWidth, _pictureHeight));
}
/// Удаление набора
public void DelSet(string name)
{
if (_craneStorages.ContainsKey(name))
{
_craneStorages.Remove(name);
}
}
/// Доступ к набору
public CranesGenericCollection<DrawingCrane, DrawningObjectsCrane>? this[string ind]
{
get
{
if (_craneStorages.ContainsKey(ind))
return _craneStorages[ind];
return null;
}
}
}
}

View File

@ -0,0 +1,11 @@
namespace HoistingCrane
{
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,163 @@
using HoistingCrane.Entities;
using HoistingCrane.MovementStrategy;
namespace HoistingCrane.DrawningObjects
{
public class DrawingCrane
{
public EntityCrane? EntityCrane { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPositionX;
protected int _startPositionY;
protected readonly int _craneWidth = 200;
protected readonly int _craneHeight = 150;
public IMoveableObject GetMoveableObject => new DrawningObjectsCrane(this);
public DrawingCrane(int speed, double weight, Color bodyColor, int width, int height)
{
if ((_craneWidth > width) || (_craneHeight > height)) return;
_pictureHeight = height;
_pictureWidth = width;
EntityCrane = new EntityCrane(speed, weight, bodyColor);
}
protected DrawingCrane(int speed, double weight, Color bodyColor, int width, int height, int craneWidth, int craneHeight)
{
if ((craneWidth > width) || (craneHeight > height)) return;
_pictureHeight = height;
_pictureWidth = width;
_craneHeight = craneHeight;
_craneWidth = craneWidth;
EntityCrane = new EntityCrane(speed, weight, bodyColor);
}
public void SetPosition(int x, int y)
{
while (x + _craneWidth > _pictureWidth)
{
x -= _pictureWidth;
}
_startPositionX = x;
while (y + _craneHeight > _pictureHeight)
{
y -= _pictureHeight;
}
_startPositionY = y;
}
public void MoveCrane(DirectionType direction)
{
if (EntityCrane == null) return;
switch (direction)
{
case DirectionType.Left:
if (_startPositionX - EntityCrane.Step > 0)
{
_startPositionX -= (int)EntityCrane.Step;
}
break;
case DirectionType.Right:
if (_startPositionX + EntityCrane.Step + _craneWidth < _pictureWidth)
{
_startPositionX += (int)EntityCrane.Step;
}
break;
case DirectionType.Up:
if (_startPositionY - EntityCrane.Step > 0)
{
_startPositionY -= (int)EntityCrane.Step;
}
break;
case DirectionType.Down:
if (_startPositionY + EntityCrane.Step + _craneHeight < _pictureHeight)
{
_startPositionY += (int)EntityCrane.Step;
}
break;
}
}
public int GetPosX => _startPositionX;
public int GetPosY => _startPositionY;
public int GetWidth => _craneWidth;
public int GetHeight => _craneHeight;
public bool CanMove(DirectionType direction)
{
if (EntityCrane == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPositionX - EntityCrane.Step > 0,
//вверх
DirectionType.Up => _startPositionY - EntityCrane.Step > 0,
// вправо
DirectionType.Right => _startPositionX + EntityCrane.Step - _craneWidth < _pictureWidth,
//вниз
DirectionType.Down => _startPositionY + EntityCrane.Step - _craneHeight < _pictureHeight
};
}
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityCrane == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
_startPositionX -= (int)EntityCrane.Step;
break;
//вверх
case DirectionType.Up:
_startPositionY -= (int)EntityCrane.Step;
break;
// вправо
case DirectionType.Right:
_startPositionX += (int)EntityCrane.Step;
break;
//вниз
case DirectionType.Down:
_startPositionY += (int)EntityCrane.Step;
break;
}
}
public virtual void DrawTransport(Graphics g)
{
if (EntityCrane == null) return;
Pen pen = new Pen(Color.Black);
Brush bodybrush = new SolidBrush(EntityCrane.BodyColor);
// Гусеницы
g.DrawLine(pen, _startPositionX + 5, _startPositionY + 110, _startPositionX + 195, _startPositionY + 110);
g.DrawLine(pen, _startPositionX, _startPositionY + 115, _startPositionX, _startPositionY + 145);
g.DrawLine(pen, _startPositionX + 5, _startPositionY + 150, _startPositionX + 195, _startPositionY + 150);
g.DrawLine(pen, _startPositionX + 200, _startPositionY + 115, _startPositionX + 200, _startPositionY + 145);
g.DrawArc(pen, _startPositionX, _startPositionY + 110, _craneWidth / 20, _craneHeight / 15, 135, 180);
g.DrawArc(pen, _startPositionX, _startPositionY + 140, _craneWidth / 20, _craneHeight / 15, 45, 180);
g.DrawArc(pen, _startPositionX + 190, _startPositionY + 110, _craneWidth / 20, _craneHeight / 20, 225, 180);
g.DrawArc(pen, _startPositionX + 190, _startPositionY + 143, _craneWidth / 20, _craneHeight / 20, 315, 180);
// основное тело
g.DrawRectangle(pen, _startPositionX + 10, _startPositionY + 65, 180, 40);
g.FillRectangle(bodybrush, _startPositionX + 10, _startPositionY + 65, 180, 40);
//катки
g.DrawEllipse(pen, _startPositionX + 2, _startPositionY + 112, 36, 36);
g.DrawEllipse(pen, _startPositionX + 160, _startPositionY + 112, 36, 36);
g.DrawEllipse(pen, _startPositionX + 45, _startPositionY + 128, 20, 20);
g.DrawEllipse(pen, _startPositionX + 89, _startPositionY + 128, 20, 20);
g.DrawEllipse(pen, _startPositionX + 133, _startPositionY + 128, 20, 20);
g.DrawEllipse(pen, _startPositionX + 74, _startPositionY + 112, 10, 10);
g.DrawEllipse(pen, _startPositionX + 111, _startPositionY + 112, 10, 10);
//кабинка и выхлоп
g.DrawRectangle(pen, _startPositionX + 60, _startPositionY + 10, 20, 55);
g.DrawRectangle(pen, _startPositionX + 110, _startPositionY, 75, 65);
}
}
}

View File

@ -0,0 +1,27 @@
using HoistingCrane.DrawningObjects;
namespace HoistingCrane.MovementStrategy
{
public class DrawningObjectsCrane : IMoveableObject
{
private readonly DrawingCrane? _drawingCrane = null;
public DrawningObjectsCrane(DrawingCrane drawingCrane)
{
_drawingCrane = drawingCrane;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawingCrane == null || _drawingCrane.EntityCrane == null)
{
return null;
}
return new ObjectParameters(_drawingCrane.GetPosX, _drawingCrane.GetPosY, _drawingCrane.GetWidth, _drawingCrane.GetHeight);
}
}
public int GetStep => (int)(_drawingCrane?.EntityCrane?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) => _drawingCrane?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) => _drawingCrane?.MoveTransport(direction);
}
}

View File

@ -0,0 +1,20 @@
namespace HoistingCrane.Entities
{
public class EntityCrane
{
//скорость
public int Speed { get; private set; }
//вес
public double Weight { get; private set; }
//основной цввет
public Color BodyColor { get; private set; }
//шаг перемещения
public double Step => (double)Speed * 100 / Weight;
public EntityCrane(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -1,39 +0,0 @@
namespace HoistingCrane
{
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
}
}

View File

@ -1,10 +0,0 @@
namespace HoistingCrane
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -1,120 +0,0 @@
<?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>

View File

@ -0,0 +1,189 @@
namespace HoistingCrane
{
partial class FormCraneCollection
{
/// <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.groupBoxInstruments = new System.Windows.Forms.GroupBox();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.buttonReload = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.groupBoxSet = new System.Windows.Forms.GroupBox();
this.textBoxStorageName = new System.Windows.Forms.TextBox();
this.buttonAddSet = new System.Windows.Forms.Button();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.buttonRemoveSet = new System.Windows.Forms.Button();
this.groupBoxInstruments.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.groupBoxSet.SuspendLayout();
this.SuspendLayout();
//
// groupBoxInstruments
//
this.groupBoxInstruments.Controls.Add(this.groupBoxSet);
this.groupBoxInstruments.Controls.Add(this.maskedTextBoxNumber);
this.groupBoxInstruments.Controls.Add(this.buttonReload);
this.groupBoxInstruments.Controls.Add(this.buttonDelete);
this.groupBoxInstruments.Controls.Add(this.buttonAdd);
this.groupBoxInstruments.Location = new System.Drawing.Point(811, 0);
this.groupBoxInstruments.Name = "groupBoxInstruments";
this.groupBoxInstruments.Size = new System.Drawing.Size(185, 464);
this.groupBoxInstruments.TabIndex = 0;
this.groupBoxInstruments.TabStop = false;
this.groupBoxInstruments.Text = "Инструменты";
//
// maskedTextBoxNumber
//
this.maskedTextBoxNumber.Location = new System.Drawing.Point(23, 319);
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(150, 31);
this.maskedTextBoxNumber.TabIndex = 9;
//
// buttonReload
//
this.buttonReload.Location = new System.Drawing.Point(12, 397);
this.buttonReload.Name = "buttonReload";
this.buttonReload.Size = new System.Drawing.Size(167, 35);
this.buttonReload.TabIndex = 8;
this.buttonReload.Text = "Обновить экран";
this.buttonReload.UseVisualStyleBackColor = true;
this.buttonReload.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(12, 356);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(167, 35);
this.buttonDelete.TabIndex = 7;
this.buttonDelete.Text = "Удалить кран";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.ButtonRemoveCrane_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(12, 278);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(167, 35);
this.buttonAdd.TabIndex = 6;
this.buttonAdd.Text = "Добавить кран";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAddCrane_Click);
//
// pictureBoxCollection
//
this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(996, 434);
this.pictureBoxCollection.TabIndex = 5;
this.pictureBoxCollection.TabStop = false;
//
// groupBoxSet
//
this.groupBoxSet.Controls.Add(this.textBoxStorageName);
this.groupBoxSet.Controls.Add(this.buttonAddSet);
this.groupBoxSet.Controls.Add(this.listBoxStorages);
this.groupBoxSet.Controls.Add(this.buttonRemoveSet);
this.groupBoxSet.Location = new System.Drawing.Point(6, 21);
this.groupBoxSet.Name = "groupBoxSet";
this.groupBoxSet.Size = new System.Drawing.Size(179, 257);
this.groupBoxSet.TabIndex = 6;
this.groupBoxSet.TabStop = false;
this.groupBoxSet.Text = "Наборы";
//
// textBoxStorageName
//
this.textBoxStorageName.Location = new System.Drawing.Point(6, 30);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(150, 31);
this.textBoxStorageName.TabIndex = 14;
//
// buttonAddSet
//
this.buttonAddSet.Location = new System.Drawing.Point(6, 65);
this.buttonAddSet.Name = "buttonAddSet";
this.buttonAddSet.Size = new System.Drawing.Size(167, 35);
this.buttonAddSet.TabIndex = 12;
this.buttonAddSet.Text = "Добавить набор";
this.buttonAddSet.UseVisualStyleBackColor = true;
this.buttonAddSet.Click += new System.EventHandler(this.ButtonAddObject_Click);
//
// listBoxStorages
//
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 25;
this.listBoxStorages.Location = new System.Drawing.Point(6, 106);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(167, 104);
this.listBoxStorages.TabIndex = 13;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
//
// buttonRemoveSet
//
this.buttonRemoveSet.Location = new System.Drawing.Point(6, 216);
this.buttonRemoveSet.Name = "buttonRemoveSet";
this.buttonRemoveSet.Size = new System.Drawing.Size(167, 35);
this.buttonRemoveSet.TabIndex = 11;
this.buttonRemoveSet.Text = "Удалить набор";
this.buttonRemoveSet.UseVisualStyleBackColor = true;
this.buttonRemoveSet.Click += new System.EventHandler(this.ButtonDelObject_Click);
//
// FormCraneCollection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(996, 434);
this.Controls.Add(this.groupBoxInstruments);
this.Controls.Add(this.pictureBoxCollection);
this.Name = "FormCraneCollection";
this.Text = "Набор кранов";
this.groupBoxInstruments.ResumeLayout(false);
this.groupBoxInstruments.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.groupBoxSet.ResumeLayout(false);
this.groupBoxSet.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxInstruments;
private MaskedTextBox maskedTextBoxNumber;
private Button buttonReload;
private Button buttonDelete;
private Button buttonAdd;
private PictureBox pictureBoxCollection;
private GroupBox groupBoxSet;
private TextBox textBoxStorageName;
private Button buttonAddSet;
private ListBox listBoxStorages;
private Button buttonRemoveSet;
}
}

View File

@ -0,0 +1,133 @@
using HoistingCrane.DrawningObjects;
using HoistingCrane.Generics;
using HoistingCrane.MovementStrategy;
namespace HoistingCrane
{
public partial class FormCraneCollection : Form
{
private readonly CranesGenericStorage _storage;
public FormCraneCollection()
{
InitializeComponent();
_storage = new CranesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
private void ReloadObjects()
{
int index = listBoxStorages.SelectedIndex;
listBoxStorages.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
listBoxStorages.Items.Add(_storage.Keys[i]);
}
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
{
listBoxStorages.SelectedIndex = 0;
}
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
{
listBoxStorages.SelectedIndex = index;
}
}
private void ButtonAddObject_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
}
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxCollection.Image =
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowCars();
}
private void ButtonDelObject_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
private void ButtonAddCrane_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
CraneVisual form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (obj + form.SelectedCrane != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowCars();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveCrane_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (obj - pos)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = obj.ShowCars();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowCars();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,13 @@
namespace HoistingCrane.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
/// Шаг объекта
int GetStep { get; }
/// Проверка, можно ли переместиться по нужному направлению
bool CheckCanMove(DirectionType direction);
/// Изменение направления перещения объекта
void MoveObject(DirectionType direction);
}
}

View File

@ -0,0 +1,47 @@
namespace HoistingCrane.MovementStrategy
{
internal class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal <= FieldWidth && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth && objParams.ObjectMiddleHorizontal <= FieldHeight && objParams.ObjectMiddleHorizontal + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,47 @@
namespace HoistingCrane.MovementStrategy
{
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && objParams.ObjectMiddleVertical <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,42 @@
namespace HoistingCrane.MovementStrategy
{
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
/// <summary>
/// Левая граница
/// </summary>
public int LeftBorder => _x;
/// <summary>
/// Верхняя граница
/// </summary>
public int TopBorder => _y;
/// <summary>
/// Правая граница
/// </summary>
public int RightBorder => _x + _width;
/// <summary>
/// Нижняя граница
/// </summary>
public int DownBorder => _y + _height;
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleHorizontal => _x + _width / 2;
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleVertical => _y + _height / 2;
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -11,7 +11,7 @@ namespace HoistingCrane
// 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 FormCraneCollection());
}
}
}

View File

@ -0,0 +1,76 @@
namespace HoistingCrane.Generics
{
/// Параметризованный набор объектов
internal class SetGeneric<T>
where T : class
{
/// Массив объектов, которые храним
private readonly List<T?> _places;
/// Количество объектов в массиве
public int Count => _places.Count;
/// Максимальное количество объектов в списке
private readonly int _maxCount;
/// Конструктор
public SetGeneric(int count)
{
_maxCount = count;
_places = new List<T?>(count);
}
/// Добавление объекта в набор
public int Insert(T crane)
{
_places.Insert(0, crane);
return 0;
}
public int Insert(T crane, int position)
{
if (position < 0 || position >= _maxCount|| Count >= _maxCount)
return -1;
_places.Insert(position, crane);
return position;
}
/// Удаление объекта из набора с конкретной позиции
public bool Remove(int position)
{
if ((position < 0) || (position > _maxCount)) return false;
_places.RemoveAt(position);
return true;
}
/// Получение объекта из набора по позиции
public T? Get(int position)
{
if ((position < 0) || (position > Count)) return null;
return _places[position];
}
/// Получение объекта из набора по позиции
public T? this[int position]
{
get
{
if (position < 0 || position > _maxCount)
return null;
return _places[position];
}
set
{
if (position < 0 || position > _maxCount)
return;
_places[position] = value;
}
}
/// Проход по списку
public IEnumerable<T?> GetCranes(int? maxCranes = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxCranes.HasValue && i == maxCranes.Value)
{
yield break;
}
}
}
}
}

View File

@ -0,0 +1,10 @@
namespace HoistingCrane.MovementStrategy
{
// Статус выполнения операции перемещения
public enum Status
{
NotInit,
InProgress,
Finish
}
}