1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-07 17:44:22 +03:00
inform7/resources/Documentation/Examples/EyesFingersToes.txt
2023-07-24 11:56:58 +01:00

43 lines
2.6 KiB
Plaintext

Example: * Eyes, Fingers, Toes
Location: Variations: arrays, logs, queues, stacks, sets, sieves and rings
RecipeLocation: Bags, Bottles, Boxes and Safes
Index: Safe with a multi-number combination
Description: A safe with a multi-number combination, meant to be dialed over multiple turns, is implemented using a log of the last three numbers dialed. The log can then be compared to the safe's correct combination.
For: Z-Machine
It is not difficult to implement a safe which can be set to a single number to open; but a more common scenario in the real world is for the safe to open on a sequence of numbers when they have been dialed in the right order.
For IF, this means that we have to keep running track of the last N digits the player has dialed, dropping the first digit and adding a new one to the end each time the player re-dials the safe. This is a perfect occasion for lists:
{*}"Eyes, Fingers, Toes"
The Addams Wine Cellar is a room. It contains a closed lockable locked container called a safe.
The safe has a list of numbers called the current combination.
The safe has a list of numbers called the true combination. The true combination of the safe is {2, 10, 11}.
Understand "set [something] to [a number]" as setting it numerically to. Setting it numerically to is an action applying to one thing and one number.
Instead of examining the safe:
if the number of entries in the current combination of the safe is 0,
say "You haven't dialed the safe to any combination yet.";
otherwise say "You have dialed the safe to [the current combination of the safe].".
Check setting something numerically to (this is the block setting numerically rule):
say "[The noun] cannot be set."
Instead of setting the safe numerically to the number understood:
truncate the current combination of the safe to the last 2 entries;
add the number understood to the current combination of the safe;
if the safe is locked and the current combination of the safe is the true combination of the safe:
say "You dial [the number understood], and [the safe] gives a joyous CLICK.";
now the safe is unlocked;
otherwise if safe is unlocked and the safe is closed and the current combination of the safe is not the true combination of the safe:
say "You spin the dial, and [the safe] snicks locked.";
now the safe is locked;
otherwise:
say "You dial [the number understood] on the safe."
Test me with "x safe / set safe to 10 / x safe / set safe to 29 / x safe / set safe to 2 / x safe / set safe to 10 / x safe / set safe to 11 / open safe / set safe to 14 / close safe / set safe to 15 / open safe".