Steps for Creating a Simple Adventure Game in Ruby

By Christopher Haupt

Before you write one line of code in Ruby, think about the steps that your program needs to take to create an adventure game. It’s a turn-based, text adventure game, so everything will happen in the terminal window. But what exactly will it do?

First, the program needs to set up variables that keep track of the player. For this game, you’ll track the player’s health, how much treasure she found, what room she is in, and whether she escaped yet from the cavern.

The program should welcome the player, tell her what’s going on, and perhaps tell her how to play.

Each turn, the program should

  • Check to see whether the player is still alive and hasn’t escaped.

  • Check to see if a monster has shown up, and if so, let the monster and the player battle it out if desired.

  • Allow the player to look for treasure.

  • Let the player leave the room and go to another room.

The program should

  • Make sure that different rooms have unique descriptions.

  • Know how to randomly decide if monsters show up.

  • Determine randomly whether the player found treasure.

When the player takes too much damage or escapes the cavern, the program should display an appropriate final message.

Wow, that’s a lot! You’ll have to break this down into small bits of Ruby, but you’ll see that it isn’t actually too hard to create such a feature-rich game.