Game Development Reference
In-Depth Information
}
_crosswordClue = new CrosswordClue();
_crosswordClue.y = getRect(this).bottom + 20;
addChild(_crosswordClue);
}
There is a lot to the createPuzzle method, so we
'
ll break it down
into more manageable chunks.
_puzzleWidth = _content.@width;
_puzzleHeight = _content.@height;
var totalWords:int = 1;
var tile:CrosswordTile;
The first few lines simply initialize the variables that will be
used throughout the rest of the method. Note that the attributes
we assigned to the crossword XML earlier are prefixed with the @
symbol. Another great feature of E4X is that it is smart enough to
differentiate numbers from strings, so even though the values were
in quotes in the XML file, Flash converted them to numbers for us.
for (var i:int = 0; i < _puzzleHeight; i++) {
for (var j:int = 0; j < _puzzleWidth; j++) {
var letter:String = _content.puzzle.row[i].
charAt(j);
tile = new CrosswordTile(letter);
tile.name = j.toString() + " _ " + i.toString();
tile.tileIndex = new Point(j, i);
Next,webegintwo for loops that will run through the entire
grid of the puzzle, row by row. Each iteration identifies the letter
used at that space in the grid and creates a new CrosswordTile
object for each one. As you can see, to get down to a specific row
inthepuzzlenodeoftheXML,wesimplyuseacombinationof
dot and array syntax. When you have multiple nodes on the same
level with the same name, Flash converts it into an XMLList object,
like an XML array. To get at a particular item in the XMLList, we
use a number from 0 up to the number of items minus 1.
if (letter != CrosswordTile.EMPTY) {
var startOfWord:Boolean = false;
if (j == 0 || _content.puzzle.row[i].charAt(j-1) ==
CrosswordTile.EMPTY) {
tile.acrossIndex = _wordListAcross.push(new
Array());
_wordListAcross[tile.acrossIndex-1].push
(tile);
startOfWord = true;
}
Search Nedrilad ::




Custom Search