87,993
社区成员
发帖
与我相关
我的任务
分享window.onload = function initGame() {
//初始化游戏函数
if (this.level < 4) {
this.margin = 12;
}
else if (this.level < 8) {
this.margin = 6;
}
else if (this.level < 16) {
this.margin = 3;
}
else {
this.margin = 1;
}
this.card = [];
this.size = (600 - (this.level + 1) * this.margin) / this.level;
for (var i = this.level * this.level; i--;) {
this.card.push({
color: false,//false是黄色,true是蓝色
})
}
//动态生成DIV
for (var x in card) {
var box = document.createElement("div");
box.style.width = size + 'px';
box.style.height = size + 'px';
box.style.marginTop = margin + 'px';
box.style.marginLeft = margin + 'px';
box.style.marginBottom = margin + 'px';
box.style.marginRight = margin + 'px';
box.style.background = '#E6AB5E';
box.style.cssFloat = 'left';
box.className += ' ' + 'card';
box.id += '' + x;
var bo = document.getElementById("board");
bo.appendChild(box);
for (var j = 1; j < this.level; j++) {
if (x == j * this.level) {
box.style.clear = 'both';//清除浮动效果
}
}
var id = x;
var e = document.getElementById(id);
e.setAttribute("onclick", "check(id)");
}
}function check(x) {
//this.card[x].color = !this.card[x].color;
var id = document.getElementById(x);
if (id.style.background == "rgb(230, 171, 94)") {
id.style.background = '#5C90FF';
} else {
id.style.background = '#E6AB5E';
}
changeNeighbor(x);
gameOver();
if(gameOver()){
setTimeout(function(){
alert('恭喜通过第'+this.level+'关');
this.level++;
this.initfame();
//initGame();
},200)
}
}