On Sep 9, 8:19 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hello,
>
> I've created a small game with jQuery: Fifteen 
> puzzle.http://www.alexatnet.com/node/68
>
> The jQuery part is very simple but I'm interested in ideas on how to
> make it smaller. Probably this can be a good demonstration of jQuery
> power, but it now contains 40 lines of jQuery code, when I prefer
> 20 :-)

I almost here:
26 lines:

        var lock = false;
        $('#shuffle').click(function () {
                if (lock) return;
                field.reset();
                $('#moves').html('0');
                $('#game15-field').empty();
                for (var col = 0; col < 4; col++) {
                        for (var row = 0; row < 4; row++) {
                                !field.isFree(row, col) && 
($('#game15-field').get(0).appendChild(
                                        $("<div class='game-cell'>" + 
field.cells[row][col] + "</div>")
                                                .css({ 'left' : col * 60 + 10, 
'top' : row * 60 + 45})
                                                .click(function () {
                                                        if (!lock && 
field.move(this._p)) {
                                                                lock = true;
                                                                
$('#moves').html('' + field.moves);
                                                                $(this).animate(
                                                                        {'left' 
: this._p.col * 60 + 10, 'top' : this._p.row * 60 +
45},
                                                                        300, 
'', function () {
                                                                                
field.isSolved() && alert('You win!');
                                                                                
lock = false;
                                                                        });
                                                        }
                                                }).get(0))._p = {'row': row, 
'col': col});
                        }
                }
        }).click();

Any ideas how to make it smaller?

Sincerely,
Alex

>
> Thanks,
> Alex

Reply via email to