Note About This Book: Advanced Lingo For Games was written by Gary Rosenzweig in 2000 for users of Macromedia Director 7. It is presented here for free on an as-is basis, with no updating. Most of the information and code here can be used in the most recent version of Director. The book has been reproduced from the final editing files archived in 2000, and not the final proof galleys. So some minor differences between this version and the printed version my exist. The entire contents of this book are Copyright 2000, Gary Rosenzweig. No part may be reproduced or copied without written permission. The text here is provided for individual use only.
Want to thank me for making this book available for free? Just buy Special Edition Using Macromedia Director MX and we'll call it even!

Advanced Lingo For Games
by Gary Rosenzweig


Chapter 16 Section 3

Making the Game

This game's code is contained in one large script. This script is the sprite behavior that goes with the matrix text sprite. It creates the puzzle, maintains it during the game, monitors mouse actions, and deals with, well, everything else.

We'll start with the property declarations. Like the previous two chapters, we get a word list from a text member. We also have a "pEndGameFrame" property. There will be a large list of lists, stored in "pMatrix" that contains the whole letter matrix. The width and height of this square matrix will be stored in "pMatrixSize".

The rest of the properties have to do with the player's current selection in the matrix. We have one property, "pFirstChar", that stores the first character in the selection, and another, "pSecondChar" that stores the last character. When these two properties are set to VOID, it means that no selection is being made at the current time.


property pWordSource -- text member with words
property pWordList -- assembled word list
property pMatrix -- list containing all letters
property pMatrixSize -- width and height of matrix
property pEndGameFrame
property pFirstChar -- first char position of selection
property pLastChar -- last char position of selection

The on getPropertyDescriptionList handler only contains two properties this time. The first is the member that contains the word list. The second is the frame that the game goes to when the player has found all the words. Figure 16.2 shows the Parameters dialog box.

Figure 16.2
The Parameters dialog box is shown here for the word search behavior.

on getPropertyDescriptionList me
  list = [:]
  
  -- the text member with the words in it
  addProp list, #pWordSource,[cc]
    [#comment: "Word Source",[cc]
     #format: #text,[cc]
     #default: VOID]
  
  addProp list, #pEndGameFrame,[cc]
    [#comment: "End Game Frame",[cc]
     #format: #marker,[cc]
     #default: #next]
  
  return list
end

The behavior starts off by building the matrix and placing it and the word list on the screen. It also initializes the selection properties.

The property "pMatrixSize" is set to 15 in this handler. However, you could set it to some other value for a larger or smaller puzzle, or even add it to the on getPropertyDescriptionList handler to allow it to be set in the Parameters dialog box. However, the rest of the code is optimized for a 15[ts]15 matrix. So you might have to make some adjustments in your font size and selection line sizes should you decide to change this property.


-- initialize word list, matrix, and screen displays
on beginSprite me
  pMatrixSize = 15
  buildMatrix(me)
  showMatrix(me)
  showWordList(me)
  pFirstChar = VOID
  pLastChar = VOID
end

The first step in creating the game matrix is to read the list of words in the text member. Just like with the cryptogram and Hangman games, this game makes sure that all the letters are in uppercase, even if they have not been typed in that way.


-- get words from text member
on getWords me
  text = member(pWordSource).text
  -- convert all letters to caps
  repeat with i = 1 to text.length
    put convertToCaps(me,text.char[i]) into char i of text
  end repeat
  
  -- populate word list
  list = []
  repeat with i = 1 to text.line.count
    -- throw away blank lines
    if text.line[i].length < 1 then next repeat
    add list, text.line[i]
  end repeat
  
  return list
end

This next handler is identical to the "on convertToCaps" handlers in the previous two chapters.


-- utility handler that takes a character and converts it to uppercase
on convertToCaps me, c
  ascii = chartonum