spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column47


A DOM-Based Snakes Game, Part II

Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies

In our previous column, A DOM-Based Snakes Game, Part I, we showed you the architecture of the Snakes game and the structure of the DOM that models it. We explained to you how to write the main script and we went over the global variables and their roles. In this column, we'll explain the rest of the script. We'll go over all functions and explain their objectives and algorithms.

The game's version presented here is slightly different than the one presented in the previous column. First, we have added several checks that made the game more robust. Secondly, we have implemented levels. The snake's speed doubles every time the player scores another 6 points. Go ahead and try the new version now. As an exercise, take the code from the previous column and try to implement the levels. See how different is your code from our version.

In this column we want to emphasize two particular programming aspects. The first one is how to build a JavaScript application around the DOM. We'll cover a lot of code in this column so you'll have to pay close attention to details. The second one is the software engineering side of the script. As a habit, we give long descriptive names to functions and variables. This practice makes the code relatively more readable and almost nullifies the need for easy-to-get-stale in-line documentation.

In particular, you'll learn:

We also include the game's complete listing and its zipped version as well.

More Resources from Doc JavaScript
Columns Popular Columns Tips Tools
Latest Columns
41-50 | 31-40 | 21-30
11-20 | 1-10
Working with Windows
JavaScript and Frames
Bookmarklets
Random Tips
Personalized Tips
RSS Channels
Menu Builder
Rollover Builder
Rotation Builder
Reference Tip Categories (want one?)
Links
For Your Site
Did you learn something? Do you like this site? Please link to us!

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji


Created: Aug 30, 1999
Revised: Aug 30, 1999

URL: http://www.webreference.com/js/column47/