The Game Engine
Text adventures are pretty simple computer programs. The computer describes the current location and any objects that can be found there.
The player then types simple commands such as 'GET ROPE' or 'BREAK WALL' and if the computer understands the command it will update the world and display any feedback that is relevant.
Most of the time a command moves you to a new location ('North', 'Climb Ladder') or it changes the state of the world (A door opens or an object is picked up).
To streamline the game logic, I created a sort of 'Logic List' that can be used by the program to check for specific game conditions.
Here is the class:
public class Logic
{
public int LogicID { get; set; }
public byte LocationID { get; set; }
public string Verb { get; set; }
public string Noun { get; set; }
public byte LocItem { get; set; }
public byte HaveLocItem { get; set; }
public string Action { get; set; }
public byte ID1 { get; set; }
public byte ID2 { get; set; }
public byte MsgID { get; set; }
}
The idea of the logic list is as follows: The commands typed by the player (verb and noun) are compared with the verb and noun in the logic list.
If they match then some additional checks are made - for example some commands only work in certain locations and other commands only work if you have access to another object.
If all the conditions are met then the logic list will execute a certain action.
It might display a message on screen, alter the state of an object or alter the game world by allowing the player to move to a location that was previously not possible.
We can now create a list with 'logic conditions' such as the following:
(1, 1, "HELP", "", 0, 0, "MSG", 43, 0, 0),
(2, 1, "GET", "BRAN", 24, 0, "MSG", 4, 0, 0),
(3, 1, "REMO", "LEAV", 24, 0, "SWITCH", 24, 4, 0),
(4, 2, "LOOK", "ANY", 0, 0, "MSG", 45, 0, 0),
If a player writes 'REMOVE LEAVES', and the current location is 1 then a SWITCH takes place. The branch (ItemID 24) is switched into a stick (ItemID 4).
All in all a pretty efficient way to deal with adventure world game logic.
Next - Game State