Skip to content
Snippets Groups Projects
Commit 9418530d authored by Will Billingsley's avatar Will Billingsley
Browse files

fixed bugs detected by test cases

parent 69cd737b
No related branches found
No related tags found
No related merge requests found
...@@ -109,10 +109,9 @@ public class DotsAndBoxesGrid { ...@@ -109,10 +109,9 @@ public class DotsAndBoxesGrid {
if (x >= width - 1 || x < 0 || y >= height - 1 || y < 0) { if (x >= width - 1 || x < 0 || y >= height - 1 || y < 0) {
return false; return false;
} }
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn. // 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). // FIXME: You'll need to fix this code (after writing a test first).
return true; return horizontals[x][y] && horizontals[x][y + 1] && verticals[x][y] && verticals[x + 1][y];
} }
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */ /** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
...@@ -138,6 +137,9 @@ public class DotsAndBoxesGrid { ...@@ -138,6 +137,9 @@ public class DotsAndBoxesGrid {
if (y >= height || y < 0) { if (y >= height || y < 0) {
throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height)); throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height));
} }
if (horizontals[x][y]) {
throw new IllegalStateException("Line has already been drawn");
}
// 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.
...@@ -169,6 +171,9 @@ public class DotsAndBoxesGrid { ...@@ -169,6 +171,9 @@ public class DotsAndBoxesGrid {
if (y >= height - 1 || y < 0) { if (y >= height - 1 || y < 0) {
throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height - 1)); throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height - 1));
} }
if (verticals[x][y]) {
throw new IllegalStateException("Line has already been drawn");
}
// You need to throw an exception if the line was already drawn. // You need to throw an exception if the line was already drawn.
......
...@@ -12,7 +12,7 @@ public class Main { ...@@ -12,7 +12,7 @@ public class Main {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2); DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2);
// FIXME: Update this label to show your name and student number // FIXME: Update this label to show your name and student number
JLabel label = new JLabel("Name: (Your name and student number goes here)"); JLabel label = new JLabel("Name: NabaZaheerKhan");
JPanel borderPane = new JPanel(new BorderLayout()); JPanel borderPane = new JPanel(new BorderLayout());
borderPane.add(label, BorderLayout.SOUTH); borderPane.add(label, BorderLayout.SOUTH);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment