This commit is contained in:
Yunusov_Niyaz 2023-11-04 01:46:55 +04:00
parent 66bb3f0907
commit e59a8e2cd2
10 changed files with 78 additions and 0 deletions

60
src/AbstractStrategy.java Normal file
View File

@ -0,0 +1,60 @@
public abstract class AbstractStrategy {
private IMoveableObject moveableObject;
private Status state = Status.NOT_INIT;
private int fieldWidth;
protected int getFieldWidth(){return fieldWidth;}
private int fieldHeight;
protected int getFieldHeight(){return fieldHeight;}
public Status getStatus() {return state;}
public void setData(IMoveableObject moveableObject, int width, int height){
if (moveableObject == null)
{
state = Status.NOT_INIT;
return;
}
state = Status.IN_PROGRESS;
this.moveableObject = moveableObject;
fieldWidth = width;
fieldHeight = height;
}
public void makeStep(){
if (state != Status.IN_PROGRESS) {
return;
}
if (isTargetDestination()) {
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.getObjectPosition();
else return null;
}
protected Integer getStep() {
if (state != Status.IN_PROGRESS)
{
return null;
}
return moveableObject.getStep();
}
protected abstract void moveToTarget();
protected abstract boolean isTargetDestination();
private boolean moveTo(DirectionType directionType) {
if (state != Status.IN_PROGRESS)
{
return false;
}
if (moveableObject.checkCanMove(directionType))
{
moveableObject.moveObject(directionType);
return true;
}
return false;
}
}

2
src/DrawingBus.java Normal file
View File

@ -0,0 +1,2 @@
package PACKAGE_NAME;public class DrawingBus {
}

View File

@ -0,0 +1,2 @@
package PACKAGE_NAME;public class DrawingDoorsRoundedUp {
}

View File

@ -0,0 +1,2 @@
package PACKAGE_NAME;public class DrawingDoorsRoundedUpAndDown {
}

View File

@ -0,0 +1,2 @@
package PACKAGE_NAME;public class DrawingObjectBus {
}

2
src/EntityBus.java Normal file
View File

@ -0,0 +1,2 @@
package PACKAGE_NAME;public class EntityBus {
}

2
src/IDrawDoors.java Normal file
View File

@ -0,0 +1,2 @@
package PACKAGE_NAME;public interface IDrawDoors {
}

2
src/IMoveableObject.java Normal file
View File

@ -0,0 +1,2 @@
package PACKAGE_NAME;public interface IMoveableObject {
}

2
src/MoveToBorder.java Normal file
View File

@ -0,0 +1,2 @@
package PACKAGE_NAME;public class MoveToBorder {
}

View File

@ -0,0 +1,2 @@
package PACKAGE_NAME;public class ObjectParameters {
}