在线急!!!!

来源:2-2 界面渲染逻辑

慕的地2332822

2019-08-16 15:22

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,2,2,1,0,0,0],

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

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

];

var nextDivs = [];

var gameDivs = [];

var initGame = function(){

for (var i=0; i<gameData.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);

}

gameDivs.push(gameDiv);

}

}

var initNext = function(){

for (var i = 0; i <nextData.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('next').appendChild(newNode);

nextDiv.push(newNode);

}

nextDivs.push(nextDiv);

}

}

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 (nextDivs[i][j]==1) {

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

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

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

}

}

}

}

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 (gameDivs[i][j] == 1) {

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

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

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

}

}

}

}


initGame();

initNext();

refreshGame();

refreshNext();

我的页面上什么也没显示,是不是gameData和nextData里没传进去数据?

写回答 关注

1回答

  • 慕设计8123586
    2019-08-24 15:24:43

    css没引用吧

基于websocket的火拼俄罗斯(单机版)

前端大牛带你实现单机版俄罗斯方块!

31676 学习 · 106 问题

查看课程

相似问题