Commit 993ab9e1 authored by nreeves5's avatar nreeves5
Browse files

Committing bug fixed code to main branch

parent 3068f5da
......@@ -112,8 +112,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).
return true;
if (this.horizontals[x][y] == true && this.horizontals[x][y+1] == true && this.verticals[x][y] == true && this.verticals[x+1][y] == true) {
return true;
}
return false;
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
......@@ -141,6 +144,10 @@ public class DotsAndBoxesGrid {
}
// FIXME: You need to throw an exception if the line was already drawn.
if (this.horizontals[x][y] == true) {
throw new IllegalStateException(String.format("IllegalStateException - This line has already been drawn"));
}
this.horizontals[x][y] = true;
......@@ -172,6 +179,9 @@ public class DotsAndBoxesGrid {
}
// You need to throw an exception if the line was already drawn.
if (this.verticals[x][y]) {
throw new IllegalStateException(String.format("This line has already been drawn"));
}
this.verticals[x][y] = true;
// Try to claim the north or south boxes
......
......@@ -32,13 +32,13 @@ public class DotsAndBoxesGridTest {
@Test
public void testTestingBoxComplete() {
logger.info("Test of box completion test");
logger.info("Drawing complete box, then asserting incomplete state");
logger.info("Drawing complete box, then asserting complete state");
DotsAndBoxesGrid g = new DotsAndBoxesGrid(4,4,1);
g.drawHorizontal(1,1, 1);
g.drawHorizontal(1,2,1);
g.drawVertical(1,1,1);
g.drawVertical(2,1,1);
assertEquals(false,g.boxComplete(1,1));
assertEquals(true,g.boxComplete(1,1));
}
@Test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment