Script Classes for Adventure Games/Game Class

From SCI Wiki
Jump to: navigation, search

Official SCI Documentation

Chapter: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | Index

The Game Class

Author: Jeff Stephenson

Date: 5 April 1988


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.

In file:
Inherits from: Object
Inherited by: none



The user's current score.


The maximum number of points possible in the game.


The number of timer ticks (1/60th of a second) between animation intervals. Don't set this directly — use changeSpeed:.


A Set of the currently running Timers. The doit: method of the Game is what runs the timers.



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 basically
(self init:)
(while (not quit)
     (self doit:)
     (Wait speed)


Initializes the game, setting up some global variables and initializing the menu and inventory.


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: n

Make 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: n

Load 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: n

Add 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: event

After 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: n

Set 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.


This restarts the game at the beginning, allowing the user to start again without rebooting the game.


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.


Restores a saved game state. Not implemented.


Displays the amount of memory remaining in heap and hunk space.




Table of Contents


< Previous: The User Class Next: The Region Class >