11"use strict" ;
2- let timerId = 0 ;
2+
33let timer = "stop" ;
44let generationFigure = 0 ;
55
@@ -40,10 +40,7 @@ function deadCellJudge(around) {
4040}
4141
4242const generation = document . getElementById ( "generation" ) ; //世代を表す文(第+数字+世代)
43- const isProgress = document . getElementById ( "timer" ) ; //進行中かを表す文(再生中/停止中)
4443//BUTTON
45- const startButton = document . getElementById ( "startbutton" ) ;
46- const stopButton = document . getElementById ( "stopbutton" ) ;
4744const randomButton = document . getElementById ( "randombutton" ) ;
4845const resetButton = document . getElementById ( "resetbutton" ) ;
4946const sizeChangeButton = document . getElementById ( "sizeChangeButton" ) ;
@@ -88,7 +85,9 @@ function renderBoard() {
8885 table . appendChild ( tr ) ;
8986 }
9087}
88+
9189renderBoard ( ) ;
90+ progressBoard ( ) ;
9291
9392randomButton . onclick = ( ) => {
9493 //白黒ランダムにBoardを変更
@@ -108,35 +107,12 @@ resetButton.onclick = () => {
108107 stop ( ) ;
109108} ;
110109
111- startButton . onclick = start ;
112- stopButton . onclick = stop ;
113-
114- function timerChange ( sentence ) {
115- //現在再生中かを表すtimer変数を変更し、文章も変更
116- timer = sentence ;
117- isProgress . textContent = timer === "start" ? "再生中" : "停止中" ;
118- }
119-
120110function generationChange ( num ) {
121111 //現在の世代を表すgenerationFigureを変更し、文章も変更
122112 generationFigure = num ;
123113 generation . textContent = "第" + generationFigure + "世代" ;
124114}
125115
126- function start ( ) {
127- if ( timer === "stop" ) {
128- timerId = setInterval ( progressBoard , 1000 ) ;
129- timerChange ( "start" ) ;
130- }
131- }
132-
133- function stop ( ) {
134- if ( timer === "start" ) {
135- clearInterval ( timerId ) ;
136- timerChange ( "stop" ) ;
137- }
138- }
139-
140116function progressBoard ( ) {
141117 const newBoard = structuredClone ( board ) ;
142118 for ( let i = 0 ; i < boardSize ; i ++ ) {
0 commit comments