Game Development Reference
In-Depth Information
You can see from these lists that any changes could tilt the outcome in favor of the
player or the CPU. Game programmers pay a lot of attention to balancing all of the
elements of the game. Initial value assignments are important to providing that game
balance.
Even the Vanish defect could have been the result of an Assignment problem. In the
imaginary implementation that follows, the Vanish ability is activated by setting up a
data structure and passing it to a generic ability handling routine.
ABILITY_STRUCT realmAbility;
realmAbility.ability = VANISH_ABILITY;
reamAbility.purge = DAMAGE_OVER_TIME_PURGE;
realmAbility.level = g_currentCharacterLevel[VANISH_ABILITY];
reamAbility.speed = g_vanishSpeed[realmAbility.level]
realmAbility.attackDelay = 30SECONDS;
realmAbility.duration = g_vanishTime[realmAbility.level];
realmAbility.displayDuration = FALSE; // wrong flag value
HandleAbility(realmAbility);
Alternatively, the assignment of the displayDuration flag could be missing altogether.
Again, cut and paste could be how the fault was introduced, or it could have been
wrong or left out as a mistake on the part of the programmer, or a misunderstanding
about the requirements.
Checking
A Checking defect type occurs when the code fails to properly validate data before it is
used. This could be a missing check for a condition or the check is improperly defined.
Some examples of improper checks in C code would be the following:
“=�? instead of “==�? used for comparison of two values
Incorrect assumptions about operator precedence when a series of compar-
isons are not parenthesized
“Off by one�? comparisons, such as using “<=�? instead of “<�?
A value ( *pointer ) compared to NULL instead of an address ( pointer )—either
directly from a stored variable or as a returned value from a function call
Ignored (not checked) values returned by C library function calls such as strcpy
Back to our friend the Vanish bug. The following shows a Checking defect scenario
where the ability handler doesn't check the flag for displaying the effect duration or
checks the wrong flag to determine the effect duration.
Search WWH ::




Custom Search