猿问

请问什么地方有错啊!效果出不来。

var nextData=[

[2, 2, 0, 0],

[0, 2, 2, 0],

[0, 0, 0, 0],

[0, 0, 0, 0]

];

var gameData= [

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 2, 1, 0, 0, 0],

[0, 0, 0, 2, 2, 2, 1, 0, 0, 0],

[1, 1, 1, 1, 1, 1, 1, 0, 0, 0]

];

var nextDivs=[];

var gameDivs=[];

var initGame = function(){

for (var i=0; i<gameData[0].Length;i++) {

var gameDiv=[];

for(var j=0; j<gameData[0].Length;j++){

var newNode = document.createElement('div');

newNode.className='none';

newNode.style.top=(i*20) + 'px';

newNode.style.left=(j*20)+'px';

document.getElementById('game').appendChild(newNode);

gameDiv.push(newNode);

}

gameDiv.push(gameDiv);

}

}

var initNext = function(){

for (var i=0; i<nextData[0].Length;i++) {

var nextDiv=[];

for(var j=0; j<nextData[0].Length;j++){

var newNode = document.createElement('div');

newNode.className='none';

newNode.style.top=(i*20) + 'px';

newNode.style.left=(j*20)+'px';

document.getElementById('game').appendChild(newNode);

nextDiv.push(newNode);

}

nextDiv.push(nextDiv);

}

}

var refreshGame = function(){

for (var i=0; i<gameData.Length; i++) {

for (var j=0; j<gameData[0].length; j++) {

if(gameData[i][j] == 0){

gameDivs[i][j].className='none';

} else if(gameData[i][j] == 1){

gameDivs[i][j].className='done';

}else if(gameData[i][j] == 2){

gameDivs[i][j].className='current';

}

  }

}

}

var refreshNext = function(){

for (var i=0; i<nextData.Length;i++) {

for (var j=0; j<nextData[0].Length;j++) {

if(nextData[i][j] == 0){

nextDivs[i][j].className='none';

} else if(nextData[i][j] == 1){

nextDivs[i][j].className='done';

}else if(nextData[i][j] == 2){

nextDivs[i][j].className='current';

}

  }

}

}

initGame();

initNext();

refreshGame();

refreshNext();


慕盖茨1031366
浏览 1169回答 2
2回答

qq_杀意隆_0

贪吃蛇的?

第二十五夜

for (var i=0; i<gameData[0].Length;i++) 包括后面的有关i的都错了,应该是i<gameData.Length,j<gameData[0].length才对(二维数组的遍历)。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答