Skip to content
Snippets Groups Projects
Commit f3435d8f authored by kkarki4's avatar kkarki4
Browse files

fix bugs for drawing lines and checking box completion

parent 59a71bc5
No related branches found
No related tags found
No related merge requests found
...@@ -115,7 +115,11 @@ public class DotsAndBoxesGrid { ...@@ -115,7 +115,11 @@ public class DotsAndBoxesGrid {
// A box is complete if the north and south horizontals and the east and west // A box is complete if the north and south horizontals and the east and west
// verticals have all been drawn. // verticals have all been drawn.
// FIXME: You'll need to fix this code (after writing a test first). // FIXME: You'll need to fix this code (after writing a test first).
return true; // Check if all four sides are drawn
return horizontals[x][y] && // North
horizontals[x][y + 1] && // South
verticals[x][y] && // West
verticals[x + 1][y]; // East
} }
/** /**
...@@ -150,6 +154,10 @@ public class DotsAndBoxesGrid { ...@@ -150,6 +154,10 @@ public class DotsAndBoxesGrid {
} }
// FIXME: You need to throw an exception if the line was already drawn. // FIXME: You need to throw an exception if the line was already drawn.
// Check if the line was already drawn
if (this.horizontals[x][y]) {
throw new IllegalStateException("Line already drawn");
}
this.horizontals[x][y] = true; this.horizontals[x][y] = true;
...@@ -185,6 +193,10 @@ public class DotsAndBoxesGrid { ...@@ -185,6 +193,10 @@ public class DotsAndBoxesGrid {
} }
// You need to throw an exception if the line was already drawn. // You need to throw an exception if the line was already drawn.
// Check if the line was already drawn
if (this.verticals[x][y]) {
throw new IllegalStateException("Line already drawn");
}
this.verticals[x][y] = true; this.verticals[x][y] = true;
// Try to claim the north or south boxes // 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