Building a Gamebook Web Thingy

What's a Gamebook?

Give this short one a try

adventures.landoftalinas.com/homage

Can you figure out the video game homage?

What are the elements of a Gamebook?

Elements of a Gamebook

  1. Location text
  2. Choices
  3. Consequences/Transition text
  4. State

Adventure

Location

The trading post is a small village, set up here by enterprising settlers from the mainland. Its main export is fir trees from the forest. There is not much in the town; only the settlers' houses, a small market, a wharf, and a shrine to Lacuna the Huntress, goddess of nature.

Excerpts from Fabled Lands: War-Torn Kingdom

Choices

  • Visit the shrine to Lacuna turn to 544
  • Visit the market turn to 452
  • Visit the wharf turn to 332
  • Climb the hill that overlooks the town turn to 11
  • Go inland into the forest turn to 257

Consequences
Transitions

Transition

A narrow path leads up the hill, the top of which is crowned with a circle of large obsidian standing stones, hewn from solid rock. Turn to 65.

Consequence

The whirlwind guardian catches you and slams you against the stone walls until you are dead. Your adventures are over....

State

Put a checkmark in an empty box. If all the boxes are checked, turn to 236. Otherwise...

Converting the Elements to Objects

  1. Book => AdventureInterface
  2. Location text => SettingInterface
  3. Choice => ActionInterface (The crux!)
  4. Transition => Transition::class
  5. Consequence => Throw Exception
  6. State => Events::class

The Example

Location: You are in a Dark Cave with two torches towards the middle. Between the two torches is an Old Man. He holds a sword in his hands with the hilt towards you.

Choice: Take the Sword

The Example

State: Store event “sword-taken”

Transition: You grip the hilt of the sword and hold it above your head. Da da da da! The Old Man disappears and you are left alone in the cave.

AdventureInterface

Adventure::doAction

SettingInterface

Setting::doAction

ActionInterface

Actions are where it’s at!

SimpleResponseAction

LeaveAction

BinaryAction

ConditionalAction

ConditionalCheckInterface

MultiAction

AddEventAction

CompleteQuestAction

Transition

Putting It All Together

The Web Side of Things

  1. No Database!?!?
  2. Instantiates all objects on every request!?!?
  3. No Dependency injection container!?!?
  4. Views are made via echo-ing!?!?

Brace yourself. It’s about to get ugly.

Thanks

Questions? Critiques?