Game Development Reference
In-Depth Information
If-else: If something is true, do something; if it
s not true, do something
else. You can see an example structure of the if-else command in
Figure 14.7. Decisions are being made all the time in a computer game.
For example, consider a scenario where a player is moving toward some
enemies. If the player is within a certain distance of the enemies, the
creatures will attack. If the player is outside this range, the creatures will
continue to ignore the player. That is just one simple example of when
you may have if and if-else logic running within your game.
'
n
Figure 14.7
An example structure of the if-else command from the Microsoft MSDN site.
Switch: Allows you to use a number of options that could be true, and
then run code specifically for an answer. So you might ask a player for
her favorite color, for example. In the switch statement, if the color is
red, you will give 5 points, if it
n
'
'
s
yellow you will add 15 points. The switch case statement is very good at
assigning code to a particular response. You can also assign a default
s blue you will give 10 points, and if it
“
if
�
option. You can see an example of the switch structure in Figure 14.8.
none of the switch case is true, use the code contained in this section
Figure 14.8
An example structure of the switch case from the Microsoft MSDN site.
 
Search WWH ::




Custom Search