示例#1
0
class Editor(object):
    def __init__(self, stdscr):
        # Set member values
        self.screen = stdscr
        self.height, self.width = self.screen.getmaxyx()
        self.file = text.TextFile("cursor.py")
        self.quit = False
        self.cursor = Cursor(self.file)
        self.status = ""

        # Set curses to non-blocking input
        self.screen.nodelay(True)
        self.screen.timeout(0)

    def update_state(self):
        c = self.screen.getch()
        if c == -1: return
        if c == curses.KEY_LEFT: self.cursor.left()
        if c == curses.KEY_RIGHT: self.cursor.right()
        if c == curses.KEY_UP: self.cursor.up()
        if c == curses.KEY_DOWN: self.cursor.down()
        if c == ord('q'): self.quit = True
        if c == ord('o'): self.status = TextObject.word().at(self.cursor).text
        if c == ord('l'): self.status = self.file.line(self.cursor.y)
        if c == ord('c'): self.status = self.cursor.at
        if c == ord('p'): self.cursor.push()
        if c == ord('P'): self.cursor.pop()
        if c == ord('w'): self.cursor.next_space()
        if c == ord('W'): self.cursor.prev_space()
        if c == ord('a'): self.cursor.next_letter()
        if c == ord('A'): self.cursor.prev_letter()
        if c == ord('s'): self.cursor.next_symbol()
        if c == ord('S'): self.cursor.prev_symbol()
        if c == ord('d'): self.cursor.next_digit()
        if c == ord('D'): self.cursor.prev_digit()

    def update_screen(self):
        for r in range(self.height - 1):
            self.screen.addstr(r, 0, self.file.line(r)[:self.width - 1])
        clean_status = ('<' + self.status + '>').replace(
            "\n", "\\n").ljust(self.width - 1)
        self.screen.addstr(self.height - 1, 0, clean_status, curses.A_REVERSE)
        self.screen.move(self.cursor.y, self.cursor.x)
        self.screen.refresh()

    @property
    def finished(self):
        return self.quit
示例#2
0
                    moving = True
                
            else:
                playerTurn = True
                for unit in playerUnits:
                    unit.active = True
                for unit in currentMap.enemyUnits:
                    activeEnemyUnits.append(unit)
        

        ## menu and cursor controls 
        ## if keys (they are up here because you should be able to hold the key)
        elif playerTurn and not (currentState in  [states.selectingAction, states.selectingAttack, states.selectingItems, states.selectingWeapon, states.attacking]):
            # cursor controls
            if keys[pygame.K_DOWN]:
                yCamera += mainCursor.down(yCamera)
                checkMapUI()
            if keys[pygame.K_UP]:
                yCamera += mainCursor.up(yCamera)
                checkMapUI()
            if keys[pygame.K_RIGHT]:
                xCamera += mainCursor.right(xCamera)
                checkMapUI()
            if keys[pygame.K_LEFT]:
                xCamera += mainCursor.left(xCamera)
                checkMapUI()
            # end cursor controls

        # menu movement controls
        elif playerTurn and currentState == states.selectingAction:
            if keys[pygame.K_DOWN]: