The Essential Guide to HTML5

(Greg DeLong) #1

CHAPTER 5


Though these two programs are real games, they can be improved. For example, the player cant lose.
After reviewing this material, try to figure out a way to force a loss, perhaps by limiting the number of
moves or imposing a time limit.


These applications start the clock when theyre loaded. Some games wait to begin timing until the player
performs the first action. If you want to take this friendlier approach, youd need to set up a logical variable
initializ ed to false and create a mechanism in the choose function for checking whether this variable has
been set to true. Since it may not have been, youd have to include code for setting the starttime
variable.


This is a single-player game. You can devise a way to make it a game for two. You probably need to
assume that the people are taking turns properly, but the program can keep separate scores for each
participant.


Some people like to set up games with levels of difficulty. To do so, you could increase the number of
cards, decrease the pause time, or take other measures.


You can make this application yours by using your own pictures. You can, of course, use images of
friends and family members, but you could also create an educational game with pictures that represent
items or concepts such as musical-note names and symbols, countries and capitals, maps of counties
and names, and more. You can change the number of pairs as well. The code refers to the length of the
various arrays, so you dont need to go through the code changing the number of cards in the deck. You
may need to adjust the values of the cardwidth and cardheight variables, though, to arrange the cards
on the screen.


Another possibility, of course, is usin g a standard deck of 52 cards (o r 54 with jokers). For an example
using playing cards, skip ahead to Chapter 10, which takes you through creation of a blackjack game. For
any matching game, youll need to develop a way to represent the information defining which cards match.


Testing and uploading the application........................................................................................................


When we, the developers, check our programs, we tend to do the same thing on each pass. Users,
players, and customers, however, often do strange things. Thats why getting others to test our
applications is a good idea. So ask friends to test out your game. You should always have people who had
no hand in building the application test it. You may discover problems you didnt identify.


The HTML document for the polygon version of the memory game contains the complete game, since the
program draws and redraws the polygons on the fly. The photo version of the game requires you to upload
all the images. You can vary this game by using image files from the Web (outside of your own Web page).
Note that the pairs array needs to have th e complete addresses.

Free download pdf