Hardware Reference
In-Depth Information
pfio.write_output(lastColour)
time.sleep(0.3)
pfio.write_output(newColour)
time.sleep(0.3)
player = pfio.read_input() & 3
count +=1
pfio.write_output(0) # turn off the light
time.sleep(2)
countToMatch = random.randint(3, 10)
def set_table(name, score):
scoreTable = shelve.open('score_table.snap')
if not name in scoreTable:
scoreTable[name] = score
elif score > scoreTable[name]:
scoreTable[name] = score
else :
score = scoreTable[name]
scoreTable.close()
return score
def show_table():
print
print “The current high scores are”
scoreTable = shelve.open('score_table.snap')
highscores = scoreTable.items()
highscores.sort(key=lambda elem: elem[1], reverse=True)
for entry in highscores:
print entry[0], “has a score of”,entry[1]
scoreTable.close()
print
if __name__ == '__main__':
main()
First of, you will see that you use the pygame module, but you are using that only for the
generation of sound. he main function starts of by asking for all the user input and then
enters an outer while loop that plays all the rounds. his is followed by another while loop
that does the actual playing of the round; this calls up the generation of the colours and the
checking of the user input in addition to playing the appropriate sound. At the end of all the
rounds, one player is declared the winner, and the updated high-score table is displayed.
Search WWH ::




Custom Search