| 1 |
// $Id$
|
| 2 |
|
| 3 |
Game Clock
|
| 4 |
|
| 5 |
Initial development by Aaron Winborn.
|
| 6 |
|
| 7 |
Game clocks may be used for various purposes, such as keeping an in-game
|
| 8 |
calendar, tracking game effects and events, and limiting characters to acting
|
| 9 |
at a slower pace than might be suitable for a web-based game.
|
| 10 |
|
| 11 |
You may view all active game clocks from the Game Clock administration page,
|
| 12 |
as well as create new clocks there. Additionally, you can create new game
|
| 13 |
clocks programmatically with the API provided with the Game Clock module.
|
| 14 |
|
| 15 |
To do so, you would create a game clock array as follows:
|
| 16 |
|
| 17 |
$game = array(
|
| 18 |
'name' => $name, // A unique machine-name.
|
| 19 |
'title' => $title, // A human-readable title.
|
| 20 |
'status' => $status, // If TRUE, then the clock will begin started.
|
| 21 |
// If FALSE it begins paused. Defaults to FALSE.
|
| 22 |
'turn' => $turn, // The current turn to begin the clock.
|
| 23 |
// Defaults to 0.
|
| 24 |
'increment' => $increment, // How many seconds before incrementing to the
|
| 25 |
// next turn. Defaults to 0 (never; must be
|
| 26 |
// manually incremented).
|
| 27 |
'block' => $block, // If TRUE, then a block displaying this clock's
|
| 28 |
// current turn and status will become
|
| 29 |
// available. Defaults to FALSE.
|
| 30 |
'init' => $init, // If TRUE, then the clock will be checked for
|
| 31 |
// incrementation on every page load, assuming
|
| 32 |
// the proper time has passed.
|
| 33 |
);
|
| 34 |
game_clock_create($game);
|
| 35 |
|
| 36 |
Other available functions in the Game Clock API that may be useful:
|
| 37 |
|
| 38 |
game_clock_pause($clock = 'default', $status = FALSE);
|
| 39 |
game_clock_start($clock = 'default');
|
| 40 |
game_clock_increment($clock = 'default', $force = FALSE);
|
| 41 |
game_clock_reset($clock = 'default', $turn = NULL);
|
| 42 |
game_clock_state($clock = NULL);
|
| 43 |
|
| 44 |
Additionally, you may create a hook_game_clock function in your module to act
|
| 45 |
on game clock events, as follows:
|
| 46 |
|
| 47 |
function hook_game_clock($op, $clock = 'default', $state = NULL) {
|
| 48 |
switch ($op) {
|
| 49 |
case 'create':
|
| 50 |
// A clock named $clock has been created with $state.
|
| 51 |
break;
|
| 52 |
case 'pause':
|
| 53 |
// The clock named $clock has just been paused.
|
| 54 |
break;
|
| 55 |
case 'start':
|
| 56 |
// The clock named $clock has just been started.
|
| 57 |
break;
|
| 58 |
case 'increment':
|
| 59 |
// The clock named $clock has just been incremented a tick.
|
| 60 |
break;
|
| 61 |
case 'reset':
|
| 62 |
// The clock named $clock has just been reset (usually to 0).
|
| 63 |
break;
|
| 64 |
}
|
| 65 |
}
|
| 66 |
|
| 67 |
Please read the documentation in the game_clock.module file for more information.
|