* Returns:
* If the move is possible (i.e., it is not off the puzzle frame),
* then it returns true. The actual direction of the move is
* stored in the mov parameter.
*
*/
SlidingPuzzle.translateMove = function(n, x, y, mov) {
mov.x = mov.y = 0;
switch (n) {
case 0: mov.y = 1; break;
case 1: mov.x = 1; break;
case 2: mov.y = -1; break;
case 3: mov.x = -1; break;
default: return false;
}
if (x + mov.x >= 0 &&
x + mov.x <= 3 &&
y + mov.y >= 0 &&
y + mov.y <= 3) {
return true;
}
else {
return false;
}
};
/*
* This handles the Window’s load event.
*/
$(function() {
var puzzle = new SlidingPuzzle();
puzzle.shuffle();
puzzle.setTileSize(80);
puzzle.start("puzzle");
});
</script>
</head>
<body>
<div id="puzzle"></div>
</body>
</html>
Further Reading
If you have become a keen programmer (I sincerely hope you have), you will soon
discover th at we only touched the surface of jQuery in this appendix, an d qu ite under-
standably so. There is simply too much going on in the wild to be able to even think of
including everyth ing in an appendix of an introductory programming book. I tried my
best, though, to introduce you the b asic principles that perpetuate this extremely pop-
ular library, but you will soon be reaching for other sources of information. Proba bly
one of the best sources for beginners is
Learning jQuery, a book by Jonatha n Chaer
B.4. jQu ery 301
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.81.154