Game Development Reference
In-Depth Information
You are in a dark room, you can see nothing.
> Search
You search around in the dark, your fingers brush against something
metallic.
> Examine metallic thing
It's hard to make out in the dark but it seems to be a flashlight.
> Turn on flashlight.
The flashlight flickers to life.
An interactive fiction game has two main parts: a data structure holding the
description of the world and a parser that interprets the users input. The data
structure describing the world can be quite simple.
class Room
{
public string Description {get; set;}
public List < Room > Exits{get; set;}
public Room(string description, List < Room > exits)
{
Exits = exits;
Description = description;
}
}
The Room class is a single place in the game world; it has a string of text that
describes it and a list of exits to different rooms. The player can be given a de-
scription of each room and use the exits to travel around the map. Exits can be
added and removed as puzzles are solved.
The parser is a piece of code that matches patterns. The user might type ''Look''
into the console and then press enter to look around a room; in code this would
be handled like so:
if (_input == "look")
{
// The look function writes the description to the console.
_currentRoom.Look();
}
A more complicated statement would require more parsing; for example, ''use
hammer on doorstep.'' The following code is a little idealized but gives an idea of
how the user commands could be broken down.
Search WWH ::




Custom Search