0
   if(isEmptySquare(this)){

        adjacents = adjacentSquares(this);

        $(adjacents).each(function(){

            uncoverSquare(this);

                    //if(isEmptySquare(this)){

            //adjacents = adjacentSquares(this);

            //$(adjacents).each(function(){

                //uncoverSquare(this);

        //});                   
    //}

        });                 
    }

 function adjacentSquares(square){

            var thisRow = $(square).parent().parent().children().index($(square).parent());
            var thisCol = $(square).parent().children().index($(square));
            var prevRow = (thisRow-1);
            var nextRow = (thisRow+1);

            if(thisCol == 0){sliceFrom = 0;} else { sliceFrom = (thisCol-1);}

            var above = $('tr:eq('+prevRow+')').children('td').slice((sliceFrom),(thisCol+2));
            var below = $('tr:eq('+nextRow+')').children('td').slice((sliceFrom),(thisCol+2));
            var aboveBelow = $.merge(above,below);
            var prevNext = $.merge(($(square).next('td')),($(square).prev('td')));
            var adjacents = $.merge(aboveBelow,prevNext);

            return adjacents;

        }

function isEmptySquare(square){

        if($(square).filter(function(){return !/[0-9]/.test( $(square).text() );}).not(":contains('x')").length>0){

            return true;

        } else { 

            return false; 
        }
    }

我将如何开始使用 jQuery 为表格单元格执行填充算法?

当前,当用户单击表格单元格时,如果该单元格为空,则其相邻单元格将被覆盖。我发现让它工作的一种方法是重复每个相邻方块的代码(我已经注释掉这部分代码),然后重复代码,重复代码.....尽管它变得没有响应.

我正在尝试用 jQuery 制作一个扫雷游戏,有人向我提到了一种洪水填充算法,尽管我不确定如何实现这一点。

4

1 回答 1

1

以防万一有人偶然发现这一点。我在这里找到了我正在寻找的答案http://www.htmlgoodies.com/primers/jsp/article.php/3622321/Javascript-Basics-Part-12.htm

于 2011-05-13T08:22:12.493 回答