Game Development Reference
In-Depth Information
by its first letter, clicking the first letter again will highlight the
down word. Once we have determined the proper word to select,
we run through a for loop that assigns the color transforms we cre-
ated earlier to each of the tiles in the word. Now all that is left to
do is display the clue for the word; to do this, we grab the wordIn-
dex of the first tile in the word. Finally, we concatenate a string
with the word descriptor (
etc.) and the
clue itself, pulled from the corresponding XMLList. Now that we
have the behavior defined for when the player selects a tile, we
need some way of deselecting the tiles and words, like when they
click on a blacked-out tile. That
30 Across,
s where the clearSelection method
comes into play.
protected function clearSelection():void {
if (!_selectedWord) return;
for (var i:int = 0; i
_selectedWord.length; i++) {
_selectedWord[i].transform.colorTransform = new
All this method does is reset the color transforms for the tiles in
the currently selected word. If no word is selected when the
method is called, it exits. Note that we do not null out the variables
_selectedTile and _selectedWord , because we may need to know the
previously selected word. In fact, the selectTile method relies on
knowing the previously selected word to fulfill all its conditions.
Now that we have methods to set up a puzzle and select specific
tiles in it and we need one more method to insert letters into the
tiles.Ifyourecallinthe selectTile method,wesetupakeyboard
event listener when a tile is successfully selected. This method, key-
Down ,iswhatwe
ll look at next.
protected function keyDown(e:KeyboardEvent):void {
var selectedIndex:int = (_selectedTile.tileIndex.
y *_puzzleWidth) + _selectedTile.tileIndex.x;
var newIndex:int;
switch (e.keyCode) {
case Keyboard.UP:
newIndex = Math.max(0, selectedIndex -
if (_tileList[newIndex].letter != CrosswordTile.
EMPTY) _tileList[newIndex].dispatchEvent(new
case Keyboard.DOWN:
newIndex = Math.min(_tileList.length-1,
selectedIndex + _puzzleWidth);
Search Nedrilad ::

Custom Search