俄罗斯方块布局

布局的话就是随意搭配的,一共有三块:
方块的容器,显示预告,和显示得分。
都是用JS来写的,没有用到jquery。

其中divs是下落方块的数组

// 显示方块
this.show = function() {
   for(var i in this.divs) {
       this.divs[i].style.top = (this.shape[i * 2 + 1] - -this.y) * size + "px";   //顶部中间开始
       this.divs[i].style.left = (this.shape[i * 2] - -this.x) * size + "px";
       }
}

divs2是预告方块的数组

// 显示预告
this.showAnnouncement = function() {
   for(var i in this.divs2) {
       this.divs2[i].style.top = (this.shape2[i * 2 + 1] - -1) * size + "px";   //定位在显示区
       this.divs2[i].style.left = (this.shape2[i * 2] - -1 - -col) * size + "px";
       }
}

container是显示界面构造函数的一个对象

// 显示分数
this.showScore = function() {
   if(this.container && this.score) {
       this.score.innerHTML = "score:" + this.container.score;
       }
}

猜你喜欢

转载自blog.csdn.net/qq_43302945/article/details/82973135