Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • kpatel9/assignment_2
1 result
Select Git revision
Loading items
Show changes
Commits on Source (3)
......@@ -117,8 +117,11 @@ 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) && 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. */
private boolean claimBox(int x, int y, int p) {
......@@ -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
......