Game Development Reference
In-Depth Information
You can use the newline character in the middle of any string to break the text onto two lines or more.
Here's an example:
PdeopatpXjeo^nkgajejpdaie``ha*
It displays as follows:
Pdeopatp
eo^nkgajejpdaie``ha*
In the program you added the newline character by joining it to the rest of the text using string con-
catenation. Here's how it looks using the example text:
Pdeopatp'Xj'eo^nkgajejpdaie``ha*
The result is exactly the same, but the code is a little easier to read because it's visually very clear
where the line break falls.
Hey, why use the gameStatus variable, anyway?
There's one last thing you should quickly look at, and a question that you might have had about how
you've written the code in the eb+ahoa statement. You could have written the first two directives in
the eb+ahoa statement to look like this:
eb$_qnnajpCqaoo:iuopanuJqi^an%
w
kqplqp*patp9Pd]p#opkkdecd*'Xj' ±
CqaooaoNai]ejejc6'cqaooaoNai]ejejc'( ±
CqaooaoI]`a6'cqaooaoI]`a7
y
ahoaeb$_qnnajpCqaoo8iuopanuJqi^an%
w
kqplqp*patp9Pd]p#opkkhks*'Xj' ±
CqaooaoNai]ejejc6'cqaooaoNai]ejejc'( ±
CqaooaoI]`a6'cqaooaoI]`a7
y
ahoa
w
kqplqp*patp9Ukqckpep7
y
Why then did you go to all the trouble of creating a special c]iaOp]pqo variable if you could easily
have done without it? Obviously, it's a lot of code, it makes the eb+ahoa statement more difficult to
read, and you'd have to write it all out twice.
The other reason might be less obvious: if you have that text neatly stored in the c]iaOp]pqo vari-
able and you need to make any changes to it, you have to change it only once. Any place you use the
c]iaOp]pqo variable in the program is automatically updated with the new text. This might not be
such a big issue in a small program like this number guessing game, but in a bigger program, being
used 10 or 20 times in different places, it would be a lot of work to update.
 
Search Nedrilad ::




Custom Search