src/lib/wordfindgame.js
function (target) {
            // if the user hasn't started a word yet, just return
            if (!startSquare) {
                return;
            }
            // if the new square is actually the previous square, just return
            var lastSquare = selectedSquares[selectedSquares.length - 1];
            if (lastSquare == target) {
                return;
            }
            // see if the user backed up and correct the selectedSquares state if
            // they did
            var backTo;
            for (var i = 0, len = selectedSquares.length; i < len; i++) {
                if (selectedSquares[i] == target) {
                    backTo = i + 1;
                    break;
                }
            }
            while (backTo < selectedSquares.length) {
                $(selectedSquares[selectedSquares.length - 1]).removeClass('selected');
                selectedSquares.splice(backTo, 1);
                curWord = curWord.substr(0, curWord.length - 1);
            }
            // see if this is just a new orientation from the first square
            // this is needed to make selecting diagonal words easier
            var newOrientation = calcOrientation($(startSquare).attr('x') - 0, $(startSquare).attr('y') - 0, $(target).attr('x') - 0, $(target).attr('y') - 0);
            if (newOrientation) {
                selectedSquares = [startSquare];
                curWord = $(startSquare).text();
                if (lastSquare !== startSquare) {
                    $(lastSquare).removeClass('selected');
                    lastSquare = startSquare;
                }
                curOrientation = newOrientation;
            }
            // see if the move is along the same orientation as the last move
            var orientation = calcOrientation($(lastSquare).attr('x') - 0, $(lastSquare).attr('y') - 0, $(target).attr('x') - 0, $(target).attr('y') - 0);
            // if the new square isn't along a valid orientation, just ignore it.
            // this makes selecting diagonal words less frustrating
            if (!orientation) {
                return;
            }
            // finally, if there was no previous orientation or this move is along
            // the same orientation as the last move then play the move
            if (!curOrientation || curOrientation === orientation) {
                curOrientation = orientation;
                playTurn(target);
            }
        }
function (target) {
            // if the user hasn't started a word yet, just return
            if (!startSquare) {
                return;
            }
            // if the new square is actually the previous square, just return
            var lastSquare = selectedSquares[selectedSquares.length - 1];
            if (lastSquare == target) {
                return;
            }
            // see if the user backed up and correct the selectedSquares state if
            // they did
            var backTo;
            for (var i = 0, len = selectedSquares.length; i < len; i++) {
                if (selectedSquares[i] == target) {
                    backTo = i + 1;
                    break;
                }
            }
            while (backTo < selectedSquares.length) {
                $(selectedSquares[selectedSquares.length - 1]).removeClass('selected');
                selectedSquares.splice(backTo, 1);
                curWord = curWord.substr(0, curWord.length - 1);
            }
            // see if this is just a new orientation from the first square
            // this is needed to make selecting diagonal words easier
            var newOrientation = calcOrientation($(startSquare).attr('x') - 0, $(startSquare).attr('y') - 0, $(target).attr('x') - 0, $(target).attr('y') - 0);
            if (newOrientation) {
                selectedSquares = [startSquare];
                curWord = $(startSquare).text();
                if (lastSquare !== startSquare) {
                    $(lastSquare).removeClass('selected');
                    lastSquare = startSquare;
                }
                curOrientation = newOrientation;
            }
            // see if the move is along the same orientation as the last move
            var orientation = calcOrientation($(lastSquare).attr('x') - 0, $(lastSquare).attr('y') - 0, $(target).attr('x') - 0, $(target).attr('y') - 0);
            // if the new square isn't along a valid orientation, just ignore it.
            // this makes selecting diagonal words less frustrating
            if (!orientation) {
                return;
            }
            // finally, if there was no previous orientation or this move is along
            // the same orientation as the last move then play the move
            if (!curOrientation || curOrientation === orientation) {
                curOrientation = orientation;
                playTurn(target);
            }
        }
function ( target ) { // if the user hasn't started a word yet, just return if ( ! startSquare ) { return ; } // if the new square is actually the previous square, just return var lastSquare = selectedSquares [ selectedSquares . length - 1 ] ; if ( lastSquare == target ) { return ; } // see if the user backed up and correct the selectedSquares state if // they did var backTo ; for ( var i = 0 , len = selectedSquares . length ; i < len ; i ++ ) { if ( selectedSquares [ i ] == target ) { backTo = i + 1 ; break ; } } while ( backTo < selectedSquares . length ) { $ ( selectedSquares [ selectedSquares . length - 1 ] ) . removeClass ( 'selected' ) ; selectedSquares . splice ( backTo , 1 ) ; curWord = curWord . substr ( 0 , curWord . length - 1 ) ; } // see if this is just a new orientation from the first square // this is needed to make selecting diagonal words easier var newOrientation = calcOrientation ( $ ( startSquare ) . attr ( 'x' ) - 0 , $ ( startSquare ) . attr ( 'y' ) - 0 , $ ( target ) . attr ( 'x' ) - 0 , $ ( target ) . attr ( 'y' ) - 0 ) ; if ( newOrientation ) { selectedSquares = [ startSquare ] ; curWord = $ ( startSquare ) . text ( ) ; if ( lastSquare !== startSquare ) { $ ( lastSquare ) . removeClass ( 'selected' ) ; lastSquare = startSquare ; } curOrientation = newOrientation ; } // see if the move is along the same orientation as the last move var orientation = calcOrientation ( $ ( lastSquare ) . attr ( 'x' ) - 0 , $ ( lastSquare ) . attr ( 'y' ) - 0 , $ ( target ) . attr ( 'x' ) - 0 , $ ( target ) . attr ( 'y' ) - 0 ) ; // if the new square isn't along a valid orientation, just ignore it. // this makes selecting diagonal words less frustrating if ( ! orientation ) { return ; } // finally, if there was no previous orientation or this move is along // the same orientation as the last move then play the move if ( ! curOrientation || curOrientation === orientation ) { curOrientation = orientation ; playTurn ( target ) ; } }
Event that handles mouse over on a new square. Ensures that the new square
is adjacent to the previous square and the new square is along the path
of an actual word.
Event that handles mouse over on a new square . Ensures that the new square is adjacent to the previous square and the new square is along the path of an actual word .