Skip to content
Snippets Groups Projects
Commit 64fc5289 authored by Rohan Gene Isaac Vance's avatar Rohan Gene Isaac Vance
Browse files

Added main.java, uncommented bugfixes in Grid

parent b4cdcab4
No related branches found
No related tags found
No related merge requests found
......@@ -108,14 +108,24 @@ public class DotsAndBoxesGrid {
* @return true if all four sides have been drawn.
*/
public boolean boxComplete(int x, int y) {
if (x >= width - 1 || x < 0 || y >= height - 1 || y < 0) {
return false;
}
// 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;
// outside boundary of grid
if (x >= width - 1 || x < 0 || y >= height - 1 || y < 0) {
return false;
}
// if (getHorizontal(x, y) &&
// getHorizontal(x, y + 1) &&
// getVertical(x, y) &&
// getVertical(x + 1, y)) {
// return true;
// }
// return false;
}
/**
......@@ -150,6 +160,9 @@ public class DotsAndBoxesGrid {
}
// FIXME: You need to throw an exception if the line was already drawn.
// if (getHorizontal(x, y) == true) {
// throw new RuntimeException();
// }
this.horizontals[x][y] = true;
......@@ -183,8 +196,13 @@ public class DotsAndBoxesGrid {
throw new IndexOutOfBoundsException(
String.format("y was %d, which is out of range. Range is 0 to %d", y, height - 1));
}
if (getVertical(x, y) == true) {
throw new RuntimeException();
}
// You need to throw an exception if the line was already drawn.
// if (getVertical(x, y) == true) {
// throw new RuntimeException();
// }
this.verticals[x][y] = true;
// Try to claim the north or south boxes
......
......@@ -9,7 +9,6 @@ public class Main {
public static void main(String... args) throws Exception {
JFrame mainWindow = new JFrame("Dots and Boxes");
// 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
JLabel label = new JLabel("Name: (Rohan Vance 220188799)");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment