Code Organization


I’m getting ready to make my first game outside of a 4-room test game, and it’s going to be fairly large (at least for me). I’d like some tips on organizing it so that it doesn’t get confusing. As a web developer I’m aware that a manageable organization up front can make all the difference in not getting overwhelmed.

I’d love some suggestions on how others do it. This is what I’m leaning toward right now:

[map directions]

North of the Dining Room is the Kitchen.
East of the Kitchen is the Dining Room.


The Dining Room is a room.
“You are in a well decorated dining room with blah blah…”

The Kitchen is a room
“You are in a small kitchen with blah blah…”

[initial states]

The table is in the dining room.
The chair is in the dining room.

The refrigerator is in the kitchen.
The milk is in the refrigerator.
The sink is in the kitchen.

[every turn]
Instead of taking milk:
do whatever

Any suggestions would be appreciated. Thanks!

The best thing to do is to look at how other people have done it. lists many games with released source code. Looks like many people tend to organize the code roughly as General rules - Rooms (with items as each room’s subchapters) - NPCs - Testing. It also depends on the type of the game what the best organization is.

Good advice, Nitku, I will do that.

One thing I’m doing in the meantime is creating individual puzzles in their own small projects (like makeHatTester) so that I can test them exhaustively before entagling them in the larger project. So far I’m surprised at how manageable I’m keeping the game. I do want to make sure I can read through and understand it after it’s all in one large file, though.

Are there any source files that other recommend as particularly well-organized?