what are the approaches used to handle the game/level logic, which prevent you from falling into a spaghetti code?
I have a player in 3d isometric adventure game where you escape from a set of rooms.
Each room is different and sometimes you will need to go back, to pickup an item which is needed in your current ara ( you pickup a wrench in room 3, which you will use in room 6 to open up the safe ).
http://youtu.be/TmiTJPjdTzU
Let's imagine a simple level :

Player
Doors
Key
Ok, now that is easy aye?You can make this easily with a single BOOLean like:
// PSEUDOCODE //
bool bHasKey = false;
// Event handler
case ITEM_PICKEDUP:
{
if(item == key)
{
bHasKey = true;
}
}
break;
case PLAYER_COLLIDES_DOORS:
if(bHasKey == true)
{
pDoors->Open();
pKey->Destroy();
}
break;
It's easy but i would like to avoid this kind of coding game logic - as it turns very quickly, that if you handle 10 rooms per level in one game state, and you have 5 levels, your game state class for level handling will grow into a piece of if/else/switch/case stuff that you'll debug continously scratching your head and asking - why is this here, and that there..?
Let's go to another theoretical room.
So, this time player has tu pull 3 switches in specific order - which in return opens the door for 5 seconds.

Player
Switch
Doors
Now this level plus the previous one are slowly moving towards a mess - but as long as there are three to four rooms per level - you can handle it somehow.
What if my Level (map) has 10 rooms, each one more and more complicated, and i have 5 levels ready - making 50 rooms in total.
This kind of coding would be a disaster sooner or later...
How do you approach that ? single state machine per level ? ( how would you apply it to this model ? ) anything else?
I just can't figure out how to do it - my brain is empty after several days of decoding ima4.
Thanks !






