Hardware Reference
In-Depth Information
bit of code initially assumes that the irst player to press is correct, and the bit patterns that
are going to turn on the red and green LEDs on the two joysticks and enable the Slot Car
game are set up. hen the response is evaluated to see if it is correct. his is done by using the
list called single to convert or look up the four button press bits into a screen answer posi-
tion, which is then compared to the answer position that was previously noted. If it matches,
the initial assumption is correct - that is, the player to respond irst got it right; however, if
it doesn't match, you need to invert the bits deining the LEDs and relay with an exclusive OR
operation ^ using a mask of 0x3f. Also, the results display needs to be changed.
With the results displayed and Slot Car game enabled, the correct function is called. his
lashes the correct answer by alternately writing it in the normal text colour, or the alternate
text colour. his is done at 0.3 second intervals deined in the last line of the function for ten
times as deined in the second line of the function, giving a total of three seconds. Changing
any one of these two lines will change this three-second time. When this function returns to
the checkInput function all the PiFace outputs are turned of. his disables the racing car
and turns of the LEDs. hen the correct function is called again. his keeps on lashing the
correct answer for a further three seconds.
Over to You
Well, there you have the game as I wrote it. Now it is over to you to make it better or more
suit what you want it to do. You can change the racing car time; three seconds might not
seem very long, but I have found it is about right. However, with a bigger track to control you
might want it to be longer, or with a smaller track you might want it to be shorter.
hen there are the questions. You can add many more questions to the ile, but you might want
to have more than one set of questions of difering diiculty or on diferent subjects. You can
arrange that the user types in the name of the question bank ile irst. Better yet, you can give
the user a list of ilenames and get him or her to type in the appropriate number. If you use the
right sort of ile list command, you can list all the .txt iles in the directory so that you simply
need to add another ile to the directory for it to be automatically included in the list.
Finally, think about sound efects. You have seen in many of the programs in previous chap-
ters that there are sound efects, and they are quite easy to add too. How about a car roaring
noise when the game is enabled? Or you could add a blip to indicate when a question is up on
the screen ready to be answered. Or you could add a correct and incorrect noise of applause
and sighs, respectively. he choice is yours. Race away!
Search WWH ::




Custom Search