def process_events(self): """Handle any events that may have accumulated in pygame's event queue""" for event in pygame.event.get(): # process mouse events if event.type == MOUSEBUTTONDOWN: singleton_grid.mouse_click(event.pos) singleton_interface.mouse_press(event.pos) # process key events elif event.type == KEYDOWN: if event.key == K_F4 and (get_mods() & KMOD_ALT): sys.exit(0) elif event.key == K_ESCAPE: singleton_interface.set_mode(interface.NORMAL) elif event.key == K_2 and (get_mods() & KMOD_SHIFT): try: code = get_input("Enter some code to execute.") exec(code) except Exception as e: show_message(str(e)) # process exit signals elif event.type == QUIT: pygame.quit() sys.exit(0)
def activate(self): ''' When the save button is clicked, bring up a menu to save the level.''' name = get_input("What should this saved game be called? (You may want to use your first name.)") if name.strip() == '': return path = get_save_path(name) with open(path, 'w') as f: f.write(str(level.current_level)) f.close()
def activate(self): ''' When the load button is pressed, get a filename and then jump to the level given in the file.''' name = get_input("Enter the name of the saved game.") if name.strip() == '': return path = get_save_path(name) try: with open(path, 'r') as f: saved_level = int(f.read()) level.current_level = saved_level level.levels[level.current_level].begin() except IOError: show_message("No save file with that name was found.")