As someone who loves physics, I usually like to create games that have a lot of physically realistic movement, like pool, pinball, or miniature golf. But one day I noticed my wife playing a word-search game from a tiny book she'd just bought. She jokingly asked me, "Why can't you make a game like this?" So I did, and this is it!
Before beginning the task of creating Word Search, I thought, how hard can it be? It turns out that although it wasn't too terribly difficult, it was much harder than I had initially thought. It took me quite a bit of time to come up with a plan for coding this game.
The game of Word Search is easy to understand. It has a grid of letters that can be any size. In this game we use 17 by 17 letters. There is a list of words that can be found within this grid. Words may be positioned vertically, horizontally, or diagonally (and either spelled forward or backward in any of these directions). In this Flash Word Search version, I have enabled words in all directions except diagonal stretching from upper right to lower left.
When playing a word-search game on paper, you typically circle a word when you find it, or you mark through it. You also mark it off the list so that you can easily see which words you still have left to find. It's the same in this Flash version. When you find a series of letters you wish to select, you click and hold the first letter, and drag toward the last letter you want to include. As you drag, an oval is drawn along your path of movement. When you reach the last letter, you release the mouse button. If the letters you selected match a word from the word list, then the oval you drew stays on the grid, and the word from the word list is marked through and its color is changed. (If you've tried to select a group of letters that isn't on the word list, the oval disappears.)
The first thing you see is the main menu (also called the splash screen). This is the screen from which the player should be able to reach all major areas of the game. This basic splash screen has just three buttons: Start Game, Instructions, and Credits.
When you click Start Game, you are immediately taken to a new screen. On this screen you can scroll through a roster of word lists. Each category contains 14 words that will be hidden in the Word Search grid. To select a category, click the category name and click the Play button. You are then taken to the game screen. A list of words is displayed on the left. Each of those words is hidden among the pool of letters in the grid. Unlike what happens in the paper version of this game, if you get stumped, you can click the Show Answers button. This will make all of the letters invisible except those that fall within a word from the word list.
Every time a game starts, the grid is randomly created. The words are placed randomly and the filler letters are chosen randomly. The end result is this: You can play the same word list thousands of times and never get the same grid configuration. If you click Restart, the game will be restarted with a new grid configuration, but with the same word list.
That's it for the basic tour of the game. There is one more important thing to note, though. The word lists are stored in a single XML file called wordlists.xml. To fully understand how Flash loads an XML file and parses it to extract the necessary information, see Appendix D, "XML Basics in Flash." But even without much knowledge of XML, you can still modify the word lists very easily. You can add or remove lists, or just change what is there.
Open wordlists.xml from the Chapter14 directory. (As you probably know by now, you can open an XML file in almost any text editor.) The format of the XML in this file is very basic and should be easy to understand. The root node the lowest level of the XML structure is <lists>. There can be any number of <list> nodes that are children of <lists>. Each <list> contains 14 <word> nodes (to correspond to the 14-word format we've chosen for this game). Following is an example of what the entire XML file could contain if there were only two word lists.
Other than my choices for classic films, this example file should be fairly easy to understand. You'll notice that there is an attribute called category on the <list> nodes. This is the name you will see in the scrolling list on the Start Game screen of the game. You should also note that it doesn't matter if the words are capitalized or lowercased (except in the category attribute), because in the game all of the letters are going to get capitalized. Finally, you cannot use any characters in the <word> tags that are not letters. That means no spaces, dashes, numbers, or any symbols that are outside the realm of A Z. As an example, "Wizard of Oz" is written above as wizardofoz. With this information, you can easily create your own word lists!