Lab2
This commit is contained in:
parent
66bb3f0907
commit
e59a8e2cd2
60
src/AbstractStrategy.java
Normal file
60
src/AbstractStrategy.java
Normal 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
2
src/DrawingBus.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public class DrawingBus {
|
||||
}
|
2
src/DrawingDoorsRoundedUp.java
Normal file
2
src/DrawingDoorsRoundedUp.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public class DrawingDoorsRoundedUp {
|
||||
}
|
2
src/DrawingDoorsRoundedUpAndDown.java
Normal file
2
src/DrawingDoorsRoundedUpAndDown.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public class DrawingDoorsRoundedUpAndDown {
|
||||
}
|
2
src/DrawingObjectBus.java
Normal file
2
src/DrawingObjectBus.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public class DrawingObjectBus {
|
||||
}
|
2
src/EntityBus.java
Normal file
2
src/EntityBus.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public class EntityBus {
|
||||
}
|
2
src/IDrawDoors.java
Normal file
2
src/IDrawDoors.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public interface IDrawDoors {
|
||||
}
|
2
src/IMoveableObject.java
Normal file
2
src/IMoveableObject.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public interface IMoveableObject {
|
||||
}
|
2
src/MoveToBorder.java
Normal file
2
src/MoveToBorder.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public class MoveToBorder {
|
||||
}
|
2
src/ObjectParameters.java
Normal file
2
src/ObjectParameters.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public class ObjectParameters {
|
||||
}
|
Loading…
Reference in New Issue
Block a user