Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve display does not work if your html page contains some classes labelled as '.' + word to find #17

Open
clodion opened this issue Jan 31, 2022 · 0 comments

Comments

@clodion
Copy link

clodion commented Jan 31, 2022

The solve display need to find all the buttons created with an automated created class with the text to find. So, if your page uses this class to display some elements that are not in the puzzle, thoses elements will get the "wordFound" class.

The first time you solves the puzzle everything is good. but if you want to dynamically rgenerate another puzzle, without reloading your html page, then the solve script does not word anymore on the texte to find, which correspond to the className.

I've changed in wordfindgame.js the solve script in order to set the class "wordFound" only into the div containing te puzzle, whatever this div id can be. here is the code :

` solve: function(puzzle, words) {

            var solution = wordfind.solve(puzzle, words).found;

            // recherche l'element qui contient le puzzle
            var elem_puzzle = $('[x="0"][y="0"]').parent().parent().attr('id')
          
            for (var i = 0, len = solution.length; i < len; i++) {

                var word = solution[i].word,
                    orientation = solution[i].orientation,
                    x = solution[i].x,
                    y = solution[i].y,
                    next = wordfind.orientations[orientation];

                if (!$('#'+elem_puzzle + '.' + word).hasClass('wordFound')) {
                  
                    for (var j = 0, size = word.length; j < size; j++) {
                        var nextPos = next(x, y, j);
                        $('[x="' + nextPos.x + '"][y="' + nextPos.y + '"]').addClass('solved');
                    }

                    $('#'+ elem_puzzle +' .' + word).addClass('wordFound');
                    
                }
            }

        },

Hope it helps`everybody

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant