spacer

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

home / experts / javascript / column47


A DOM-Based Snakes Game, Part II (2)

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Building the Game's DOM

We build the game's DOM similarly to how we did it for the sliding puzzle. The board consists of maxRowCount of rows. We append a <BR> tag to the end of each row, and thus forcing the new lines:

function buildBoard() {
  for(var i = 0; i < maxRowCount; i++) {
    addOneRow();
    addBr();
  }
}

We build each row by first cloning the squareNode that we create in the main script:

var squareNode = document.createElement("IMG");

and then appending all nodes to the divNode node. Here is the full function:

function addOneRow() {
  for (var i = 0; i < maxColumnCount -1; i++) {
    tempSquareNode = squareNode.cloneNode();
    divNode.appendChild(tempSquareNode);
  }
}

Similarly, we create the <BR> node by cloning the brNode that we create in the main script:

var brNode = document.createElement("BR");

and then appending each node to the divNode node. Here is the full function for creating a single <BR> node:

function addBr() {
  tempBrNode = brNode.cloneNode();
  divNode.appendChild(tempBrNode);
}

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 >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Created: August 30, 1999
Revised: August 30, 1999

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