-
Notifications
You must be signed in to change notification settings - Fork 2
/
menus.py
79 lines (63 loc) · 2.8 KB
/
menus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
#menus are defined here
import game, pygame, menu, sys, time, speech, cPickle
from ug_data import *
s = speech.s
_ = speech.getTransFunc()
def resumegame():
ev_game_active = pygame.event.Event(pygame.USEREVENT, {'code': 1})
game.previous = time.time() + game.remaining
pygame.mixer.unpause()
pygame.event.post(ev_game_active)
def abortgame():
pygame.mixer.stop()
game.remaining = None
game.score = None
return main_menu.init()
def quit ():
s.say (_("Exiting now."), 1)
s.quit ()
pygame.quit ()
sys.exit ()
def readmanual():
s.say (_("This is very simple. Listen for incoming planes and press corresponding arrow (Left, Up or Right) to launch a missile in given direction.\nPress L to announce number of remaining lives and S to announce your score.\nPress ESCAPE to pause the game.\nHave fun!"), 1)
#define function for dynamic generation of score menu
def genscoremenu(field):
scoremenuitems = []
filteredscore = []
for score in game.scoreboard:
if score[field] != None:
filteredscore.append(score)
if field == 0:
sortedscore = sorted(filteredscore, key = lambda score: score[field], reverse=True)
else:
sortedscore = sorted(filteredscore, key = lambda score: score[field])
for item in sortedscore:
menustring = _("{0} points").format(item[0])+unicode(time.strftime("%c", item[1]), "utf-8")
if item[2] != None:
menustring += _(", the fastest reaction {0} milliseconds").format(item[2])
scoremenuitems.append(menu.menuitem(menustring, None))
scoremenuitems.append(menu.menuitem(_("Go back"), lambda :main_menu.init()))
scoremenu = menu.menu(_("Use up and down arrows to browse score.\nSelect last item to return to the main menu."), scoremenuitems)
return scoremenu.init()
def stereoTestFunc():
game.chan.play(stereotest)
def resetScoreFunc():
game.scoreboard = []
scorefile = open("score.dat", "w")
cPickle.dump (game.scoreboard, scorefile)
scorefile.close()
s.say(_("The score has been reset."), 1)
#define menus
#define main menu
start = menu.menuitem(_("Start the game"), game.startgame, [5, 3])
testspeakers = menu.menuitem(_("Test your speakers"), stereoTestFunc)
viewscore = menu.menuitem(_("View your score"), genscoremenu, [0])
resetscore =menu.menuitem(_("Reset your score"), resetScoreFunc)
instructions = menu.menuitem(_("Read instructions"), readmanual)
quit = menu.menuitem(_("Quit the game"), quit)
main_menu = menu.menu(_("Welcome to the main menu. Use up and down arrows to select an item, enter to confirm and escape to quit."), [start, testspeakers, viewscore, resetscore, instructions, quit])
#define pause game prompt
continuegame = menu.menuitem(_("Continue the game"), resumegame)
abort = menu.menuitem(_("Abort the game and return to the main menu."), abortgame)
abortprompt = menu.menu(_("Do you really want to abort the game?"), [continuegame, abort])