Example #1
0
 def go(self, distance=99):
     """ Create a direction movement program.
         example: gk - go up until hit something.
     """
     field.status('g')
     c = field.scr.getch()
     if str(c) in conf.directions:
         self.program = (distance, c)
Example #2
0
 def go(self, distance=99):
     """ Create a direction movement program.
         example: gk - go up until hit something.
     """
     field.status('g')
     c = field.scr.getch()
     if str(c) in conf.directions:
         self.program = (distance, c)
Example #3
0
 def save(self):
     """Save current map."""
     field.status("Enter the name: ")
     curses.echo()
     name = field.scr.getstr().strip()
     curses.noecho()
     if name:
         self.maps[name] = field.fld
Example #4
0
 def move_program(self, count):
     """Create a program to move in given direction (count) times."""
     log("- - in move_program()")
     field.status(count)
     c = field.scr.getch()
     if 48 <= c <= 57:
         # example: 22l
         count = int('%d%d' % (count, c-48))
         field.status(count)
         c = field.scr.getch()
     if str(c) in conf.directions:
         self.program = (count, c)
Example #5
0
 def move_program(self, count):
     """Create a program to move in given direction (count) times."""
     # log("- - in move_program()")
     field.status(count)
     c = field.scr.getch()
     if 48 <= c <= 57:
         # example: 22l
         count = int('%d%d' % (count, c-48))
         field.status(count)
         c = field.scr.getch()
     if str(c) in conf.directions:
         self.program = (count, c)
Example #6
0
    def loop(self):
        """Main ui loop."""
        go = False  # program movement
        while 1:
            x = None
            if not go:
                c = field.scr.getch()
                field.status(c)
            if c in self.keymap:
                field.status("c is in keymap")
                self.commands[self.keymap[c]]()

            # g<dir>
            elif c == 103:
                go = 99
                c = field.scr.getch()
                continue

            # <num><dir>
            elif 48 <= c <= 57:
                go = c-48
                field.status(go)
                c = field.scr.getch()
                if 48 <= c <= 57:
                    go += int('%d%d' % (go, c-48))
                    c = field.scr.getch()
                continue

            # <dir>
            if str(c) in conf.directions:
                x,y = self.get_coords(c)
                #field.status('%d,%d' % (x,y))
                if x < 1 or x > conf.xmax:
                    go = False
                    continue
                elif y < 1 or y > conf.ymax:
                    go = False
                    continue

                self.location = x,y
                if self.mode == 'wall':
                    items = field[self.location]
                    put_wall = True
                    for item in items:
                        if item.kind == 'wall':
                            put_wall = False
                            break
                    if put_wall:
                        field.set(self.location, Item('wall'))
                if go:
                    go -= 1

            field.full_display()
            lx, ly = self.location
            field.status('%d,%d' % (lx,ly))
            field.msg()
            if x:
                field.scr.move(y-1,x-1)
                field.scr.refresh()
Example #7
0
 def load(self):
     """Load map."""
     field.status("Enter name of the map to load: ")
     curses.echo()
     name = field.scr.getstr().strip()
     curses.noecho()
     if name:
         if not self.maps.has_key(name):
             field.text = ["No such map found! (%s)" % name]
             field.msg()
             return
         field.fld = self.maps[name]
         self.location = 1,1
         field.scr.move(0,0)
         field.display()
Example #8
0
 def __init__(self, scr):
     """Initialize field, move cursor to start, load maps, show status,
     start loop."""
     field.init(scr)
     # blanking puts an empty item into each empty cell, this makes maps
     # file 2mb large
     field.blank()
     field.show_vertices = True
     # field module starts coordinations from 1, not 0
     self.location = 1,1
     self.mode = "move"
     #curses.curs_set(2)     # high cursor visibility
     field.scr.move(0,0)
     self.maps = shelve.open('maps')
     self.init_commands()
     field.status("Hit '?' for help.")