Skip to content
Snippets Groups Projects
Commit 93380104 authored by Krishkumar Sandipkumar Patel's avatar Krishkumar Sandipkumar Patel
Browse files

Merge branch 'issue'

This merge merges issue branch into main branch. For my project, the issue
branch contains the bugfixes in the DotsAndBoxesGrid.java class and the main
branch contains testing code.
parents bc6c17ab f929b351
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment