varboard = new Array();
$(document).ready() {
newgame();
}
function newgame() {
init();
generateOneNumber();
generateOneNumber();
}
function init() {
alert("sdf");
for (var i = 0; i < 4) ; i ) {
borad[i] = new Array();
for (var j = 0; j < 4; j ) {
board[i] ][j] = 0;
var GridCell = $("#grid-cell-" i "-" j);
GridCell.css ("top", getPostTop(i, j));
gridCell.css("left", getPostLeft(i, j));
}
}
updateBoardview();
}
function updateBoardview() {
for (var i = 0; i < 4; i ) {
for (var j = 0; j < 4; j ) {
## $("#grid-container").append("<div class='number-cell' id='number-cell-" i "-" j "'></div>");
varnumberCell = $("#number-cell-" i "-" j);
if (board[i][j]) {
#numberCell.css("幅", 0 ピクセル);
numberCell.css("高さ", 0 ピクセル);
numberCell.css("上" , getPostTop(i, j) 100);
numberCell.css("left", getPostLeft(i, j) 100);
} else {
numberCell. css("幅", 100 ピクセル);
numberCell.css("高さ", 100 ピクセル);
numberCell.css("上", getPostTop(i, j));
numberCell.css("left", getPostLeft(i, j));
numberCell.css("background-color", getNumberBackgroundColor(board[i][j]));
numberCell.css("color", getNumbercolor(board[i][j]));
numberCell.text(board[i][j]);
}
}
}
}
function generatedOneNumber( ) {
var randx = parseInt(Math.floor(Math.random() * 4));
var randy = parseInt(Math.floor(Math.random() * 4) );
when(true) {
if (board[randx][randy] == 0) {
Break;
}
var randx = parseInt(Math.floor(Math.random() * 4));
var randy = parseInt(Math.floor(Math.random() * 4));
}
var randNumber = Math.random() < 0.5? 2 : 4;
ボード[randx][randy] = randNumber;
showNumberWithAnimation(randx, randy, randNumber);
}
##