Created
November 11, 2016 15:05
-
-
Save michaldo/765ca68f7ffd31324fc0f561fc27091c to your computer and use it in GitHub Desktop.
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
import java.util.ArrayList; | |
import java.util.List; | |
public class OldCheckpoints { | |
private boolean completed = false; | |
private List<Point> chechpoints = new ArrayList<>(); | |
private Point first; | |
private Point current; | |
public boolean isCompleted() { | |
return completed; | |
} | |
public void setCurrent(Point p) { | |
if (p.equals(current)) { | |
return; | |
} | |
current = p; | |
if (completed) { | |
return; | |
} | |
if (current.equals(first)) { | |
completed = true; | |
return; | |
} | |
if (first == null) { | |
first = current; | |
} | |
chechpoints.add(p); | |
} | |
public Point nextCheckpoint() { | |
return nextCheckpoint(current); | |
} | |
public Point nextCheckpoint(Point currentCheckpoint) { | |
if (!completed) { | |
throw new IllegalStateException("Dude, not completed yet. Call isCompleted() next time"); | |
} | |
int idx = chechpoints.indexOf(currentCheckpoint); | |
if (idx == -1) { | |
throw new IllegalStateException("Dude, uknown " + currentCheckpoint); | |
} | |
int nextIdx = (idx + 1) % chechpoints.size(); | |
return chechpoints.get(nextIdx); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment