//update
function updateBoardView(){
$(".number-cell").remove();
for( var i=0 ; i< 4;i++){
for (var j = 0; j <4 ; j++) {
$("#contain").append('<div class="number-cell" id= "number-cell-'+i+'-'+j+'" ></div>');
var numbercell=$("#number-cell-"+i+"-"+j);
if( board[i][j]==0){
numbercell.css({
width:0,
height:0,
top:getTopPos(i,j),
left:getLeftPos(i,j),
backgroundColor:getNumberGroundColor(board[i][j])
});
}
else
{
numbercell.css({
width:100,
height:100,
top:getTopPos(i,j),
left:getLeftPos(i,j),
color:getNumberColor(board[i][j]),
backgroundColor:getNumberGroundColor(board[i][j])
})
}
}
}
}
// 这个是 moveleft
function moveleft(){
if(!canmoveleft(board))
return false;
//moveleft
for (var i = 0; i < 4; i++)
for (var j = 1; j < 4; j++) {
if(board[i][j]!=0){
for (var k= 0; k < j; k++) {
if(board[i][k]==0&&noblock(i,k,j,board)){
changeAnamation(i,j,i,k);
board[i][k]=board[i][j];
board[i][j]=0;
continue;
}
else if(board[i][k]==board[i][j]&&noblock(i,k,j,board)){
changeAnamation(i,j,i,k);
board[i][k] += board[i][k];
board[i][j]=0;
continue;
}
}
}
}
updateBoardView();
return true;
}
相关分类