File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -18,23 +18,24 @@ const cellSize = 600 / boardSize; //セルの大きさ(px)
1818function isNextAlive ( around , self ) {
1919 // 自身が生きている & 周囲が 2 か 3 で生存
2020 if ( self && 2 <= around && around <= 3 ) {
21- return true ;
21+ return self ;
2222 }
2323 // 自身が死んでいる & 周囲が 3 で誕生
2424 if ( ! self && around === 3 ) {
25- return true ;
25+ return 1 ;
2626 }
27- return false ;
27+ return 0 ;
2828}
2929
3030// cellの状態に応じた色を返す関数
3131function getStyle ( cell ) {
32- // cellがtrueなら黒、falseなら白を返す
33- return cell ? "black" : "white" ;
32+ if ( cell === 0 ) return "white" ;
33+ // cellの値に応じて色を返す場合はここに追加
34+ return "black" ; // デフォルトは黒
3435}
3536
3637//Boardの初期化
37- let board = Array . from ( { length : boardSize } , ( ) => Array . from ( { length : boardSize } , ( ) => false ) ) ;
38+ let board = Array . from ( { length : boardSize } , ( ) => Array . from ( { length : boardSize } , ( ) => 0 ) ) ;
3839const table = document . getElementById ( "game-board" ) ;
3940
4041//盤面をBoardに従って変更する関数達(Boardを変更したら実行する)
@@ -209,7 +210,7 @@ function progressBoard() {
209210 for ( let ii = 0 ; ii < tate . length ; ii ++ ) {
210211 for ( let jj = 0 ; jj < yoko . length ; jj ++ ) {
211212 if ( tate [ ii ] !== 0 || yoko [ jj ] !== 0 ) {
212- around += board [ i + tate [ ii ] ] [ j + yoko [ jj ] ] ? 1 : 0 ;
213+ around += board [ i + tate [ ii ] ] [ j + yoko [ jj ] ] !== 0 ? 1 : 0 ;
213214 }
214215 }
215216 }
You can’t perform that action at this time.
0 commit comments