Game Development Reference
In-Depth Information
2. Save the I]ej*]o file and test the program. The mystery number is now a random number
between 1 and 100. You'll also see the text The mystery number is: ?? displayed in the output
window so that you can make sure everything is working as you expect it to. Figure 5-21 shows
an example of what your game might now look like.
Figure 5-21. Randomizing the mystery
number
Disabling the Guess button
One quirky bug in the game so far is that if the player wins the game but continues clicking the Guess
button, the output text field still continues to count the guesses. If you think about how the program
is working, this makes perfect sense because the button itself has no way of knowing whether or not
the game is over; it just keeps on dutifully doing the jobs you assigned to it.
To fix this, you need to do three things when the game ends:
1. Remove the kjCqaoo>qppkj?he_g event listener from the cqaoo>qppkj object.
2. Disable the button so that it can't be clicked.
3. Dim the Guess button so that it's obvious to the player that the button can't be clicked. This is
an optional step, but anything you can do in your games to provide visual cues about how your
GUI works will really be appreciated by your players.
Three very straightforward lines of code are all you need.
1. Add the following code in bold to the aj`C]ia method:
bqj_pekjaj`C]ia$%6rke`
w
eb$c]iaSkj%
w
kqplqp*patp9Uao(ep#o'iuopanuJqi^an''Xj' ±
Epkjhupkkgukq'cqaooaoI]`a'cqaooao*7
y
ahoa
w
kqplqp*patp9E#ioknnu(ukq#ranqjkqpkbcqaooao*'Xj' ±
Pda_knna_pjqi^ans]o'iuopanuJqi^an'*7
y
++@eo]^hapdacqaoo^qppkj
cqaoo>qppkj*naikraArajpHeopajan$IkqoaArajp*?HE?G( ±
kjCqaoo>qppkj?he_g%7
cqaoo>qppkj*aj]^ha`9b]hoa7
 
Search Nedrilad ::




Custom Search