I’ve been avoiding my little text adventure tutorial because the next bit is quite a bit of work. But I’m gonna make a start on that today by talking a bit about doors. Liz England has a great post about door in games that’s well worth reading. For the sake of our text adventure we’ll define doors for ourselves.
Basically a door is any kind of barrier the player has to overcome. In our case we’re going to be implementing a literal door, in this case a cell door. But we’re gonna do it in a way that we can implement as many doors as we like using the same code. No point programing a one off event for something as important as this!
In the context of our map it’s going to have two locations, one in each room that it links. That means it potentially need two descriptions, one from each side, especially if it has a window, or is a cell door made of bars like in the old westerns, or some dungeons. The door itself might need a more detailed description, but we can use examination for that. To give clues as to how it might be opened. Of course a variable to tell us if it is locked, or opened would also be useful if it’s going to take a puzzle to open it. And since this is an adventure game, it wouldn’t be right to have a door that opens without having to solve a puzzle first. Our door structure then, will look something like this:
- Description Closed 1 – string
- Description Closed 2 – string
- Description Open 1 – string
- Description Open 2 – string
- On Examination – string
- Location 1 – int
- Location 2 – int
- Is Open – bool
- Is locked – bool
- Word – string
- Code – int
As you can see the humble Door is a bit more complicated than you might have thought. Even with that we’re probably no encapsulating all the data we need to have an effective door but that should be enough for the moment.
The next step will be expanding out parser to take into account of the new structure. This isn’t a difficult task but it will be time consuming as we will have to update all the actions to account for doors as well as adding this new word type to the command list. So just a bit more housekeeping than usual.
I’ve split this into two parts due to the usual time constraints, but part 2 won’t be as long coming as part 1 was. Because it’s been something I’ve been avoiding I’m making a concerted effort to get through this part so we can get on to more interesting stuff! Thanks for sticking with the series so far, I really hope you’ve gotten something out of it.