Ejemplo n.º 1
0
 def wall(self):
     """Start wall mode."""
     field.text.append("in wall()")
     # field.status("in wall()")
     # c = field.scr.getch()
     self.mode = 'wall'
     field.set(self.location, Item('wall'))
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
 def die(self):
     """Stop living."""
     self.alive = 0
     field.remove(self.loc, self)
     corpse = Item('corpse', level.last_index)
     level.last_index += 1
     field.set(self.loc, corpse)
     field.redraw(self.loc)
     if self in level.monsters:
         level.monsters.remove(self)
Ejemplo n.º 4
0
 def die(self):
     """Stop living."""
     self.alive = 0
     field.remove(self.loc, self)
     corpse = Item('corpse', level.last_index)
     level.last_index += 1
     field.set(self.loc, corpse)
     # field.redraw(self.loc)
     if self in level.monsters:
         level.monsters.remove(self)
Ejemplo n.º 5
0
    def move_to(self, loc):
        """ Move to location.
            Location is an (x, y) tuple.
        """

        move_result = None
        if loc != self.loc:
            move_result = field.set(loc, self)
            if move_result == 3:
                self.program = None
            if move_result in (1, 4):
                # redraw cell where we just were
                field.pop(self.loc)
                field.redraw(self.loc)

                # paint us on a new cell
                self.loc = loc
                field.scr.move(loc.y-1, loc.x-1)    # ??
                field.redraw(loc)

                # pick up items
                items = field[loc]
                being = level.hoplite if self.kind=="party" else self

                for item in items:

                    # pick up armor
                    if item.kind == 'armor':
                        if not self.armor or self.armor.defense >= item.defense:
                            being.inventory.append(self.armor)
                            being.armor = item
                            field.remove(loc, item)
                            field.text.append('%s picked up %s armor' % (being.kind, item.description))
                        self.program = None

                    # pick up weapons
                    elif item.kind == 'weapon':
                        if not self.weapon or self.weapon.attack >= item.attack:
                            being.inventory.append(self.weapon)
                            being.weapon = item
                            field.remove(loc, item)
                            field.text.append('%s picked up %s' % (being.kind, item.description))
                        self.program = None

                if len(items) > 1:
                    if any( [ i!=self or i.kind!="empty" for i in items ] ):
                        self.program = None

                field.display()
        return move_result
Ejemplo n.º 6
0
    def move_to(self, loc):
        """ Move to location.
            Location is an (x, y) tuple.
        """

        move_result = None
        if loc != self.loc:
            move_result = field.set(loc, self)
            if move_result == 3:
                self.program = None
            if move_result in (1, 4):
                # redraw cell where we just were
                field.pop(self.loc)
                # field.redraw(self.loc)

                # paint us on a new cell
                self.loc = loc
                field.scr.move(loc.y-1, loc.x-1)    # ??
                # field.redraw(loc)

                # pick up items
                items = field[loc]
                being = level.hoplite if self.kind=="party" else self

                for item in items:

                    # pick up armor
                    if item.kind == 'armor':
                        if not self.armor or self.armor.defense >= item.defense:
                            being.inventory.append(self.armor)
                            being.armor = item
                            field.remove(loc, item)
                            field.text.append('%s picked up %s armor' % (being.kind, item.description))
                        self.program = None

                    # pick up weapons
                    elif item.kind == 'weapon':
                        if not self.weapon or self.weapon.attack >= item.attack:
                            being.inventory.append(self.weapon)
                            being.weapon = item
                            field.remove(loc, item)
                            field.text.append('%s picked up %s' % (being.kind, item.description))
                        self.program = None

                if len(items) > 1:
                    if any( [ i!=self or i.kind!="empty" for i in items ] ):
                        self.program = None

                field.display()
        return move_result
