Join us on Discord!
You can help CodeWalrus stay online by donating here.

Project LotG

Started by Woodrow, January 21, 2019, 04:53:45 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.


So, I'm making a text adventure game for a competition. i want the game (which you just lost) to
- take player choices as input and store them
- depending on player choices, move throughout the story
- have unique responses to certain inputs for comic effect, including a catch-all for unrecognized inputs ("what does [input] even mean?")

heres a basic example using my (incomplete)!game path so far. (etc means thats the farthest ive programmed in that path)

start > look > look > look > death for annoying the narrator
start > look > look > west > death for annoying the narrator
start > east > death by boredom
start > west > pet the goat > etc
start > west > attack the goat > death by goat attack
start > west > feed the goat > death by goat bite

basically, there is only one correct path through the game. all other paths inevitably lead to death and end the program.

my question is, how can i do this without drowning in if/else if/else/while loops? is there a library that could make my life easier? im using c++, but i can switch to java if that means more efficiency.

i have about a month for the competition.
  • Calculators owned: TI-83+
  • Consoles, mobile devices and vintage computers owned: TI-83+, iPhone, Nintendo Switch, iPad, Kindle
.emaG ehT esol won lliw uoy ,siht gnidaer rof tnemhsinup sA

Jean-Baptiste Boric

You can model your game as a (set of) finite state machine(s), where each state (vertex) has a number of valid transitions (directed graph) to progress the story depending on both the game's state and the player's input. Most adventure games have at least one FSM modelling the current player's location, but you can have more than one to handle things like puzzles, timers, NPCs and so on, depending on how complex your game will be.

Understanding the player's input is historically one of the hardest things to get right. There's no miracle solution, but generally you'll have to identify at least the verb (= action) and optionally one or more objects to act on. Tokenize the input and try to make sense of it. I recommend handling a fair amount of synonyms too, unless you want to frustrate users.

You can study some classic adventure games like battlestar (, though code quality has come a long way since the early 80s. I'd also recommend studying adventure ( as an example on how NOT to write an adventure game.


I'd suggest a language made for IF and text adventures like Inform 7 I think it's going to be the best. Nice learning curve, easy to do whatever needed in a standard IF game and it mostly looks like English.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

Powered by EzPortal