Skip to content

Instantly share code, notes, and snippets.

@michaldo
Created November 11, 2016 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaldo/765ca68f7ffd31324fc0f561fc27091c to your computer and use it in GitHub Desktop.
Save michaldo/765ca68f7ffd31324fc0f561fc27091c to your computer and use it in GitHub Desktop.
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