Use grid as outparameter aswell
This commit is contained in:
parent
dd28d1291c
commit
ecccca869d
@ -137,7 +137,7 @@ int gridAliveNeighbors(Grid<Cell> &grid, int row, int col) {
|
|||||||
* - Locations with 3 neighbours will create life.
|
* - Locations with 3 neighbours will create life.
|
||||||
* - A cell with 4 or more neighbours dies.
|
* - A cell with 4 or more neighbours dies.
|
||||||
*/
|
*/
|
||||||
Grid<Cell> gridTick(Grid<Cell> &grid) {
|
void gridTick(Grid<Cell> &grid) {
|
||||||
Grid<Cell> nextGrid = grid;
|
Grid<Cell> nextGrid = grid;
|
||||||
|
|
||||||
for (int row = 0; row < grid.numRows(); row++) {
|
for (int row = 0; row < grid.numRows(); row++) {
|
||||||
@ -155,7 +155,7 @@ Grid<Cell> gridTick(Grid<Cell> &grid) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nextGrid;
|
grid = nextGrid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -234,12 +234,12 @@ int main() {
|
|||||||
// We don't have to handle QUIT, since we do in the while check
|
// We don't have to handle QUIT, since we do in the while check
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MenuAction::TICK:
|
case MenuAction::TICK:
|
||||||
grid = gridTick(grid);
|
gridTick(grid);
|
||||||
gridPrint(grid);
|
gridPrint(grid);
|
||||||
break;
|
break;
|
||||||
case MenuAction::ANIMATE:
|
case MenuAction::ANIMATE:
|
||||||
for (int i = 0; i < ANIMATION_N_GENERATIONS; i++) {
|
for (int i = 0; i < ANIMATION_N_GENERATIONS; i++) {
|
||||||
grid = gridTick(grid);
|
gridTick(grid);
|
||||||
clearConsole();
|
clearConsole();
|
||||||
gridPrint(grid);
|
gridPrint(grid);
|
||||||
pause(ANIMATION_SLEEP_MS);
|
pause(ANIMATION_SLEEP_MS);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user