Game Development Reference
Creating a game manager
In Dungeon Maze Adventure, all the game logic is attached to `qjcakjKja in the @qjcakjKja[I]j]can
class. If you have more than one level in your game, however, it makes sense to have some code that
exists outside of the dungeon objects so that you that can manage them (a kind of “Dungeon Master”
that isn't removed when the levels are removed).
Hey, you already know how to do this! It's called the document class! Dungeon Maze Adventure
doesn't use a document class, but why not? Go ahead and make one; it will open up all sorts of
You can put any properties or methods that all the dungeons can use in the document class, which
will save you having to write the same method over more than once if that method is used in more
than one level. And you can use it as a way to keep track of global values, such as a score that persists
You can use public static methods to do this. You can define a static method using this format:
Other classes can then access the method like this:
Be careful when using public methods because they can break a class's encapsulation
and open you up to some of the dependency problems you looked at in the previous
You can also create getters and setters in this game manager class to allow the dungeons or the
objects in them to communicate with it. One of the dungeon objects can access the game's score with
a getter like this:
And set the score like this:
You can also access the document class from any other class using the format Ikrea?hel$nkkp% .
You can easily access all the dungeons and objects in them from the document class like this:
You already know how to do this, so go for it!