I realized today in office hours that there was a slight bug in my Zork II design; namely, when Exits are being hydrated, they need to be able to get Room objects that match the names in the file, yet the Dungeon is in the process of being hydrated, and so isn’t available yet.
This seems like the cleanest fix:
- Add a .setDungeon() accessor method to GameState in order to access the Dungeon object. (This is now reflected in the class diagram.)
- Add this line of code as the first line of the new Dungeon constructor:
Now, in the Exit constructor, you’ll be able to safely call GameState.instance().getDungeon().getRoom() so that you can wire up your hydrated Exits to the right Rooms.