Game Development Reference
In-Depth Information
An alternative way of casting variables is to use the ]o keyword. You can write the
previous line of code like this:
_qnnajpCqaoo9ejlqp*patp]oqejp7
This line is very readable, and the effect is exactly the same. It's entirely up to you
which style of casting you prefer.
Now that you have a number in the _qnnajpCqaoo variable, you can use the eb+ahoa statement to
analyze it:
eb$_qnnajpCqaoo:iuopanuJqi^an%
w
kqplqp*patp9Pd]p#opkkdecd*7
y
ahoaeb$_qnnajpCqaoo8iuopanuJqi^an%
w
kqplqp*patp9Pd]p#opkkhks*7
y
ahoa
w
kqplqp*patp9Ukqckpep7
y
The logic behind this is really simple. If the _qnnajpCqaoo variable is greater than the iuopanuJqi^an,
That's too high. displays in the output text field. If it's less than the iuopanuJqi^an, That's too low.
displays. If it's neither too low nor too high, there has to be only one alternative left: the number is
correct. The output text field displays You got it!
Not so hard at all, is it? If you understand how this works, you might be pleased to know that writing
eb+ahoa statements will be at the very heart of the logic in your game design projects. It really doesn't
get much more difficult than this.
Displaying the game status
The logic works well enough, but you can't actually win or lose the game. The game gives you an end-
less number of guesses and even after you guess the mystery number correctly, you can keep playing
forever! Again, a fascinating glimpse into the nature of eternity and the fleeting and ephemeral nature
of life on earth, but not at all fun to play!
To limit the number of guesses, the program needs to know a little more about the status of the game
and then what to do when the conditions for winning or losing the game have been reached. You'll
solve this in two parts, beginning with displaying the game status.
 
Search Nedrilad ::




Custom Search