Commit ef119def authored by Anya Helene Bagge's avatar Anya Helene Bagge 🦆
Browse files

fix grid

parent 77e966c8
......@@ -16,6 +16,8 @@ public class GridTest {
IGrid grid = new MyGrid(11, 17, CellState.DEAD);
// TODO: sjekk at bredde og høyde faktisk er 11 og 17
assertEquals(11, grid.getWidth());
assertEquals(17, grid.getHeight());
}
/**
* Tests that trying to access outside of the dimensions of the grid throws
......
......@@ -36,13 +36,13 @@ public class MyGrid implements IGrid {
@Override
public int getHeight() {
return 0; // TODO: fyll inn
return height; // TODO: fyll inn
}
@Override
public int getWidth() {
return 0; // TODO: fyll inn
return width; // TODO: fyll inn
}
......@@ -54,8 +54,12 @@ public class MyGrid implements IGrid {
throw new IndexOutOfBoundsException();
// TODO: fyll inn
cells.set(xyToI(x, y), elem);
}
private int xyToI(int x, int y) {
return x + y*width;
}
@Override
public CellState get(int x, int y) {
......@@ -64,7 +68,7 @@ public class MyGrid implements IGrid {
if(y < 0 || y >= height)
throw new IndexOutOfBoundsException();
return null; // TODO: fyll inn
return cells.get(xyToI(x, y)); // TODO: fyll inn
}
@Override
......
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