def orb_turn(self, activity):
     self.turn_counter += 1
     if self.turn_counter == 8:
         activity.mark(
             l=self,
             s='last turn, quitting')
         log('quitting')
         raise SolentQuitException()
示例#2
0
 def orb_turn(self, activity):
     events = sdl2.ext.get_events()
     if events:
         activity.mark(l=self, s='sdl2 event(s)')
     for event in events:
         if event.type == sdl2.SDL_QUIT:
             raise SolentQuitException()
         elif event.type == sdl2.SDL_KEYDOWN:
             if event.key.keysym.sym == sdl2.SDLK_UP:
                 self.ent_player_b.velocity.vy = -3
             elif event.key.keysym.sym == sdl2.SDLK_DOWN:
                 self.ent_player_b.velocity.vy = 3
             elif event.key.keysym.sym == ord('\\'):
                 raise SolentQuitException()
         elif event.type == sdl2.SDL_KEYUP:
             if event.key.keysym.sym in (sdl2.SDLK_UP, sdl2.SDLK_DOWN):
                 self.ent_player_b.velocity.vy = 0
     self.sdl_world.process()
示例#3
0
 def cb_line_console_command(self, cs_line_console_command):
     rail_h = cs_line_console_command.rail_h
     tokens = cs_line_console_command.tokens
     #
     cmd = tokens[0]
     rest = tokens[1:]
     if cmd == 'q':
         raise SolentQuitException()
     else:
         self.rail_line_console.send('  ??\r\n')
示例#4
0
def event_loop(console):
    cgrid = Cgrid(
        width=console.width,
        height=console.height)
    cgrid.put(
        drop=console.height-3,
        rest=1,
        s='(Escape to quit)',
        cpair=solent_cpair('white'))
    for (idx, (cpair, name)) in enumerate(solent_cpair_pairs()):
        cgrid.put(
            drop=(5+int(idx/4)),
            rest=(2+int(18*(idx%4))),
            s='%s %s'%(name, cpair),
            cpair=cpair)
    console.screen_update(
        cgrid=cgrid)
    #
    t = 0
    while True:
        keycode = console.async_get_keycode()
        if keycode != None:
            if keycode == solent_keycode('esc'):
                raise SolentQuitException()
            cgrid.put(
                drop=3,
                rest=1,
                s='key %s (%s)  '%(hex(keycode), chr(keycode)),
                cpair=solent_cpair('red'))
        else:
            time.sleep(0.05)
        cgrid.put(
            drop=1,
            rest=1,
            s='loop counter: %s'%(t),
            cpair=solent_cpair('green'))
        console.screen_update(
            cgrid=cgrid)
        t += 1
示例#5
0
 def async_get_keycode(self):
     for itm in pygame.event.get():
         self.event_queue.append(itm)
     # The reason this is a while loop is to get through event characters
     # we don't care about. i.e. it's a different reason for a while loop
     # in the same position in block_get_keycode. (At first glance, it
     # looks trivial to merge them, but it's not)
     while True:
         if not self.event_queue:
             return None
         ev = self.event_queue.popleft()
         if ev.type == pygame.QUIT:
             raise SolentQuitException()
         if ev.type == pygame.MOUSEBUTTONDOWN:
             (xpos, ypos) = ev.pos
             if ev.button == 1:
                 self.last_lmousedown = self.grid_display.coords_from_mousepos(
                     xpos=xpos, ypos=ypos)
                 return solent_keycode('lmousedown')
             if ev.button == 3:
                 self.last_rmousedown = self.grid_display.coords_from_mousepos(
                     xpos=xpos, ypos=ypos)
                 return solent_keycode('rmousedown')
         if ev.type == pygame.MOUSEBUTTONUP:
             (xpos, ypos) = ev.pos
             if ev.button == 1:
                 self.last_lmouseup = self.grid_display.coords_from_mousepos(
                     xpos=xpos, ypos=ypos)
                 return solent_keycode('lmouseup')
             if ev.button == 3:
                 self.last_rmouseup = self.grid_display.coords_from_mousepos(
                     xpos=xpos, ypos=ypos)
                 return solent_keycode('rmouseup')
         if not ev.type == pygame.KEYDOWN:
             continue
         #
         c = _sanitise_input(u=ev.unicode)
         return c
