jQuery / Javascript扫雷堆叠滞后问题

时间:2013-07-24 22:38:27

标签: javascript jquery lag minesweeper

我的minesweeper存在一些滞后问题,无法弄清楚是什么导致了这个问题。当更多的瓷砖被揭示时,滞后,但不是灾难性的堆叠(自己尝试!),所以我限制了这些耦合函数的滞后可能来源:

function unhide(cell) { //called when user clicks a tile with class "hidden"
if ($(cell).hasClass('hidden')) {
    $(cell).removeClass('hidden');
    getclass(cell);
    if ($(cell).hasClass('miina')) {;
        locked = true;
        $('td').removeClass('hidden');
        textuncover();
        $('#endbox2').slideDown('slow');
        aika = null;
    }
    else if($(cell).hasClass('0')) {
        reveal(cell);
        revealmore();
    };
  };
};


function reveal(cell) { //if the clicked cell has no mines around it, the function reveals the mines the tile is touching
var row_crnt = $(cell).parent().parent().children().index($(cell).parent());
var cell_crnt = = $(cell).parent().children().index($(cell));
var row_new;
var cell_new;
if(row_crnt!=0) {
    row_new=miinakentta.rows[row_crnt -1];
    cell_new = row_new.cells[cell_crnt];
    $(cell_new).removeClass('hidden');
    getclass(cell_new);
};
if(row_crnt!=15) {
    row_new=miinakentta.rows[row_crnt +1];
    cell_new = row_new.cells[cell_crnt];
    $(cell_new).removeClass('hidden');
    getclass(cell_new);
};
if(cell_crnt!=0) {
    row_new=miinakentta.rows[row_crnt];
    cell_new = row_new.cells[cell_crnt -1];
    $(cell_new).removeClass('hidden');
    getclass(cell_new);
};
if(cell_crnt!=15) {
    row_new=miinakentta.rows[row_crnt];
    cell_new = row_new.cells[cell_crnt +1];
    $(cell_new).removeClass('hidden');
    getclass(cell_new);
};
if(row_crnt!=0 && cell_crnt!=0) {
    row_new=miinakentta.rows[row_crnt -1];
    cell_new = row_new.cells[cell_crnt -1];
    $(cell_new).removeClass('hidden');
    getclass(cell_new);
};
if(row_crnt!=15 && cell_crnt!=15) {
    row_new=miinakentta.rows[row_crnt +1];
    cell_new = row_new.cells[cell_crnt +1];
    $(cell_new).removeClass('hidden');
    getclass(cell_new);
};
if(row_crnt!=0 && cell_crnt!=15) {
    row_new=miinakentta.rows[row_crnt -1];
    cell_new = row_new.cells[cell_crnt +1];
    $(cell_new).removeClass('hidden');
    getclass(cell_new);
};
if(row_crnt!=15 && cell_crnt!=0) {
    row_new=miinakentta.rows[row_crnt +1];
    cell_new = row_new.cells[cell_crnt -1];
    $(cell_new).removeClass('hidden');
    getclass(cell_new);
};
};

function revealmore() { //makes all 'empty' tiles to reveal the content around it
var toreveal = $(".0:not(.hidden)");
if (toreveal.length != 0) {
    $(toreveal).each(function() { 
        getclass($(this));
        reveal($(this));
    });
setTimeout(revealmore,25);
};
toreveal = null;
};

我尝试将'揭示'和'显示更多'功能结合起来,但它根本没有用,导致更大的延迟。

我应该怎样做才能减少用户遭受的延迟?

非常感谢你!

P.S因为我只是练习我的js / jquery技能,所以扫雷只能在Chrome上运行良好,分辨率大约为1080p :)

0 个答案:

没有答案