Skip to content
Snippets Groups Projects
Commit 90380fdb authored by Curtis James Moore's avatar Curtis James Moore
Browse files

Fixed assignment errors: boxComplete correctly checks if a box is complete,...

Fixed assignment errors: boxComplete correctly checks if a box is complete, drawHorizontal correctly throws an exception if the line was already drawn and drawVertical correctly throws an exception if the line was already drawn
parent a63fb852
No related tags found
No related merge requests found
......@@ -5,6 +5,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.function.Consumer;
import javax.management.RuntimeErrorException;
/**
* The state of a dots and boxes grid.
*
......@@ -111,7 +113,10 @@ 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).
if (!getHorizontal(x,y) || !getVertical(x, y) ||
!getHorizontal(x, y + 1) || !getVertical(x + 1, y)) {
return false;
}
return true;
}
......@@ -139,7 +144,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 (getHorizontal(x, y)) {
throw new RuntimeException(String.format("This horizontal line has already been drawn"));
}
this.horizontals[x][y] = true;
......@@ -170,7 +177,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 (getVertical(x, y)) {
throw new RuntimeException(String.format("This vertical line has already been drawn"));
}
this.verticals[x][y] = true;
// Try to claim the north or south boxes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment