Game Development Reference
In-Depth Information
This little snippet of code handles loading in the XML file with all
the crossword data and creates a new CrosswordPuzzle instance with it.
Finally, it centers the puzzle horizontally on the Stage and adds it to the
display list. This code could easily be integrated into a larger class that
handles, for instance, the loading of multiple puzzles.
The resulting SWF for the whole crossword engine is just less
than 15 k, pretty small for a lot of functionality. Using a device, or
a system, font for the tiles would bring it down even further, since
at least half the file is font data.
Content Is a Two-Way Street:
A Crossword Builder
While editing an XML file by hand is certainly not impossible, it
would get grueling pretty quickly to have to create entire cross-
word puzzles that way. This is where an editor comes into play.
Using the same core components, like the tile class and much of
thepuzzleclass,youcantakethecrosswordengineandwriteits
second version that outputs the XML file and even saves it to a
localfile.Whilewewon
t build an entire editor here, a savePuzzle
method might look like this for such applications.
'
protected function savePuzzle(e:Event = null) {
_content = new XML( < crossword width={_puzzleWidth}
height={_puzzleHeight} >< puzzle/ >< clues/ >< /crossword > );
for (var i:int = 0; i < _tileList.length; i+= _puzzle
Width) {
var slice:Array = _tileList.slice(i, i+_puzzle
Width-1);
var str:String =
;
for (var j:int = 0; j
""
slice.length; j++) {
if (slice[j].letter ==
<
""
) str += Cross
wordTile.EMPTY;
else str += slice[j].letter;
}
var row:XML = new XML( < row > {str} < /row > );
_content.puzzle.appendChild(row);
}
for (i = 0; i < _acrossClues.length; i++) {
var across:XML = new XML( < across > {_acrossClues
[i]} < /across > );
_content.clues.appendChild(across);
}
for (i = 0; i < _downClues.length; i++) {
var down:XML = new XML( < down > {_downClues[i]}
< /down > );
Search Nedrilad ::




Custom Search