Script Classes for Adventure Games/Game Class
Author: Jeff Stephenson
The Game Class
The Game class implements the game which is being written. The game author creates a source file with script number 0 which contains the instance of the class Game which is the game. This instance is where, for example, input not handled by any Actor, Room, Region, etc. will be handled.
The user's current score.
possibleScoreThe maximum number of points possible in the game.
speedThe number of timer ticks (1/60th of a second) between animation intervals. Don't set this directly — use changeSpeed:.
timersA Set of the currently running Timers. The doit: method of the Game is what runs the timers.
play:Your game is started by the kernel issuing the play: message to the object whose ID is in entry 0 of script.000. The play: method, as defined in the Game class, is basicallyCode:(self init:) (while (not quit) (self doit:) (Wait speed) )
init:Initializes the game, setting up some global variables and initializing the menu and inventory.
doit:This method is invoked once per animation cycle and passes the doit: method along to the rest of the game. It is responsible for changing rooms when a newRoom: has been done by the current Room.
newRoom: nMake room number n the current room. This should not be called directly from user code. This method deletes the cast and the old Room from the heap, then invokes the startRoom: method to load and initialize the new Room.
startRoom: nLoad and initialize room number n. When this method is invoked, the heap has been cleaned up from the previous room. Reimplement this to load any Regions which will span several Rooms and create heap fragmentation problems. Loading such regions below the Rooms lets them stay in the heap without fragmenting it.
changeScore: nAdd the number n (which may be negative) to the user's current game score. If the StatusLine is being displayed, update the score shown there.
handleEvent: eventAfter passing an event to the MenuBar and the cast, the User class sends the handleEvent: event message to the game, which in turn sends it to the regions. This method may be modified in the game instance to do a (super handleEvent:event) followed by processing to handle unclaimed events by printing an "I don't understand you" message.
setSpeed: nSet the number of timer ticks (1/60th of a second) between animation cycles to n. This also resets any Timers in the timers Set to account for the change in speed.
restart:This restarts the game at the beginning, allowing the user to start again without rebooting the game.
save:Saves the current state of the game to disk, allowing the user to quit the game and restart at the same point later using restore:. Not implemented.
restore:Restores a saved game state. Not implemented.
showMem:Displays the amount of memory remaining in heap and hunk space.