Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
fdd3f8a042 | |||
c8eed1e7df | |||
cfa3253cf1 | |||
1047be1e08 | |||
7d41cfe353 | |||
f631fce11e |
25
lainer/Lainer1.sln
Normal file
25
lainer/Lainer1.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.6.33829.357
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lainer1", "Lainer1\Lainer1.csproj", "{AB21363F-202A-4647-B3B2-6D522DF13DB8}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{AB21363F-202A-4647-B3B2-6D522DF13DB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{AB21363F-202A-4647-B3B2-6D522DF13DB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{AB21363F-202A-4647-B3B2-6D522DF13DB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{AB21363F-202A-4647-B3B2-6D522DF13DB8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {D9EDD43C-01B3-4787-8583-4650BC513AF7}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
69
lainer/Lainer1/AbstractStrategy.cs
Normal file
69
lainer/Lainer1/AbstractStrategy.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
using ProjectLainer;
|
||||||
|
using ProjectLainer.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectLainer.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; }
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||||
|
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||||
|
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||||
|
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();
|
||||||
|
private bool MoveTo(DirectionType directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
lainer/Lainer1/DirectionTypeEnum.cs
Normal file
10
lainer/Lainer1/DirectionTypeEnum.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace ProjectLainer
|
||||||
|
{
|
||||||
|
public enum DirectionType
|
||||||
|
{
|
||||||
|
Up = 1,
|
||||||
|
Down = 2,
|
||||||
|
Left = 3,
|
||||||
|
Right = 4
|
||||||
|
}
|
||||||
|
}
|
159
lainer/Lainer1/DrawingLainer.cs
Normal file
159
lainer/Lainer1/DrawingLainer.cs
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
using ProjectLainer.Entities;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace ProjectLainer.DrawningObjects
|
||||||
|
{
|
||||||
|
public class DrawingLainer
|
||||||
|
{
|
||||||
|
public EntityLainer? EntityLainer { get; protected set; }
|
||||||
|
private int _pictureWidth;
|
||||||
|
private int _pictureHeight;
|
||||||
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
|
public DrawingLainer(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height)
|
||||||
|
{
|
||||||
|
if (width < _LainerWidth || height < _LainerHeight)
|
||||||
|
return;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
EntityLainer = new EntityLainer(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DrawingLainer(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height, int carWidth, int carHeight)
|
||||||
|
{
|
||||||
|
if (width < _LainerWidth || height < _LainerHeight)
|
||||||
|
return;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_LainerWidth = carWidth;
|
||||||
|
_LainerHeight = carHeight;
|
||||||
|
EntityLainer = new EntityLainer(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (x + _LainerWidth < _pictureWidth && x + _LainerWidth > 0)
|
||||||
|
{
|
||||||
|
_startPosX = x;
|
||||||
|
}
|
||||||
|
if (y + _LainerHeight < _pictureHeight && y + _LainerHeight > 0)
|
||||||
|
{
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityLainer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||||
|
//îòðèñîâêà òðóá
|
||||||
|
Brush brush = new SolidBrush(Color.Black);
|
||||||
|
Rectangle smokestack1 = new Rectangle(_startPosX + 20, _startPosY, 20, 50);
|
||||||
|
Rectangle smokestack2 = new Rectangle(_startPosX + 60, _startPosY, 20, 50);
|
||||||
|
g.FillRectangle(brush, smokestack1);
|
||||||
|
g.FillRectangle(brush, smokestack2);
|
||||||
|
//ãðàíèöû ëàéíåðà
|
||||||
|
Pen pen = new(Color.Red);
|
||||||
|
brush = new SolidBrush(Color.Red);
|
||||||
|
Point point1 = new Point(_startPosX, _startPosY + 50);
|
||||||
|
Point point2 = new Point(_startPosX + _LainerWidth, _startPosY + 50);
|
||||||
|
Point point3 = new Point(_startPosX + 20, _startPosY + 80);
|
||||||
|
Point point4 = new Point(_startPosX + 80, _startPosY + 80);
|
||||||
|
Point[] points = { point1, point2, point4, point3 };
|
||||||
|
g.DrawPolygon(pen, points);
|
||||||
|
g.FillPolygon(brush, points);
|
||||||
|
//1 ïàëóáà
|
||||||
|
brush = new SolidBrush(EntityLainer.BodyColor);
|
||||||
|
Rectangle deck = new Rectangle(_startPosX + 5, _startPosY + 30, _LainerWidth - 10, 20);
|
||||||
|
g.FillRectangle(brush, deck);
|
||||||
|
//ñòåêëà
|
||||||
|
for (int i = 1; i < 5; i++)
|
||||||
|
{
|
||||||
|
g.FillEllipse(brBlue, _startPosX + i * 16, _startPosY + 33, 14, 14);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
private readonly int _LainerWidth = 150;
|
||||||
|
private readonly int _LainerHeight = 80;
|
||||||
|
public int GetWidth => _LainerWidth;
|
||||||
|
public int GetHeight => _LainerHeight;
|
||||||
|
public bool CanMove(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityLainer == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//âëåâî
|
||||||
|
DirectionType.Left => _startPosX - EntityLainer.Step > 0,
|
||||||
|
//ââåðõ
|
||||||
|
DirectionType.Up => _startPosY - EntityLainer.Step > 0,
|
||||||
|
// âïðàâî
|
||||||
|
DirectionType.Right => _startPosX + _LainerWidth + EntityLainer.Step < _pictureWidth,
|
||||||
|
//âíèç
|
||||||
|
DirectionType.Down => _startPosY + _LainerHeight + EntityLainer.Step < _pictureHeight,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction) || EntityLainer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//âëåâî
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (_startPosX - EntityLainer.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityLainer.Step;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosX = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//ââåðõ
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_startPosY - EntityLainer.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityLainer.Step;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosY = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// âïðàâî
|
||||||
|
case DirectionType.Right:
|
||||||
|
if (_startPosX + EntityLainer.Step <= _pictureWidth - _LainerWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityLainer.Step;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosX = _pictureWidth - _LainerWidth;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//âíèç
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (_startPosY + EntityLainer.Step < _pictureHeight - _LainerHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityLainer.Step;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosY = _pictureHeight - _LainerHeight;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
32
lainer/Lainer1/DrawingObjectLainer.cs
Normal file
32
lainer/Lainer1/DrawingObjectLainer.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using ProjectLainer.MovementStrategy;
|
||||||
|
using ProjectLainer.DrawningObjects;
|
||||||
|
using ProjectLainer.DrawningObjects;
|
||||||
|
namespace ProjectLainer.MovementStrategy
|
||||||
|
{
|
||||||
|
public class DrawningObjectLainer : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawingLainer? _drawningLainer = null;
|
||||||
|
public DrawningObjectLainer(DrawingLainer drawningLainer)
|
||||||
|
{
|
||||||
|
_drawningLainer = drawningLainer;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningLainer == null || _drawningLainer.EntityLainer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawningLainer.GetPosX,
|
||||||
|
_drawningLainer.GetPosY, _drawningLainer.GetWidth, _drawningLainer.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningLainer?.EntityLainer?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(DirectionType direction) =>
|
||||||
|
_drawningLainer?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(DirectionType direction) =>
|
||||||
|
_drawningLainer?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
52
lainer/Lainer1/DrawingSuperLainer.cs
Normal file
52
lainer/Lainer1/DrawingSuperLainer.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using ProjectLainer.Entities;
|
||||||
|
namespace ProjectLainer.DrawningObjects
|
||||||
|
{
|
||||||
|
public class DrawningSuperLainer : DrawingLainer
|
||||||
|
{
|
||||||
|
public DrawningSuperLainer(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool pools, bool decks, int width, int height) : base(speed, weight, bodyColor, width, height, 110, 60)
|
||||||
|
{
|
||||||
|
if (EntityLainer != null)
|
||||||
|
{
|
||||||
|
EntityLainer = new EntitySuperLainer(speed, weight, bodyColor,
|
||||||
|
additionalColor, pools, decks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityLainer is not EntitySuperLainer superlainer)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
base.DrawTransport(g);
|
||||||
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(superlainer.AdditionalColor);
|
||||||
|
if (superlainer.Decks)
|
||||||
|
{
|
||||||
|
Point point1 = new Point(_startPosX, _startPosY + 10);
|
||||||
|
Point point2 = new Point(_startPosX + GetWidth, _startPosY + 10);
|
||||||
|
Point point3 = new Point(_startPosX + 20, _startPosY + 30);
|
||||||
|
Point point4 = new Point(_startPosX + 80, _startPosY + 30);
|
||||||
|
Point[] points = { point1, point2, point4, point3 };
|
||||||
|
g.DrawPolygon(pen, points);
|
||||||
|
g.FillPolygon(additionalBrush, points);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Point point3 = new Point(_startPosX, _startPosY + 30);
|
||||||
|
Point point4 = new Point(_startPosX + GetWidth, _startPosY + 30);
|
||||||
|
Point point1 = new Point(_startPosX + 20, _startPosY + 10);
|
||||||
|
Point point2 = new Point(_startPosX + 80, _startPosY + 10);
|
||||||
|
Point[] points = { point1, point2, point4, point3 };
|
||||||
|
g.DrawPolygon(pen, points);
|
||||||
|
g.FillPolygon(additionalBrush, points);
|
||||||
|
}
|
||||||
|
for (int i = 2; i < 5; i++)
|
||||||
|
{
|
||||||
|
g.FillEllipse(brBlue, _startPosX + i * 16, _startPosY + 15, 12, 12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
144
lainer/Lainer1/DrawningLainer.cs
Normal file
144
lainer/Lainer1/DrawningLainer.cs
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
namespace ProjectLainer
|
||||||
|
{
|
||||||
|
public class DrawningLainer
|
||||||
|
{
|
||||||
|
public EntityLainer? EntityLainer { get; private set; }
|
||||||
|
private int _pictureWidth;
|
||||||
|
private int _pictureHeight;
|
||||||
|
private int _startPosX;
|
||||||
|
private int _startPosY;
|
||||||
|
private readonly int _LainerWidth = 150;
|
||||||
|
private readonly int _LainerHeight = 80;
|
||||||
|
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool ispool, bool addDecks, int width, int height)
|
||||||
|
{
|
||||||
|
if(width <= _LainerWidth || height <= _LainerHeight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
EntityLainer = new EntityLainer();
|
||||||
|
EntityLainer.Init(speed, weight, bodyColor, additionalColor, ispool, addDecks);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if(x + _LainerWidth < _pictureWidth && x + _LainerWidth > 0)
|
||||||
|
{
|
||||||
|
_startPosX = x;
|
||||||
|
}
|
||||||
|
if (y + _LainerHeight < _pictureHeight && y + _LainerHeight > 0)
|
||||||
|
{
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityLainer == null)
|
||||||
|
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//âëåâî
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (_startPosX - EntityLainer.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityLainer.Step;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosX = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//ââåðõ
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_startPosY - EntityLainer.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityLainer.Step;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosY = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// âïðàâî
|
||||||
|
case DirectionType.Right:
|
||||||
|
if (_startPosX + EntityLainer.Step <= _pictureWidth - _LainerWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityLainer.Step;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosX = _pictureWidth - _LainerWidth;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//âíèç
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (_startPosY + EntityLainer.Step <= _pictureHeight - _LainerHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityLainer.Step;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosY = _pictureHeight - _LainerHeight;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityLainer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new
|
||||||
|
SolidBrush(EntityLainer.AdditionalColor);
|
||||||
|
var brush = new SolidBrush(Color.Black);
|
||||||
|
// äîï ïàëóáû è îòðèñîâêà òðóá
|
||||||
|
Rectangle smokestack1 = new Rectangle(_startPosX + 20, _startPosY, 20, 50);
|
||||||
|
Rectangle smokestack2 = new Rectangle(_startPosX + 60, _startPosY, 20, 50);
|
||||||
|
g.FillRectangle(brush, smokestack1);
|
||||||
|
g.FillRectangle(brush, smokestack2);
|
||||||
|
if (EntityLainer.Decks)
|
||||||
|
{
|
||||||
|
Rectangle deck2 = new Rectangle(_startPosX + 10, _startPosY + 10, _LainerWidth - 18, 20);
|
||||||
|
g.FillRectangle(additionalBrush, deck2);
|
||||||
|
for (int i = 2; i < 6; i++)
|
||||||
|
{
|
||||||
|
g.FillEllipse(brBlue, _startPosX + i * 16, _startPosY + 15, 12, 12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//ãðàíèöû ëàéíåðà
|
||||||
|
pen = new(Color.Red);
|
||||||
|
brush = new SolidBrush(Color.Red);
|
||||||
|
Point point1 = new Point(_startPosX, _startPosY + 50);
|
||||||
|
Point point2 = new Point(_startPosX + _LainerWidth, _startPosY+50);
|
||||||
|
Point point3 = new Point(_startPosX + 20, _startPosY+80);
|
||||||
|
Point point4 = new Point(_startPosX + 80, _startPosY + 80);
|
||||||
|
Point[] points = { point1, point2, point4, point3};
|
||||||
|
g.DrawPolygon(pen, points);
|
||||||
|
g.FillPolygon(brush, points);
|
||||||
|
//1 ïàëóáà
|
||||||
|
brush = new SolidBrush(Color.Green);
|
||||||
|
Rectangle deck = new Rectangle(_startPosX + 5, _startPosY + 30, _LainerWidth - 10, 20);
|
||||||
|
g.FillRectangle(brush,deck);
|
||||||
|
//ñòåêëà
|
||||||
|
for (int i = 1; i < 7; i++)
|
||||||
|
{
|
||||||
|
g.FillEllipse(brBlue, _startPosX + i*16, _startPosY + 33, 14, 14);
|
||||||
|
}
|
||||||
|
// áàññåéí
|
||||||
|
if (EntityLainer.Pool)
|
||||||
|
{
|
||||||
|
g.FillEllipse(brBlue, _startPosX + _LainerWidth - 35, _startPosY + _LainerHeight - 55, 35, 12);
|
||||||
|
brush = new SolidBrush(Color.DarkGray);
|
||||||
|
Rectangle rect2 = new Rectangle(_startPosX + _LainerWidth - 35, _startPosY + _LainerHeight - 50, 35, 20);
|
||||||
|
g.FillRectangle(brush, rect2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
lainer/Lainer1/EntityLainer.cs
Normal file
16
lainer/Lainer1/EntityLainer.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
namespace ProjectLainer.Entities
|
||||||
|
{
|
||||||
|
public class EntityLainer
|
||||||
|
{
|
||||||
|
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 EntityLainer(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
lainer/Lainer1/EntitySuperLainer.cs
Normal file
16
lainer/Lainer1/EntitySuperLainer.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
namespace ProjectLainer.Entities
|
||||||
|
{
|
||||||
|
public class EntitySuperLainer : EntityLainer
|
||||||
|
{
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
public bool Pools { get; private set; }
|
||||||
|
public bool Decks { get; private set; }
|
||||||
|
public EntitySuperLainer(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool pools, bool decks) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
Pools = pools;
|
||||||
|
Decks = decks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
lainer/Lainer1/IMoveableObject.cs
Normal file
11
lainer/Lainer1/IMoveableObject.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//using ProjectLainer.Drawings;
|
||||||
|
namespace ProjectLainer.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
int GetStep { get; }
|
||||||
|
bool CheckCanMove(DirectionType direction);
|
||||||
|
void MoveObject(DirectionType direction);
|
||||||
|
}
|
||||||
|
}
|
26
lainer/Lainer1/Lainer1.csproj
Normal file
26
lainer/Lainer1/Lainer1.csproj
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<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>
|
175
lainer/Lainer1/LainerForm.Designer.cs
generated
Normal file
175
lainer/Lainer1/LainerForm.Designer.cs
generated
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
namespace ProjectLainer
|
||||||
|
{
|
||||||
|
partial class LainerForm : Form
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
pictureBoxLainer = new PictureBox();
|
||||||
|
ButtonCreate = new Button();
|
||||||
|
buttonRight = new Button();
|
||||||
|
buttonLeft = new Button();
|
||||||
|
buttonDown = new Button();
|
||||||
|
buttonUp = new Button();
|
||||||
|
ButtonCreateSuperLainer = new Button();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
ButtonStep = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxLainer).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxLainer
|
||||||
|
//
|
||||||
|
pictureBoxLainer.Dock = DockStyle.Fill;
|
||||||
|
pictureBoxLainer.Location = new Point(0, 0);
|
||||||
|
pictureBoxLainer.Name = "pictureBoxLainer";
|
||||||
|
pictureBoxLainer.Size = new Size(729, 397);
|
||||||
|
pictureBoxLainer.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
|
pictureBoxLainer.TabIndex = 0;
|
||||||
|
pictureBoxLainer.TabStop = false;
|
||||||
|
//
|
||||||
|
// ButtonCreate
|
||||||
|
//
|
||||||
|
ButtonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
ButtonCreate.Location = new Point(12, 356);
|
||||||
|
ButtonCreate.Name = "ButtonCreate";
|
||||||
|
ButtonCreate.Size = new Size(94, 29);
|
||||||
|
ButtonCreate.TabIndex = 1;
|
||||||
|
ButtonCreate.Text = "создать";
|
||||||
|
ButtonCreate.UseVisualStyleBackColor = true;
|
||||||
|
ButtonCreate.Click += ButtonCreate_Click;
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRight.BackgroundImage = Lainer1.Properties.Resources._3042406;
|
||||||
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonRight.Location = new Point(659, 315);
|
||||||
|
buttonRight.Name = "buttonRight";
|
||||||
|
buttonRight.Size = new Size(30, 30);
|
||||||
|
buttonRight.TabIndex = 2;
|
||||||
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonLeft.BackgroundImage = Lainer1.Properties.Resources._2;
|
||||||
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonLeft.Location = new Point(587, 315);
|
||||||
|
buttonLeft.Name = "buttonLeft";
|
||||||
|
buttonLeft.Size = new Size(30, 30);
|
||||||
|
buttonLeft.TabIndex = 3;
|
||||||
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonDown.BackgroundImage = Lainer1.Properties.Resources._1;
|
||||||
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonDown.Location = new Point(623, 344);
|
||||||
|
buttonDown.Name = "buttonDown";
|
||||||
|
buttonDown.Size = new Size(30, 30);
|
||||||
|
buttonDown.TabIndex = 4;
|
||||||
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonUp.BackgroundImage = Lainer1.Properties.Resources._3;
|
||||||
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonUp.Location = new Point(623, 287);
|
||||||
|
buttonUp.Name = "buttonUp";
|
||||||
|
buttonUp.Size = new Size(30, 30);
|
||||||
|
buttonUp.TabIndex = 5;
|
||||||
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// ButtonCreateSuperLainer
|
||||||
|
//
|
||||||
|
ButtonCreateSuperLainer.Location = new Point(137, 356);
|
||||||
|
ButtonCreateSuperLainer.Name = "ButtonCreateSuperLainer";
|
||||||
|
ButtonCreateSuperLainer.Size = new Size(192, 29);
|
||||||
|
ButtonCreateSuperLainer.TabIndex = 6;
|
||||||
|
ButtonCreateSuperLainer.Text = "создать супер лайнер";
|
||||||
|
ButtonCreateSuperLainer.UseVisualStyleBackColor = true;
|
||||||
|
ButtonCreateSuperLainer.Click += ButtonCreateSuperLainer_Click;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "центр", "край"});
|
||||||
|
comboBoxStrategy.Location = new Point(566, 12);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(151, 28);
|
||||||
|
comboBoxStrategy.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// ButtonStep
|
||||||
|
//
|
||||||
|
ButtonStep.Location = new Point(623, 66);
|
||||||
|
ButtonStep.Name = "ButtonStep";
|
||||||
|
ButtonStep.Size = new Size(94, 29);
|
||||||
|
ButtonStep.TabIndex = 8;
|
||||||
|
ButtonStep.Text = "шаг";
|
||||||
|
ButtonStep.UseVisualStyleBackColor = true;
|
||||||
|
ButtonStep.Click += ButtonStep_Click;
|
||||||
|
//
|
||||||
|
// LainerForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(729, 397);
|
||||||
|
Controls.Add(ButtonStep);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
|
Controls.Add(ButtonCreateSuperLainer);
|
||||||
|
Controls.Add(buttonUp);
|
||||||
|
Controls.Add(buttonDown);
|
||||||
|
Controls.Add(buttonLeft);
|
||||||
|
Controls.Add(buttonRight);
|
||||||
|
Controls.Add(ButtonCreate);
|
||||||
|
Controls.Add(pictureBoxLainer);
|
||||||
|
Name = "LainerForm";
|
||||||
|
Text = "LainerField";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxLainer).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxLainer;
|
||||||
|
private Button ButtonCreate;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button ButtonCreateSuperLainer;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button ButtonStep;
|
||||||
|
}
|
||||||
|
}
|
114
lainer/Lainer1/LainerForm.cs
Normal file
114
lainer/Lainer1/LainerForm.cs
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
using ProjectLainer.DrawningObjects;
|
||||||
|
using ProjectLainer.MovementStrategy;
|
||||||
|
namespace ProjectLainer
|
||||||
|
{
|
||||||
|
public partial class LainerForm : Form
|
||||||
|
{
|
||||||
|
private DrawingLainer? _drawningLainer;
|
||||||
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public LainerForm()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawningLainer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new(pictureBoxLainer.Width,
|
||||||
|
pictureBoxLainer.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawningLainer.DrawTransport(gr);
|
||||||
|
pictureBoxLainer.Image = bmp;
|
||||||
|
}
|
||||||
|
private void ButtonCreateSuperLainer_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
_drawningLainer = new DrawningSuperLainer(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)),
|
||||||
|
pictureBoxLainer.Width, pictureBoxLainer.Height);
|
||||||
|
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
|
100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
_drawningLainer = new DrawingLainer(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000),
|
||||||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||||
|
random.Next(0, 256)),
|
||||||
|
pictureBoxLainer.Width, pictureBoxLainer.Height);
|
||||||
|
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
|
100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningLainer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_drawningLainer.MoveTransport(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_drawningLainer.MoveTransport(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_drawningLainer.MoveTransport(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_drawningLainer.MoveTransport(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void ButtonStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningLainer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||||
|
switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(new
|
||||||
|
DrawningObjectLainer(_drawningLainer), pictureBoxLainer.Width,
|
||||||
|
pictureBoxLainer.Height);
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
lainer/Lainer1/LainerForm.resx
Normal file
120
lainer/Lainer1/LainerForm.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
58
lainer/Lainer1/MoveToBorder.cs
Normal file
58
lainer/Lainer1/MoveToBorder.cs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLainer.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder <= FieldWidth &&
|
||||||
|
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||||
|
objParams.DownBorder <= FieldHeight &&
|
||||||
|
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
|
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
lainer/Lainer1/MoveToCenter.cs
Normal file
50
lainer/Lainer1/MoveToCenter.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
namespace ProjectLainer.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
lainer/Lainer1/ObjectParameters.cs
Normal file
23
lainer/Lainer1/ObjectParameters.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
namespace ProjectLainer.MovementStrategy
|
||||||
|
{
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int _x;
|
||||||
|
private readonly int _y;
|
||||||
|
private readonly int _width;
|
||||||
|
private readonly int _height;
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
public int TopBorder => _y;
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
lainer/Lainer1/Program.cs
Normal file
17
lainer/Lainer1/Program.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace ProjectLainer
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
ApplicationConfiguration.Initialize();
|
||||||
|
Application.Run(new LainerForm());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
lainer/Lainer1/Status.cs
Normal file
9
lainer/Lainer1/Status.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace ProjectLainer.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user