Skip to content
Snippets Groups Projects
Commit 4617d2a7 authored by Carol-Ann Donaldson's avatar Carol-Ann Donaldson
Browse files

Fixed bugs in box completion and duplicate line drawing

parent 60f6a15f
No related branches found
No related tags found
1 merge request!2Fixed bugs in box completion and duplicate line drawing
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
......@@ -112,7 +112,9 @@ 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;
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn.
return getHorizontal(x, y) && getHorizontal(x, y + 1) &&
getVertical(x, y) && getVertical(x + 1, y);
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
......@@ -140,7 +142,9 @@ public class DotsAndBoxesGrid {
}
// FIXME: You need to throw an exception if the line was already drawn.
if (horizontals[x][y]) {
throw new IllegalStateException("Line already drawn");
}
this.horizontals[x][y] = true;
// Try to claim the north or south boxes
......@@ -171,6 +175,9 @@ public class DotsAndBoxesGrid {
}
// You need to throw an exception if the line was already drawn.
if (verticals[x][y]) {
throw new IllegalStateException("Line already 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.
Please register or to comment