файлы лабораторной
This commit is contained in:
parent
1047be1e08
commit
cfa3253cf1
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;
|
||||
}
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,16 @@
|
||||
namespace ProjectLainer
|
||||
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 Color AdditionalColor { get; private set; }
|
||||
public bool Pool { get; private set; }
|
||||
public bool Decks { get; private set; }
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool ispool, bool addDecks)
|
||||
public EntityLainer(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Pool = ispool;
|
||||
Decks = addDecks;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user