Просмотр исходного кода

Stop if there are no remaining living cells

master
Dylan Baker 3 лет назад
Родитель
Сommit
3848384363
1 измененных файлов: 5 добавлений и 0 удалений
  1. 5
    0
      src/Board.tsx

+ 5
- 0
src/Board.tsx Просмотреть файл

@@ -45,6 +45,11 @@ class Board extends React.Component<{}, State> {
45 45
     this.timer = setInterval(() => {
46 46
       const grid = generateNewGrid(this.state.grid);
47 47
       this.setState({ grid, generations: this.state.generations + 1 });
48
+
49
+      if (!grid.map((row) => row.includes(true)).includes(true)) {
50
+        this.stop();
51
+        alert(`No more living cells, stopping`);
52
+      }
48 53
     }, this.state.speed);
49 54
   };
50 55
 

Загрузка…
Отмена
Сохранить