From 998856f1b93d4bfb561b3424645e33bf86678161 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Thu, 14 Apr 2016 16:12:01 +0200 Subject: Refactor stop path --- src/ch/epfl/xblast/server/GameState.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/ch/epfl') diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index e133159..61e64f3 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java @@ -232,8 +232,7 @@ public final class GameState { return p0; if (!newDir.isPresent()) - // TODO: make this clearer - return GameState.pathToNextCentralPosition(p0).concat(Player.DirectedPosition.stopped(new Player.DirectedPosition(GameState.nextCentralPosition(p0), p0.head().direction()))); + return GameState.stopPath(p0); if (p0.head().direction().isPerpendicularTo(newDir.get())) return GameState.pivotPath(Player.DirectedPosition.moving(p0.head()), newDir.get()); @@ -241,6 +240,21 @@ public final class GameState { return Player.DirectedPosition.moving(new Player.DirectedPosition(p0.head().position(), newDir.get())); } + /** + * Builds and returns a path stopping at the next central SubCell. + * + * @param p0 the current path + * @return the stop path + */ + private static Sq stopPath(Sq p0) { + SubCell nextCentral = GameState.nextCentralPosition(p0); + Direction currentDir = p0.head().direction(); + + return GameState + .pathToNextCentralPosition(p0) + .concat(Player.DirectedPosition.stopped(new Player.DirectedPosition(nextCentral, currentDir))); + } + /** * Builds and returns a pivot path reaching the next pivot SubCell and then rotating to the given Direction. * -- cgit v1.2.3