I need to creat a graphical output for the Game of Life, which replaces my Syste
ID: 3911440 • Letter: I
Question
I need to creat a graphical output for the Game of Life, which replaces my System.out.println toString from my previous assignment. I posted below my previous code of the class as well as a screenshot of what the end assignment should look like and some guidance on writing the code.
public class MyGameOfLife implements GameOfLife {
private int [][] size;
public MyGameOfLife() {
size = new int[19][19];
}
public int getCellState(int row, int col) {
return size[row - 1][col - 1];
}
public void setCellState(int row, int col, int state) {
size[row - 1][col - 1] = state;
}
public void nextGeneration() {
}
public String toString() {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < size.length; i++) {
for(int j = 0; j < size[i].length; j++) {
sb.append(String.format("%c ",size[i][j] == ALIVE ? 'O' : '.'));
}
sb.append(" ");
}
return sb.toString();
}
}
Explanation / Answer
i am giving you the code for main logic of Game.. you, should post another question for UI side implementation as that will be a very big question to answer here. Thanks!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.