home / experts / javascript / column46 |
|
The Main ScriptUnlike the Sliding Puzzle from the previous column, the Snakes' board is constantly changing, even w/o a player intervention. Familiarize yourself with the game again. The snake is always on the move, even if the player is not engaged. Such a constant movement is achieved via the
The main program gives you a high-level abstract of the game's architecture and flow. The first line creates the root of the subtree we will deal with in the game:
The
Notice how we set the node properties. The name of the property is identical to the corresponding HTML attributes of the corresponding tag. We use the A DOM's subtree is not visible unless it is connected to the
The
The rest of the script is in a higher abstraction level. We first build the board:
Then we load its images:
We greet the player with game instructions:
We start the game by displaying the snake and its target:
And finally we go into an infinite loop of equally-spaced-in-time steps. In each step we move the snake one grid square:
In the next column we'll explain in detail each of this functions. |
Produced by Yehuda Shiran and Tomer Shiran
Created: August 16, 1999
Revised: August 16, 1999
URL: http://www.webreference.com/js/column46/main.html