From c7b13068a1d7ab841c240c8d8a50bbf563464c98 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Mon, 16 Oct 2023 09:54:49 +0400 Subject: [PATCH] Test commit --- .idea/misc.xml | 6 ++ .../MovementStrategy/AbstractStrategy.java | 64 +++++++++++++++++++ .../MovementStrategy/IMoveableObject.java | 10 +++ .../MovementStrategy/ObjectParameters.java | 29 +++++++++ src/MonorailHard/MovementStrategy/Status.java | 7 ++ 5 files changed, 116 insertions(+) create mode 100644 .idea/misc.xml create mode 100644 src/MonorailHard/MovementStrategy/AbstractStrategy.java create mode 100644 src/MonorailHard/MovementStrategy/IMoveableObject.java create mode 100644 src/MonorailHard/MovementStrategy/ObjectParameters.java create mode 100644 src/MonorailHard/MovementStrategy/Status.java diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..cc6eae0 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/MonorailHard/MovementStrategy/AbstractStrategy.java b/src/MonorailHard/MovementStrategy/AbstractStrategy.java new file mode 100644 index 0000000..571522b --- /dev/null +++ b/src/MonorailHard/MovementStrategy/AbstractStrategy.java @@ -0,0 +1,64 @@ +package MonorailHard.MovementStrategy; + +import MonorailHard.DirectionType; + +public abstract class AbstractStrategy { + private IMoveableObject _moveableObject; + private Status _state = Status.NotInit; + private int FieldWidth; + protected int FieldWidth(){return FieldWidth;} + private int FieldHeight; + protected int FieldHeight(){return FieldWidth;} + 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 boolean MoveLeft() {return MoveTo(DirectionType.Left);} + protected boolean MoveRight() {return MoveTo(DirectionType.Right);} + protected boolean MoveUp() {return MoveTo(DirectionType.Up);} + protected boolean MoveDown() {return MoveTo(DirectionType.Down);} + protected ObjectParameters GetObjectParameters(){ + if(_moveableObject != null) + return _moveableObject.GetObjectParameters(); + else return null; + } + + protected Integer GetStep() + { + if (_state != Status.InProgress) + { + return null; + } + return _moveableObject.GetStep(); + } + + protected abstract void MoveToTarget(); + + protected abstract boolean IsTargetDestinaion(); + + private + +} diff --git a/src/MonorailHard/MovementStrategy/IMoveableObject.java b/src/MonorailHard/MovementStrategy/IMoveableObject.java new file mode 100644 index 0000000..16f86eb --- /dev/null +++ b/src/MonorailHard/MovementStrategy/IMoveableObject.java @@ -0,0 +1,10 @@ +package MonorailHard.MovementStrategy; + +import MonorailHard.DirectionType; + +public interface IMoveableObject { + public ObjectParameters GetObjectParameters(); + public int GetStep(); + boolean CheckCanMove(DirectionType direction); + void MoveObject(DirectionType direction); +} diff --git a/src/MonorailHard/MovementStrategy/ObjectParameters.java b/src/MonorailHard/MovementStrategy/ObjectParameters.java new file mode 100644 index 0000000..4a00c36 --- /dev/null +++ b/src/MonorailHard/MovementStrategy/ObjectParameters.java @@ -0,0 +1,29 @@ +package MonorailHard.MovementStrategy; + +public class ObjectParameters { + private final int _x; + private final int _y; + private final int _width; + private final int _height; + public int LeftBorder; + public int TopBorder; + public int RightBorder; + public int DownBorder; + public int ObjectMiddleHorizontal; + public int ObjectMiddleVertical; + + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + LeftBorder = _x; + TopBorder = _y; + RightBorder = _x + width; + DownBorder = _y + height; + ObjectMiddleHorizontal = _x + _width / 2; + ObjectMiddleVertical = _y + _height / 2; + } + +} diff --git a/src/MonorailHard/MovementStrategy/Status.java b/src/MonorailHard/MovementStrategy/Status.java new file mode 100644 index 0000000..c07cf56 --- /dev/null +++ b/src/MonorailHard/MovementStrategy/Status.java @@ -0,0 +1,7 @@ +package MonorailHard.MovementStrategy; + +public enum Status { + NotInit, + InProgress, + Finish +}