Skip to content

Commit 535b901

Browse files
committed
Engine Converted
1 parent 1943147 commit 535b901

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ I have partially transitions to using the new interface, in the tests for LifeBo
2121
## Engine Tests Converted
2222

2323
The engine tests have been converted. Notice that they still take advantage of the fact that the board implementation is static. This is because the engine itself hasn't been converted.
24+
25+
## Engine Converted
26+
27+
Engine is the last class which was using the internal representation of the LifeBoard. Now it's converted to use only the defined interfaces.
28+
29+
By passing the LifeBoard to the constructor of the engine, I'm also removing the dependency on the static implementation of the board's storage. I verified that by removing the static storage class in LifeBoard.

src/main/java/Engine.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
*/
44
public class Engine {
55

6+
private LifeBoard board;
7+
8+
public Engine(LifeBoard board) {
9+
this.board = board;
10+
}
11+
612
int neighbors(int x, int y) {
713
int count = 0;
814

915
for(int i=-1; i < 2; ++i) {
1016
for(int j=-1; j < 2; ++j) {
1117
if (!(0 == i && 0 == j))
12-
if (LifeBoard.value[x + i][y + j]) {
18+
if (board.at(x + i, y + j) != 0) {
1319
++count;
1420
}
1521
}

src/main/java/LifeBoard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
public class LifeBoard implements Board {
55
public static final int X_MAX = 50;
66
public static final int Y_MAX = 50;
7-
static public boolean[][] value = new boolean[X_MAX][Y_MAX];
7+
public boolean[][] value = new boolean[X_MAX][Y_MAX];
88

99

1010
public void clear() {

src/test/java/EngineTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class EngineTest {
1717

1818
@Before
1919
public void setUp() {
20-
engine = new Engine();
2120
board = new LifeBoard();
21+
engine = new Engine(board);
2222

2323
board.clear();
2424
}

0 commit comments

Comments
 (0)