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 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.")
class EventManager:

    @staticmethod
    def dispatch(event):
		if event['event'] == 1:
            answer = print_face(event['payload'])
        elif event['event'] == 2:
            show_message(event['payload'])
            answer = 1
Beispiel #4
0
 def cmd_show(self, args):
     'usage: show [-q] [-l)ist] [-a)ll] [-h)eaders] [-c charset] [-P)rev|-N)ext] msg:part ...'
     try:
         (opts, args) = getopt(args, 'qlahc:PN')
     except GetoptError:
         raise Kernel.ShowUsage()
     #
     verbose = 1
     dolist = False
     showall = False
     headerlevel = 1
     charset = None
     rel = 0
     for (k, v) in opts:
         if k == '-q': verbose = 0
         elif k == '-l': dolist = True
         elif k == '-a': showall = True
         elif k == '-h': headerlevel = 2
         elif k == '-c': charset = v
         elif k == '-P': rel = -1
         elif k == '-N': rel = +1
     #
     (docs, args) = self.get_messages(args or ['.'], rel)
     if args:
         self.terminal.warning('Arguments ignored: %r' % args)
     for (i, doc, part) in docs:
         if dolist:
             message.show_digest(self.terminal, i, False, doc,
                                 self.get_selection(), doc.get_labels())
             continue
         if part == None:
             message.show_message(self.terminal, i, doc,
                                  self.get_selection(), showall, showall,
                                  headerlevel, verbose)
             continue
         try:
             message.show_mime_part(self.terminal, doc.get_msg(0), part,
                                    headerlevel, charset)
         except MessagePartNotFoundError:
             raise Kernel.ValueError('Message part not found.')
     return
Beispiel #5
0
 def cmd_show(self, args):
   'usage: show [-q] [-l)ist] [-a)ll] [-h)eaders] [-c charset] [-P)rev|-N)ext] msg:part ...'
   try:
     (opts, args) = getopt(args, 'qlahc:PN')
   except GetoptError:
     raise Kernel.ShowUsage()
   #
   verbose = 1
   dolist = False
   showall = False
   headerlevel = 1
   charset = None
   rel = 0
   for (k,v) in opts:
     if k == '-q': verbose = 0
     elif k == '-l': dolist = True
     elif k == '-a': showall = True
     elif k == '-h': headerlevel = 2
     elif k == '-c': charset = v
     elif k == '-P': rel = -1
     elif k == '-N': rel = +1
   #
   (docs, args) = self.get_messages(args or ['.'], rel)
   if args:
     self.terminal.warning('Arguments ignored: %r' % args)
   for (i,doc,part) in docs:
     if dolist:
       message.show_digest(self.terminal, i, False,
                           doc, self.get_selection(), doc.get_labels())
       continue
     if part == None:
       message.show_message(self.terminal, i, doc, self.get_selection(),
                            showall, showall, headerlevel, verbose)
       continue
     try:
       message.show_mime_part(self.terminal, doc.get_msg(0),
                              part, headerlevel, charset)
     except MessagePartNotFoundError:
       raise Kernel.ValueError('Message part not found.')
   return
Beispiel #6
0
    def update(self):
        from resource import singleton_resource

        global current_level
        # Check if victory condition has been met
        bool0 = singleton_resource.get_total_workers() >= self.population_goal
        bool1 = singleton_resource.get("Gold") >= self.gold_goal
        if bool0 and bool1:
            try:
                current_level += 1
                levels[current_level].begin()
                show_message("You have conquered this level! Next is level {0}.".format(current_level + 1))
            except IndexError:
                show_message("You have beaten each level in the game! We will now take you back to the first level.")
                current_level = 0
                levels[current_level].begin()

        # Check if player has run out of time
        self.time_remaining -= 0.01
        if self.time_remaining <= 0:
            # Restart the current level
            show_message("Oh no, you have run out of time!")
            levels[current_level].begin()