Game Development Reference
In-Depth Information
Settings of different types— The current version of GameSettingsManager
only allows for storing and retrieving settings of type string . This may not
always be desirable. Of course, basic values such as booleans, integers or dou-
ble values could be stored as strings and then converted into different types
using the Parse method, but that takes a lot of extra computation time. Also,
sometimes we might want to use a more complicated type to store a setting.
For example, you could imagine that one would like to store network access
information (IP address, server login, password, and so on) in a single struc-
ture. We kept our example relatively basic, but there are several ways to solve
this. One way would be to add several dictionaries to the GameSettingsManager
class, one for each basic type. We could then write specific methods to re-
trieve and store settings of that type. You could even define these methods
as generics so that they work in a fashion similar to Content.Load<> . Another
way of solving it would be to make a single dictionary that retrieves values
of a user-defined type ValueType . Specific settings data structures could then
be implemented as a subclass of ValueType . Yet another solution would be to
implement a kind of tree structure where you can add any basic type as an
end node (this would be very similar to defining an XML structure). That
way, you do not need user-defined types, but you provide a way to the user to
define more complicated settings structures. As you can see, there are differ-
ent solutions to this problem, and you can choose the one that best fits your
particular needs.
20.6 What You Have Learned
In this chapter, you have learned:
how to define different GUI elements and display them in a menu;
how to read and store game settings using a static game settings manager.
Search WWH ::




Custom Search