Compare commits

..

2 Commits
main ... lab_2

Author SHA1 Message Date
sardq
467726e7d3 2 лабораторная 2023-10-21 21:47:58 +04:00
sardq
05d5b82867 1 лабораторная 2023-10-20 21:54:03 +04:00
19 changed files with 3193 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,180 @@
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();
((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);
//
// 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.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;
}
}

View File

@ -0,0 +1,92 @@
using HoistingCrane.DrawningObjects;
using HoistingCrane.MovementStrategy;
namespace HoistingCrane
{
public partial class CraneVisual : Form
{
private DrawingCrane? _drawingCrane;
private AbstractStrategy? _abstractStrategy;
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();
_drawingCrane = new DrawingCrane(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), 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();
_drawingCrane = new AdditionalDrawingCrane(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxCrane.Width, pictureBoxCrane.Height);
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 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,11 @@
namespace HoistingCrane
{
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,160 @@
using HoistingCrane.Entities;
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 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,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, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(new CraneVisual());
} }
} }
} }

View File

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