The data you loaded and parsed can be accessed just as you've indicated, using standard conditional logic. If you're looking for conciseness, there are other ways to do conditional logic:
switch keyword is one (found in most imperative-style languages), while the
?: operators are another. Neither is much more elegant than
if, except for small sets of conditionals.
- There is a more elegant way that takes two forms: function pointers (also known as "functors" or in C#, "delegates"), or the structural equivalent frequently used in OO languages, the Strategy Pattern.
Function pointers are simple:
//do something totally different
myFunc = boo;
myFunc = foo;
myFunc(); //we use this in place of an if statement + resultant logic. It's a "strategy" that's been assigned based on the value of something else.
The Strategy Pattern is really just a way to package up the same mechanism into classes, where one or another problem with the language makes it hard or impossible to do the assignment and/or direct function call on
myFunc, above. It's purpose is "to allow an algorithm to be selected at runtime". The "algorithm", in this case, is exactly what you have between the braces of your
if statements. As for nesting, yes you can use function pointers within calls to other pointed-to-functions. Same goes for Strategy Pattern, it can operate at many different, nested levels.
As an aside...
You have two choices at the higher level as to when to handle changes to the game world:
- What you're doing above, which is to respond to events
- Polling: On every game update, you simply re-run all of the logic that looks at the level data (as you're doing above) and makes changes to your game's data model as a result.