diff --git a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java index 922fae93debe6adc3698afe208245f21df672363..55de35e920e6c4cce970905b9603c73d8bb03acc 100644 --- a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java +++ b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java @@ -117,7 +117,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). - return true; + if ((getHorizontal(x, y) && getHorizontal(x, y + 1)) && (getVertical(x, y) && getVertical(x + 1, y))) { + return true; + } + return false; } /** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */ @@ -147,6 +150,9 @@ public class DotsAndBoxesGrid { } // FIXME: You need to throw an exception if the line was already drawn. + if (getHorizontal(x, y)) { + throw new IllegalArgumentException(String.format("line at coordinate (%d, %d) already exists. Try other coordinates", x, y)); + } this.horizontals[x][y] = true; // otherwise set the horizontal line to true @@ -179,6 +185,9 @@ public class DotsAndBoxesGrid { // FIX this too, whether vertical line was already drawn or not // You need to throw an exception if the line was already drawn. + if (getVertical(x, y)) { + throw new IllegalArgumentException(String.format("line at coordinate (%d, %d) already exists. Try other coordinates", x, y)); + } this.verticals[x][y] = true; // otherwise set the vertical line to true