Game Development Reference
In-Depth Information
P UTTING I TIN C ODE
For clarity, we will define an enumerated type GUESS_TYPE to represent our four
possible types of guessers.
typedef enum {
GUESS_33,
GUESS_22,
GUESS_RANDOM,
GUESS_SEMI,
} GUESS_TYPE;
To generate a guess using the complete model, we only need call the function
GetGuess() . The first order of business in GetGuess() is to call GetGuessType() .
GetGuessType() is a function that will, using the percentages laid out above,
identify which type of guesser we are modeling.
GUESS_TYPE CGuesser::GetGuessType()
{
int index = DieRoller.SingleDie( 100, false );
if ( index <= 4 ) return GUESS_33; // 1..4 = 4%
if ( index <= 7 ) return GUESS_22; // 5..7 = 3%
if ( index <= 37 ) return GUESS_RANDOM; // 8..37 = 30%
return GUESS_SEMI; // 38..100 = 63%
}
Note that we are using the object DieRoller that is an object of type CDie that
is declared in the header of CGuesser . We are asking for a number from 1 to 100.
(By leaving the second parameter, ZeroBased , as true, we would have received one
between 0 and 99.)
Once we have received a type of guesser back from GetGuessType() , we can
select the appropriate manner in which to generate the guess.
unsigned short CGuesser::GetGuess()
{
GUESS_TYPE GuessType = GetGuessType();
unsigned short Guess;
Search WWH ::




Custom Search