About

This project started out as a way for me to learn PHP. I'm a big fan of Interactive Fiction (IF), and always thought it'd be cool to do a web-based IF engine.

The result of that idea coupled with a few weeks of work is a general-purpose IF engine I've dubbed pFiction (the P is silent and it stands for PHP fiction).

The Engine

The engine uses a finite state machine model to handle the various phases a game might have, for example a title screen state, playing state, or game over state.

Each state is a PHP class that derives from a base State class, and can expose its own commands that can be executed on itself as methods of the class. These methods follow a specific naming convention so that only methods that follow the convention are actually exposed by the engine.

Included in the engine is a general-purpose pager state, which can accept a large amount of text. When used, the pager suspends the existing state, renders the text in pages, and when completely paged through, it resumes the original state that invoked it. In IF games, this can come in handy.

Since most (if not all) IF games work with a map, there is a base Map class that is an implementation of a graph. The class provides ways to test for the existence of edges between nodes (rooms), and also to add/remove edges and nodes very easily. The edges can be weighted for games in which the cost to move from room to room may vary depending on certain conditions (i.e. terrain, weather, etc.). Eventually I'll add pathfinding support for the maps, and probably implement a couple of algorithms to include in the engine (like A* and Euclidian distance).

Finally the engine also supports skinning through CSS, so that games can have their own look and feel.

Sometime in the future I'll probably release the engine as open source.

Wumpus

To test the flexibility of the engine I decided to use Gregory Yob's Hunt the Wumpus as a guinea pig, mostly because the game is simplistic yet fun, and I didn't want to take months to write a full game.

The game consists of 3 states - TitleScreenState, PlayingState, and GameOverState. Each handles the respective aspect of the game.

The rules and text were taken and adapted from his article in a 1975 issue of Creative Computing (link).

Using the pFiction engine, the game took about 2 days worth of time to write. Hopefully you'll enjoy it as much as I enjoyed writing it :)