Skip to content
Snippets Groups Projects
Commit 2e3bc876 authored by Arabella Adelaide Wain's avatar Arabella Adelaide Wain
Browse files

Bugs fixed and tests now working properly

parent 4809b511
No related branches found
No related tags found
No related merge requests found
......@@ -109,10 +109,11 @@ public class DotsAndBoxesGrid {
if (x >= width - 1 || x < 0 || y >= height - 1 || y < 0) {
return false;
}
return getHorizontal(x, y) && getHorizontal(x, y + 1) && getVertical(x, y) && getVertical(x + 1, y);
// 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;
//CODE IS FIXED
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
......@@ -140,7 +141,11 @@ public class DotsAndBoxesGrid {
}
// FIXME: You need to throw an exception if the line was already drawn.
// Fixed
if (this.horizontals[x][y]) {
throw new IllegalStateException("This line has already been drawn.");
}
this.horizontals[x][y] = true;
// Try to claim the north or south boxes
......@@ -172,6 +177,11 @@ public class DotsAndBoxesGrid {
// You need to throw an exception if the line was already drawn.
if (this.verticals[x][y]) {
throw new IllegalStateException("This line has already been drawn.");
}
this.verticals[x][y] = true;
this.verticals[x][y] = true;
// Try to claim the north or south boxes
boolean claimE = claimBox(x, y, player);
......
......@@ -12,7 +12,9 @@ public class Main {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2);
// FIXME: Update this label to show your name and student number
JLabel label = new JLabel("Name: (Your name and student number goes here)");
//Fixed
JLabel label = new JLabel("Name: Arabella Wain 220231921");
JPanel borderPane = new JPanel(new BorderLayout());
borderPane.add(label, BorderLayout.SOUTH);
......
......@@ -31,6 +31,9 @@ public class DotsAndBoxesGridTest {
@Test
public void boxCompleteDetectsCompletedBoxes() {
grid = new DotsAndBoxesGrid(4, 3, 2);
grid.drawHorizontal(0, 0, 1);
grid.drawHorizontal(0, 1, 1);
grid.drawVertical(0, 0, 1);
......@@ -48,6 +51,8 @@ public class DotsAndBoxesGridTest {
@Test
public void boxCompleteDetectIncompleteBoxes() {
grid = new DotsAndBoxesGrid(4, 3, 2);
grid.drawHorizontal(0, 1, 1);
assertFalse(grid.boxComplete(1, 1));
......@@ -55,6 +60,8 @@ public class DotsAndBoxesGridTest {
@Test
public void drawMethodsDetectRedrawnLines() {
grid = new DotsAndBoxesGrid(4, 3, 2);
grid.drawHorizontal(0, 0, 1);
assertThrows(IllegalStateException.class, () -> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment