def gamemenu(): # setting directory for stroing highscorelist / logfile #~ means home on linux . as first char will hide gamefolder = os.path.expanduser(os.path.join("~",".screensavertest")) gamefile = os.path.join(gamefolder, "highscorelist.txt") # do not name gamefile "file", that is a reserved word ! createGameDir(gamefolder) createGameFile(gamefile) # gamefile should now exist in gamefolder resolution = [640,480] fullscreen = False watched = 0 title = "please choose wisely:" buttons = ["watch screensaver", "change resolution", "toggle fullscreen", "view highscore","visit homepage", "quit"] #picture = None # gif file or make sure python-imaging-tk is installed correctly picture = "data/tux.gif" # ---- use pygame only to get a list of valid screen resolutions --- reslist = getPygameModes() # --- ask player name ---- playername = easygui.enterbox("What is you name?", "please enter you name and press ENTER or click ok", "Mister dunno") while True: #endless loop if fullscreen: msg2 = "fullscreen mode" else: msg2 = "window mode" msg = "Welcome at screensaver game menu.\nScreensaver will run with %ix%i resolution,\n%s" % (resolution[0], resolution[1], msg2) selection = easygui.buttonbox(msg, title, buttons, picture) if selection == "quit": easygui.msgbox("bye-bye", "such a sad decision...") break # leave loop elif selection == "visit homepage": print("i try to open the webbrowser, please wait a bit...") webbrowser.open_new_tab("http://www.thepythongamebook.com") elif selection == "toggle fullscreen": fullscreen = not fullscreen elif selection == "view highscore": text = readGameFile(gamefile) easygui.textbox("This is the Screensaver logfile", "displaying highscore", text) elif selection == "watch screensaver": watched += 1 # get return value from called pygame program (playtime) playtime = screensaver.screensaver(resolution, fullscreen) easygui.msgbox("You watched the scrensaver %i x using this game menu \nYour screen was saved for %.2f seconds" % (watched, playtime)) # writing highscore-list line = "date: %s player: %s playtime: %.2f seconds resolution: %ix%i fullscreen: %s \n" % (time.asctime(), playername, playtime, resolution[0], resolution[1], fullscreen) writeGameFile(gamefile, line) elif selection == "change resolution": answer = easygui.choicebox("Please select one of those screen resolutions", "x,y", reslist) # answer gives back a string like '(320, 200)' resolution = parse(answer) return
def gameRun(): """play a game/ watch the screensaver""" playtime = screensaver.screensaver(Config.resolution, Config.fullscreen, False) # the False avoid the screensaver to do pygame.quit() screen, background = repaint()
def gamemenu(): gamefolder = os.path.expanduser(os.path.join( "~", ".screensavertest")) # ~ means home on linux . as first char will hide gamefile = os.path.join( gamefolder, "highscorelist.txt" ) # do not call it "file", that is a reserved word ! if os.path.isdir(gamefolder): print "directory already exist" else: print "directory does not exist yet" try: os.mkdir(gamefolder) except: raise UserWarning, "error at creating directory %s" % gamefolder exit() if os.path.isfile(gamefile): print "highscore file aready exist" else: try: f = file(gamefile, "w") # open for writing f.write("--- screensaver logfile ---\n") f.close() except: raise UserWarning, "error while creating file %s" % gamefile exit() # gamefile should now exist in gamefolder resolution = [640, 480] fullscreen = False watched = 0 title = "please choose wisely:" buttons = [ "watch screensaver", "change resolution", "toggle fullscreen", "view highscore", "quit" ] #picture = None # gif file or make sure python-imaging-tk is installed correctly picture = "data/tux.gif" # ---- use pygame only to get a list of valid screen resolutions --- pygame.init() reslist = pygame.display.list_modes() pygame.quit() # ---- end of pygame ---------- # --- ask player name ---- playername = easygui.enterbox( "What is you name?", "please enter you name and press ENTER or click ok", "Mister dunno") while True: #endless loop if fullscreen: msg = "Welcome at screensaver game menu.\nScreensaver will run with %ix%i resolution,\nfullscreen mode" % ( resolution[0], resolution[1]) else: msg = "Welcome at screensaver game menu.\nScreensave will run with %ix%i resolution,\nwindow mode" % ( resolution[0], resolution[1]) selection = easygui.buttonbox(msg, title, buttons, picture) if selection == "quit": easygui.msgbox("bye-bye", "such a sad decision...") break # leave loop elif selection == "toggle fullscreen": fullscreen = not fullscreen elif selection == "view highscore": try: f = file(gamefile, "r") # read text = f.read() f.close() except: raise UserWarning, "Error while reading higscore file %s" % gamefile exit() easygui.textbox("This is the Screensaver logfile", "displaying highscore", text) elif selection == "watch screensaver": watched += 1 playtime = screensaver.screensaver(resolution, fullscreen) easygui.msgbox( "You watched the scrensaver %i x using this game menu \nYour screen was saved for %.2f seconds" % (watched, playtime)) # writing highscore-list try: f = file(gamefile, "a") # append f.write( "date: %s player: %s playtime: %.2f seconds resolution: %ix%i fullscreen: %s \n" % (time.asctime(), playername, playtime, resolution[0], resolution[1], fullscreen)) f.close() except: raise UserWarning, "Error while writing higscore file %s" % gamefile exit() elif selection == "change resolution": answer = easygui.choicebox( "Please select one of those screen resolutions", "x,y", reslist) # answer gives back a string like '(320, 200)' comma = answer.find(",") # position of the comma inside answer x = int(answer[1:comma]) y = int(answer[comma + 1:-1]) resolution = (x, y) return
def gameRun(): """play a game/ watch the screensaver""" playtime = screensaver.screensaver( Config.resolution, Config.fullscreen, False) # the False avoid the screensaver to do pygame.quit() screen, background = repaint()
def gamemenu(): gamefolder = os.path.expanduser(os.path.join("~",".screensavertest")) # ~ means home on linux . as first char will hide gamefile = os.path.join(gamefolder, "highscorelist.txt") # do not call it "file", that is a reserved word ! if os.path.isdir(gamefolder): print "directory already exist" else: print "directory does not exist yet" try: os.mkdir(gamefolder) except: raise UserWarning, "error at creating directory %s" % gamefolder exit() if os.path.isfile(gamefile): print "highscore file aready exist" else: try: f = file(gamefile, "w") # open for writing f.write("--- screensaver logfile ---\n") f.close() except: raise UserWarning, "error while creating file %s" % gamefile exit() # gamefile should now exist in gamefolder resolution = [640,480] fullscreen = False watched = 0 title = "please choose wisely:" buttons = ["watch screensaver", "change resolution", "toggle fullscreen", "view highscore", "quit"] #picture = None # gif file or make sure python-imaging-tk is installed correctly picture = "data/tux.gif" # ---- use pygame only to get a list of valid screen resolutions --- pygame.init() reslist = pygame.display.list_modes() pygame.quit() # ---- end of pygame ---------- # --- ask player name ---- playername = easygui.enterbox("What is you name?", "please enter you name and press ENTER or click ok", "Mister dunno") while True: #endless loop if fullscreen: msg = "Welcome at screensaver game menu.\nScreensaver will run with %ix%i resolution,\nfullscreen mode" % (resolution[0], resolution[1]) else: msg = "Welcome at screensaver game menu.\nScreensave will run with %ix%i resolution,\nwindow mode" % (resolution[0], resolution[1]) selection = easygui.buttonbox(msg, title, buttons, picture) if selection == "quit": easygui.msgbox("bye-bye", "such a sad decision...") break # leave loop elif selection == "toggle fullscreen": fullscreen = not fullscreen elif selection == "view highscore": try: f = file(gamefile, "r") # read text = f.read() f.close() except: raise UserWarning, "Error while reading higscore file %s" % gamefile exit() easygui.textbox("This is the Screensaver logfile", "displaying highscore", text) elif selection == "watch screensaver": watched += 1 playtime = screensaver.screensaver(resolution, fullscreen) easygui.msgbox("You watched the scrensaver %i x using this game menu \nYour screen was saved for %.2f seconds" % (watched, playtime)) # writing highscore-list try: f = file(gamefile, "a") # append f.write("date: %s player: %s playtime: %.2f seconds resolution: %ix%i fullscreen: %s \n" % (time.asctime(), playername, playtime, resolution[0], resolution[1], fullscreen)) f.close() except: raise UserWarning, "Error while writing higscore file %s" % gamefile exit() elif selection == "change resolution": answer = easygui.choicebox("Please select one of those screen resolutions", "x,y", reslist) # answer gives back a string like '(320, 200)' comma = answer.find(",") # position of the comma inside answer x = int(answer[1:comma]) y = int(answer[comma+1:-1]) resolution = (x,y) return