Awkward but necessary

So, a couple students had the same really good question: the Exit constructor needs to get Room objects from the Dungeon, but there’s no way to get the Dungeon unless you go to the GameState to get it. But won’t the GameState only learn about which Dungeon is getting instantiated too late in the game? You can’t tell the GameState about the Dungeon only in its .initialize() method, because by that time you’d have to have a complete, wholly-instantiated Dungeon to give it, and you don’t have that when you’re still hydrating Exits.

Here’s the (somewhat awkward) solution: at the top of your Dungeon hydration constructor — it could even be the very first line — do this:

    GameState.instance().setDungeon(this);

That way, anything that comes afterwards (like Exit constructors hydrating exits) can safely ask the GameState for the dungeon it’s using, and get a valid object back.