示例#6
0
 def _received_keycode(self, keycode):
     if keycode in QUIT_KEYCODES:
         raise SolentQuitException()
     #
     if None == self.rail_line_finder:
         return
     #
     cpair = solent_cpair('orange')
     # This backspace mechanism is far from perfect.
     if keycode == solent_keycode('backspace'):
         self.rail_line_finder.backspace()
         s = self.rail_line_finder.get()
         idx = len(s) % CONSOLE_WIDTH
         s = s[-1 * idx:]
         self.spin_term.write(drop=self.drop,
                              rest=0,
                              s='%s ' % s,
                              cpair=cpair)
         self.rest = len(s)
     else:
         self.rail_line_finder.accept_bytes([keycode])
         self._print(keycode=keycode, cpair=cpair)
     self.spin_term.refresh_console()
示例#7
0
 def block_get_keycode(self):
     while True:
         if self.event_queue:
             ev = self.event_queue.popleft()
         else:
             ev = pygame.event.wait()
         #
         if ev.type == pygame.QUIT:
             raise SolentQuitException()
         if ev.type == pygame.MOUSEBUTTONDOWN:
             (xpos, ypos) = ev.pos
             self.last_mousedown = self.grid_display.coords_from_mousepos(
                 xpos=xpos, ypos=ypos)
             return solent_keycode('mousedown')
         if ev.type == pygame.MOUSEBUTTONUP:
             (xpos, ypos) = ev.pos
             self.last_mouseup = self.grid_display.coords_from_mousepos(
                 xpos=xpos, ypos=ypos)
             return solent_keycode('mouseup')
         if not ev.type == pygame.KEYDOWN:
             continue
         #
         c = _sanitise_input(u=ev.unicode)
         return c
示例#8
0
 def on_exit(self):
     log('exit')
     raise SolentQuitException()
示例#9
0
 def cb_windows_event_quit(self, cs_windows_event_quit):
     zero_h = cs_windows_event_quit.zero_h
     #
     raise SolentQuitException()
示例#10
0
 def on_cmd_quit(self, accept_sid):
     raise SolentQuitException()
示例#11
0
 def on_exit(self, yn_success):
     if yn_success == 'y':
         raise SolentQuitException()
     else:
         raise Exception("Failed lookup")
示例#12
0
 def on_keystroke(self, keycode):
     log('key received %s'%keycode)
     if keycode == ord('Q'):
         raise SolentQuitException()
示例#13
0
 def on_grid_kevent(self, keycode):
     log('received keycode |%s| {%s}' % (keycode, e_keycode(keycode)))
     #
     if keycode == e_keycode.Q:
         raise SolentQuitException()
     elif keycode == e_keycode.h:
         shape_mob = self.track_mob.player
         mob_h = shape_mob.mob_h
         mtype = shape_mob.mtype
         drop = shape_mob.drop
         rest = shape_mob.rest - 1
         c = shape_mob.c
         cpair = shape_mob.cpair
         self.nearcast.mob_set(mob_h=mob_h,
                               mtype=mtype,
                               drop=drop,
                               rest=rest,
                               c=c,
                               cpair=cpair)
     elif keycode == e_keycode.j:
         shape_mob = self.track_mob.player
         mob_h = shape_mob.mob_h
         mtype = shape_mob.mtype
         drop = shape_mob.drop + 1
         rest = shape_mob.rest
         c = shape_mob.c
         cpair = shape_mob.cpair
         self.nearcast.mob_set(mob_h=mob_h,
                               mtype=mtype,
                               drop=drop,
                               rest=rest,
                               c=c,
                               cpair=cpair)
     elif keycode == e_keycode.k:
         shape_mob = self.track_mob.player
         mob_h = shape_mob.mob_h
         mtype = shape_mob.mtype
         drop = shape_mob.drop - 1
         rest = shape_mob.rest
         c = shape_mob.c
         cpair = shape_mob.cpair
         self.nearcast.mob_set(mob_h=mob_h,
                               mtype=mtype,
                               drop=drop,
                               rest=rest,
                               c=c,
                               cpair=cpair)
     elif keycode == e_keycode.l:
         shape_mob = self.track_mob.player
         mob_h = shape_mob.mob_h
         mtype = shape_mob.mtype
         drop = shape_mob.drop
         rest = shape_mob.rest + 1
         c = shape_mob.c
         cpair = shape_mob.cpair
         self.nearcast.mob_set(mob_h=mob_h,
                               mtype=mtype,
                               drop=drop,
                               rest=rest,
                               c=c,
                               cpair=cpair)
     #
     self.nearcast.render()
示例#14
0
 def mi_quit():
     raise SolentQuitException()
 def on_cmd_quit(self):
     raise SolentQuitException()
示例#16
0
 def on_quit(self):
     raise SolentQuitException('Quit message on stream')
示例#17
0
 def _mi_quit(self):
     raise SolentQuitException()
示例#18
0
 def on_splat(self, zero_h, msg):
     log('[%s] %s' % (zero_h, msg))
     raise SolentQuitException()