Skip to content

Commit a4b4b47

Browse files
committed
Implement Aging
1 parent 4d189dc commit a4b4b47

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ By passing the LifeBoard to the constructor of the engine, I'm also removing th
3030

3131
## Hide The Board's Implementation
3232

33-
I can now hide the implementation of the board and all tests still pass. This opens the way to change the actual implementation.
33+
I can now hide the implementation of the board and all tests still pass. This opens the way to change the actual implementation.
34+
35+
## Implement Aging
36+
37+
Now my new LifeBoard implementation implements an aging feature. Every time a cell is made "alive" it gets one generation older. This can be used to change the display to show different colors or intensities.

src/main/java/LifeBoard.java

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

99
public void clear() {
1010
for(int x=0; x < X_MAX; ++x) {
1111
for(int y=0; y < Y_MAX; ++y) {
12-
value[x][y] = false;
12+
value[x][y] = 0;
1313
}
1414
}
1515
}
1616

1717
public int at(int x, int y) {
18-
if (value[x][y]) {
18+
if (value[x][y] > 0) {
1919
return 1;
2020
}
2121
return 0;
2222
}
2323

2424
public void set(int x, int y, int value) {
2525
if (0 == value) {
26-
this.value[x][y] = false;
26+
this.value[x][y] = 0;
2727
} else {
28-
this.value[x][y] = true;
28+
this.value[x][y] = this.value[x][y] + 1;
2929
}
3030
}
3131
}

0 commit comments

Comments
 (0)