Game Development Reference
In-Depth Information
Enumerations
This line 07 in code sample 1-3 declares an enumeration (enum) named
EnemyState . An enum is a special structure used to store a range of
potential values for one or more other variables. It's not a variable itself
per se, but a way of specifying the limits of values that a variable might
have. In code sample 1-3, the ActiveState variable declared in line
10 makes use of EnemyState . Its value can be any valid value from
the ActiveState enumeration. Enums are a great way of helping you
validate your variables, limiting their values within a specific range and
series of options.
Another great benefit of enums is that variables based on them have their values
appear as selectable options from drop-down boxes in the Object Inspector,
as shown in the following screenshot:
Enumerations offer you drop-down options for your variables from the Object Inspector
More information on enums and their usage in C# can be found online at
http://msdn.microsoft.com/en-us/library/sbbt4032.aspx .
The following are the comments for code sample 1-3:
Line 20 : The switch statement begins. Parentheses, () , are used to select
the variable whose value or state must be checked. In this case, the
ActiveState variable is being queried.
Line 22 : The first case statement is made inside the switch statement. The
following block of code (lines 24 and 25) will be executed if the ActiveState
variable is set to EnemyState.Fight . Otherwise, the code will be ignored.
 
Search WWH ::




Custom Search