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 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()
except AtributeError, IndexError: lang = None if lang and (os.path.exists(os.path.normpath("lang/" + lang)) or os.path.exists(os.path.normpath("lang/" + lang.split("_")[0]))): lang = lang.split("_")[0] else: lang = "en" s = speech.Speaker(language=lang) #pass needed functions to menu module menu.s = s #menu._ = gettext.gettext #define menus #define main menu start = menu.menuitem(_("Start the game"), "__main__.g.startgame(5, 3)") instructions = menu.menuitem(_("Read instructions"), "__main__.readmanual()") quit = menu.menuitem(_("Quit the game"), "__main__.g.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, instructions, quit]) #define pause game prompt continuegame = menu.menuitem(_("Continue the game"), "__main__.g.resumegame()") abort = menu.menuitem(_("Abort the game and return to the main menu."), "__main__.g.abortgame()") abortprompt = menu.menu(_("Do you really want to abort the game?"), [continuegame, abort]) #channel initialisation pygame.mixer.set_reserved(2) chan = pygame.mixer.Channel(0)
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])
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])
lang=locale.getdefaultlocale()[0] except AtributeError, IndexError: lang=None if lang and (os.path.exists(os.path.normpath("lang/" + lang)) or os.path.exists(os.path.normpath("lang/" + lang.split("_")[0]))): lang=lang.split("_")[0] else: lang="en" s =speech.Speaker(language=lang) #pass needed functions to menu module menu.s = s #menu._ = gettext.gettext #define menus #define main menu start = menu.menuitem(_("Start the game"), "__main__.g.startgame(5, 3)") instructions = menu.menuitem(_("Read instructions"), "__main__.readmanual()") quit = menu.menuitem(_("Quit the game"), "__main__.g.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, instructions, quit]) #define pause game prompt continuegame = menu.menuitem(_("Continue the game"), "__main__.g.resumegame()") abort = menu.menuitem(_("Abort the game and return to the main menu."), "__main__.g.abortgame()") abortprompt = menu.menu(_("Do you really want to abort the game?"), [continuegame, abort]) #channel initialisation pygame.mixer.set_reserved(2) chan=pygame.mixer.Channel(0) mgchan = pygame.mixer.Channel(1)