-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/ui-console
- Loading branch information
Showing
18 changed files
with
577 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.simulation; | ||
|
||
/** | ||
* The four fundamental directions possible in the simulation. | ||
* <p> | ||
* {@link #NORTH} is at the top of the screen ({@link Position#getY()} getting smaller) | ||
* </p> | ||
* <p> | ||
* {@link #EAST} is at the right of the screen ({@link Position#getX()} getting bigger) | ||
* </p> | ||
* <p> | ||
* {@link #SOUTH} is at the bottom of the screen ({@link Position#getY()} getting bigger) | ||
* </p> | ||
* <p> | ||
* {@link #WEST} is at the left of the screen ({@link Position#getX()} getting smaller) | ||
* </p> | ||
* | ||
* @see Position | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public enum Direction { | ||
/** the north direction; at the top of the screen ({@link Position#getY()} getting smaller) */ | ||
NORTH, | ||
/** The east direction; at the right of the screen ({@link Position#getX()} getting bigger) */ | ||
EAST, | ||
/** The south direction; at the bottom of the screen ({@link Position#getY()} getting bigger) */ | ||
SOUTH, | ||
/** The west direction; at the left of the screen ({@link Position#getX()} getting smaller) */ | ||
WEST; | ||
|
||
/** | ||
* Get the direction that is next in a clock wise rotation | ||
* | ||
* @return The next direction | ||
*/ | ||
public Direction clockWiseNext() { | ||
return Direction.values()[(this.ordinal() + 1) % 4]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...n/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.simulation.entity; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import de.unistuttgart.informatik.fius.icge.simulation.Direction; | ||
import de.unistuttgart.informatik.fius.icge.simulation.Position; | ||
import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityNotOnFieldException; | ||
import de.unistuttgart.informatik.fius.icge.simulation.exception.IllegalMoveException; | ||
|
||
|
||
/** | ||
* A movable entity | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public abstract class MovableEntity extends BasicEntity { | ||
|
||
private Direction lookingDirection = Direction.EAST; | ||
|
||
/** | ||
* Turn this entity for 90 degrees in clock wise direction. | ||
*/ | ||
public void turnClockWise() { | ||
final CompletableFuture<Void> endOfOperation = new CompletableFuture<>(); | ||
this.getSimulation().getSimulationClock().scheduleOperationAtNextTick(endOfOperation); | ||
this.lookingDirection = this.lookingDirection.clockWiseNext(); | ||
endOfOperation.complete(null); | ||
} | ||
|
||
/** | ||
* @return the current looking direction of this entity | ||
*/ | ||
public Direction getLookingDirection() { | ||
return this.lookingDirection; | ||
} | ||
|
||
private boolean isSolidEntityAt(final Position pos) { | ||
return this.getPlayfield().isSolidEntityAt(pos); | ||
} | ||
|
||
/** | ||
* Move this entity forward one field. | ||
* | ||
* @throws EntityNotOnFieldException | ||
* if this entity is not on a playfield | ||
* @throws IllegalMoveException | ||
* if a solid entity is in the way | ||
*/ | ||
public void move() { | ||
final CompletableFuture<Void> endOfOperation = new CompletableFuture<>(); | ||
this.getSimulation().getSimulationClock().scheduleOperationInTicks(4, endOfOperation); | ||
final Position nextPos = this.getPosition().adjacentPosition(this.lookingDirection); | ||
if (this.isSolidEntityAt(nextPos)) throw new IllegalMoveException("Solid Entity in the way"); | ||
this.getPlayfield().moveEntity(this, nextPos); | ||
endOfOperation.complete(null); | ||
} | ||
|
||
/** | ||
* @return whether this entity can move forward one field. | ||
*/ | ||
public boolean canMove() { | ||
final Position nextPos = this.getPosition().adjacentPosition(this.lookingDirection); | ||
return this.isOnPlayfield() && !this.isSolidEntityAt(nextPos); | ||
} | ||
|
||
/** | ||
* Move this entity forward one field if that is possible. | ||
*/ | ||
public void moveIfPossible() { | ||
if (this.canMove()) { | ||
this.move(); | ||
} | ||
} | ||
} |
Oops, something went wrong.