Javascript と HTML5 Canvas を使用して、コンウェイの人生ゲームを作成しています。ここのコードは、gameOfLife オブジェクトのコンテキスト内にあります。
this.cells = [];
this.nextCellState = [];
this.cells
セル オブジェクトを入力した後、次this.nextCellState
のように入力します。
this.nextCellState = this.nextCellState.concat(this.cells);
マウスをクリックすると、対応するセル オブジェクト プロパティ isAlive が true になります。
function clickAlive(x, y) {
for (var i in this.cells) {
if (x.between(this.cells[i].x, this.cells[i].x + cellsize) && y.between(this.cells[i].y, this.cells[i].y + cellsize)) {
this.cells[i].isAlive = true;
console.log('Breakpoint');
}
}
}
問題は、ブレークポイントでcells
とnextCellState
配列を見ると、どちらもクリックされたセルが にアクティブになっていることtrue
です。
これは何が原因ですか?