Skip to content

Commit

Permalink
Implement Aging
Browse files Browse the repository at this point in the history
  • Loading branch information
ClayDowling committed Apr 15, 2017
1 parent 4d189dc commit a4b4b47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ By passing the LifeBoard to the constructor of the engine, I'm also removing th

## Hide The Board's Implementation

I can now hide the implementation of the board and all tests still pass. This opens the way to change the actual implementation.
I can now hide the implementation of the board and all tests still pass. This opens the way to change the actual implementation.

## Implement Aging

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.
10 changes: 5 additions & 5 deletions src/main/java/LifeBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
public class LifeBoard implements Board {
public static final int X_MAX = 50;
public static final int Y_MAX = 50;
private boolean[][] value = new boolean[X_MAX][Y_MAX];
private int[][] value = new int[X_MAX][Y_MAX];

public void clear() {
for(int x=0; x < X_MAX; ++x) {
for(int y=0; y < Y_MAX; ++y) {
value[x][y] = false;
value[x][y] = 0;
}
}
}

public int at(int x, int y) {
if (value[x][y]) {
if (value[x][y] > 0) {
return 1;
}
return 0;
}

public void set(int x, int y, int value) {
if (0 == value) {
this.value[x][y] = false;
this.value[x][y] = 0;
} else {
this.value[x][y] = true;
this.value[x][y] = this.value[x][y] + 1;
}
}
}

0 comments on commit a4b4b47

Please sign in to comment.