David Whitten (whi...@netcom.com) wrote:
> The idea is simple. For each of the puzzles or situations that the player
> may be in, you create a room. You create an object that 'ghosts' the
> player. You start the ghost object in the 'begin situation room'.
> Every time your player solves a puzzle (or acts appropriately according to
> the plot), you move the ghost object through the exit named for that
> solution, or action. This puts the ghost object in another room.
> The game/story is over when there are no further exits from the room.
I'm not sure how this would work given that several puzzles may be in
progress at once. Usually when I'm playing a game, I may have seen
several puzzles that might be valid "targets" for hints. How could the
"ghost" be in multiple rooms?
Here is another way this might be implemented. Yes, this is a DAG.
Define objects "Puzzle" and "Hint". Each Puzzle has a list of
prerequisite Puzzles which must be solved before the Puzzle can be
attempted. Hints will only be given about a puzzle if it has no
prerequisites or all of its prerequisite puzzles have been solved. Each
Hint has an owner Puzzle. Each Hint has a list of other Hints which are
prerequisites; a hint can only be given if it has no prerequisites or one
of its prerequisite hints has been given. This allows general hints to
be given first, and broader hints (i.e. more exact) can be given later only
if the earlier ones have been given.
When a command is entered that solves a Puzzle, send a "solved" message
to that Puzzle. It sets an internal variable to remember it's been solved.
When the "hint" command is entered:
Create empty list L of possible hints
Loop over all Puzzles P
If P is not solved
If all of P's prerequisites are solved
Loop over all Hints H owned by P
If H has not already been given
If any of H's prerequisite hints have been given
Add H to list L
Choose a Hint from list L, display it, and mark it as given.
This approach has the advantage that the puzzles and hints can be retrofitted
to an existing game with a separate file. The only change needed to the game
code is calling the solve function when a puzzle is solved.