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.
|
||||
* - A cell with 4 or more neighbours dies.
|
||||
*/
|
||||
Grid<Cell> gridTick(Grid<Cell> &grid) {
|
||||
void gridTick(Grid<Cell> &grid) {
|
||||
Grid<Cell> nextGrid = grid;
|
||||
|
||||
for (int row = 0; row < grid.numRows(); row++) {
|
||||
@ -155,7 +155,7 @@ Grid<Cell> gridTick(Grid<Cell> &grid) {
|
||||
}
|
||||
}
|
||||
|
||||
return nextGrid;
|
||||
grid = nextGrid;
|
||||
}
|
||||
|
||||
int main() {
|
||||
@ -234,12 +234,12 @@ int main() {
|
||||
// We don't have to handle QUIT, since we do in the while check
|
||||
switch (action) {
|
||||
case MenuAction::TICK:
|
||||
grid = gridTick(grid);
|
||||
gridTick(grid);
|
||||
gridPrint(grid);
|
||||
break;
|
||||
case MenuAction::ANIMATE:
|
||||
for (int i = 0; i < ANIMATION_N_GENERATIONS; i++) {
|
||||
grid = gridTick(grid);
|
||||
gridTick(grid);
|
||||
clearConsole();
|
||||
gridPrint(grid);
|
||||
pause(ANIMATION_SLEEP_MS);
|
||||
|
Loading…
x
Reference in New Issue
Block a user