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: game.sc
Inherits from: Object
Inherited by: none



Properties

score

The user's current score.

possibleScore

The maximum number of points possible in the game.

speed

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

timers

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


Methods

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 basically
Code:
(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: 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.

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.

 

Notes


 

Table of Contents

 

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