HTML and CSS Reference
In-Depth Information
or restore a set of walls saved earlier. In the second version, theres one program to create the mazes and
a second file that offers the player a choice of specific mazes to traverse, using radio buttons. Perhaps
one person might build the mazes on a given computer and then ask a friend to try traversing them.
HTML5s local storage facility accepts only strings of characters, and so well look at how we can use
JavaScript to encode the maze information into a character string and then decode it back to rebuild the
walls of the maze. The saved information will remain on the computer even after it is turned off.
The individual capabilities well discuss in this chapter: building structures, using the arrow keys to move a
game piece, checking for collisions, and encoding, saving, and restoring data on the user's computer, can
all be reused in a variety of games and design applications.
Note: HTML files are generally called scripts, while the term program is typically reserved for
languages such as Java or C. This is because JavaScript is an interpreted language: the statements
are translated one at a time at execution time. In contrast, Java and C programs are compiled, that
is, completely translated all at once, with the result stored for later use. Some of us are not so strict
and use the terms script, program, application, or, simply, file for HTML documents with JavaScript.
Figure 7-1 shows the opening screen for both the all-in-one program and the first script of the second
program.
Figure 7-1. Opening screen for the maze game
Figure 7-2 shows the screen after some fairly sloppy walls have been placed on the canvas.
 
Search WWH ::




Custom Search