Ejemplo n.º 7
0
    def populate(self, kind="random"):
        """Create monsters and place them on the level map."""

        self.num = levels.current
        # make monsters
        self.monsters = []
        # keep strategic view monsters when in tactical map
        # monster we are attacking now so that we can kill him in
        # strategic view if we kill him in tactical
        num_monsters = random.randrange(2, 6)
        if conf.xmax < 10: num_monsters = 1
        if conf.xmax < 2: num_monsters = 0
        monster_level = round(self.num * random.random() * 6)

        for i in range(num_monsters):
            if kind == "random" or random.random() > 0.75:
                b = being.rand()
            else:
                b = kind
            # log(b)
            m = being.Being(b, field.random(), self.last_index)
            self.last_index += 1
            m.place()
            m.team = 'monsters'
            # log(m.loc)
            self.monsters.append(m)
            # log(self.monsters)

        # make items
        #field.set(field.random(), Item('down'))
        num_items = int(round(self.num * random.random()))
        if conf.xmax < 10: num_items = 1
        if conf.xmax < 2: num_items = 0

        if num_items > 4:
            num_items = 4
        for i in range(num_items):
            if random.choice((0, 1)):
                field.set(field.random(),
                          weapon.Weapon(weapon.rand(), self.last_index))
            else:
                field.set(field.random(),
                          armor.Armor(armor.rand(), self.last_index))
            self.last_index += 1
        if conf.mode == "tactical":
            return

        # log("populate(): levels.current=%d, conf.levels: %d \n" % (levels.current, conf.levels))
        down, up = None, None
        if levels.current == 1:
            down = field.random()
            field.set(down, Item("down"))
        elif levels.current + 1 == conf.levels:
            up = field.random()
            field.set(up, Item("up"))
        else:
            up = field.random()
            down = field.random()
            field.set(down, Item("down"))
            field.set(up, Item("up"))
        self.down, self.up = down, up
Ejemplo n.º 8
0
    def populate(self, kind="random"):
        """Create monsters and place them on the level map."""

        self.num = levels.current
        # make monsters
        self.monsters = []
        # keep strategic view monsters when in tactical map
        # monster we are attacking now so that we can kill him in
        # strategic view if we kill him in tactical
        num_monsters = random.randrange(2,6)
        if conf.xmax < 10: num_monsters = 1
        if conf.xmax < 2: num_monsters = 0
        monster_level = round(self.num*random.random()*6)

        for i in range(num_monsters):
            if kind == "random" or random.random() > 0.75:
                b = being.rand()
            else:
                b = kind
            # log(b)
            m = being.Being(b, field.random(), self.last_index)
            self.last_index += 1
            m.place()
            m.team = 'monsters'
            # log(m.loc)
            self.monsters.append(m)
            # log(self.monsters)

        # make items
        #field.set(field.random(), Item('down'))
        num_items = int(round(self.num*random.random()))
        if conf.xmax < 10: num_items = 1
        if conf.xmax < 2: num_items = 0

        if num_items > 4:
            num_items = 4
        for i in range(num_items):
            if random.choice((0,1)):
                field.set(field.random(), weapon.Weapon(weapon.rand(), self.last_index))
            else:
                field.set(field.random(), armor.Armor(armor.rand(), self.last_index))
            self.last_index += 1
        if conf.mode == "tactical":
            return

        # log("populate(): levels.current=%d, conf.levels: %d \n" % (levels.current, conf.levels))
        down, up = None, None
        if levels.current == 1:
            down = field.random()
            field.set(down, Item("down"))
        elif levels.current+1 == conf.levels:
            up = field.random()
            field.set(up, Item("up"))
        else:
            up = field.random()
            down = field.random()
            field.set(down, Item("down"))
            field.set(up, Item("up"))
        self.down, self.up = down, up
Ejemplo n.º 9
0
 def place(self, loc=None):
     """Place me somewhere on the map.."""
     self.loc = loc or self.loc
     if self.loc:
         field.set(self.loc, self)
Ejemplo n.º 10
0
 def place(self, loc=None):
     """Place me somewhere on the map.."""
     self.loc = loc or self.loc
     if self.loc:
         field.set(self.loc, self)
Ejemplo n.º 11
0
 def vertice(self):
     """Add vertice."""
     field.set(self.location, Item('vertice'))