Skip to content
Snippets Groups Projects

Draft: Resolve "Errors"

Open Cameron requested to merge 1-fix-assignment-errors into main
5 files
+ 174
182
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -3,6 +3,7 @@ package dotsandboxes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Observer;
import java.util.function.Consumer;
/**
@@ -113,6 +114,11 @@ public class DotsAndBoxesGrid {
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn.
// FIXME: You'll need to fix this code (after writing a test first).
return true;
if (this.horizontals[x][y] && this.horizontals[x + 1][y] && this.verticals[x][y] && this.verticals[x][y + 1])
{
return true;
}
else return false;
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
@@ -139,7 +145,9 @@ public class DotsAndBoxesGrid {
throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height));
}
// FIXME: You need to throw an exception if the line was already drawn.
if (this.horizontals[x][y]) {
throw new IllegalStateException("Line already drawn");
}
this.horizontals[x][y] = true;
@@ -170,7 +178,9 @@ public class DotsAndBoxesGrid {
throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height - 1));
}
// You need to throw an exception if the line was already drawn.
if (this.verticals[x][y]) {
throw new IllegalStateException("Line already drawn");
}
this.verticals[x][y] = true;
// Try to claim the north or south boxes
Loading