Skip to content
Snippets Groups Projects

bugfix Fixed Fail Test Line Drawn Twice and Test Box Complete Now Passes, A...

2 files
+ 101
5
Compare changes
  • Side-by-side
  • Inline

Files

@@ -109,11 +109,15 @@ public class DotsAndBoxesGrid {
public boolean boxComplete(int x, int y) {
if (x >= width - 1 || x < 0 || y >= height - 1 || y < 0) {
return false;
}else {
// 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).
if (getHorizontal(x, y) && getVertical(x, y) && getVertical(x + 1, y) && getHorizontal(x, y + 1)) {
return true;
} else {
return false;
}
}
// 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;
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
@@ -139,8 +143,10 @@ public class DotsAndBoxesGrid {
if (y >= height || y < 0) {
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 (getHorizontal(x,y)){
throw new IllegalArgumentException("Horizontal Line in this location already drawn.");
}
this.horizontals[x][y] = true;
@@ -172,6 +178,9 @@ public class DotsAndBoxesGrid {
}
// You need to throw an exception if the line was already drawn.
if (getVertical(x,y)){
throw new IllegalArgumentException("Horizontal Line in this location already drawn.");
}
this.verticals[x][y] = true;
// Try to claim the north or south boxes
Loading