Hardware Reference
In-Depth Information
Listing 14-4 continued
buttonsInput = buttonsInput >> 4
bits = 0x26
else:
first = “ player 1 “
second = “ player 2 “
bits = 0x19
#print hex(buttonsInput), single[buttonsInput] , answerPos
if single[buttonsInput] == answerPos:
drawWords(“Correct”+first+”wins”, 5, False)
drawWords(first+”to race for 3 seconds”, 6, False)
pfio.write_output(bits)
else:
drawWords(“Wrong”+first+”loses”, 5, False)
drawWords(second+”to race for 3 seconds”, 6, False)
pfio.write_output(bits ^ 0x3f)
correct()
pfio.write_output(0)
correct() # keep on flashing for a bit
def scramble():
global aPos
aPos = [-1,-1,-1,-1]
for p in range(0,4):
match = True
while match:
match = False
candidate = random.randint(1,4)
for i in range(0,4):
if aPos[i] == candidate:
match = True
aPos[p] = candidate
def setupScreen(question) : # initialise the screen
global answer, answerPos
screen.blit(background,[0,0]) # set background colour
screen.blit(piSurface,[210,50])
pygame.display.update()
time.sleep(2.0) # delay while the players settle down
q = questions[question].split(“,”)
scramble()
drawWords(q[0],0, False)
Search WWH ::




Custom Search