Exemple #1
0
    def _status_box(self):
        """
        Create the pane with information about the player's current state.
        """

        default = "(none)"

        status_frame = curses.newwin(
            self._height(), 
            self.status_width, 
            self._top(), 
            self.level_width - 1
        )

        status_frame.erase()
        status_frame.border("|", "|", "-", " ", "+", "+", "|", "|")
        status_frame.addstr(0, 2, " status ")
        status_frame.chgat(0, 2, len(" status "), get_color(curses.COLOR_CYAN))
        statuses = self._get_statuses()
        for row, stat in enumerate(statuses, 1):
            attrs = []
            if status.type_of(stat) == "bad":
                attrs += [get_color(curses.COLOR_RED)]

            attrs = reduce(lambda a, b: a | b, attrs, 0)
            status_frame.addnstr(row, 1, stat, self.status_width-2, attrs)

        if len(statuses) == 0:
            center = (self.status_width / 2) - (len(default) / 2)
            status_frame.addstr(1, center, default)

        return status_frame
Exemple #2
0
    def _redraw_row(self, window, row):
        """
        Draw a single game-row in the curses display window. This means writing
        the text from the in-memory terminal out and setting the color/style
        attributes appropriately.
        """
        row_c = self.term.display[row].encode(self.code)
        window.addstr(row, 0, row_c)

        row_a = self.term.attributes[row]
        for col, (char_style, foreground, background) in enumerate(row_a): 
            char_style = set(char_style)
            foreground = colors.get(foreground, -1)
            background = colors.get(background, -1)
            char_style = [styles.get(s, curses.A_NORMAL) for s in char_style]
            attrs = char_style + [get_color(foreground, background)]
            window.chgat(row, col, 1, reduce(lambda a, b: a | b, attrs)) 

        if "HP:" in row_c:
            # Highlight health depending on much much is left.
            match = re.search("HP:(\\d+)\\((\\d+)\\)", row_c)
            if match is not None:
                hp, hp_max = match.groups()
                ratio = float(hp) / float(hp_max)

                if ratio <= 0.25:
                    attrs = [curses.A_BOLD, get_color(curses.COLOR_WHITE, curses.COLOR_RED)]
                elif ratio <= 0.5:
                    attrs = [curses.A_BOLD, get_color(curses.COLOR_YELLOW)]
                else:
                    attrs = [curses.A_BOLD, get_color(curses.COLOR_GREEN)]
                attrs = reduce(lambda a, b: a | b, attrs)
                window.chgat(row, match.start() + 3, match.end() - match.start() - 3, attrs)
Exemple #3
0
    def _status_box(self):
        """
        Create the pane with information about the player's current state.
        """

        default = "(none)"

        status_frame = curses.newwin(self._height(), self.status_width,
                                     self._top(), self.level_width - 1)

        status_frame.erase()
        status_frame.border("|", "|", "-", " ", "+", "+", "|", "|")
        status_frame.addstr(0, 2, " status ")
        status_frame.chgat(0, 2, len(" status "), get_color(curses.COLOR_CYAN))
        statuses = self._get_statuses()
        for row, stat in enumerate(statuses, 1):
            attrs = []
            if status.type_of(stat) == "bad":
                attrs += [get_color(curses.COLOR_RED)]

            attrs = reduce(lambda a, b: a | b, attrs, 0)
            status_frame.addnstr(row, 1, stat, self.status_width - 2, attrs)

        if len(statuses) == 0:
            center = (self.status_width / 2) - (len(default) / 2)
            status_frame.addstr(1, center, default)

        return status_frame
Exemple #4
0
    def _identify_box(self, items):
        """
        Create the pain with information about price identifying something.
        """

        items = sorted(items, lambda a, b: cmp(b[2], a[2]))
        total_chance = sum(float(i[2]) for i in items)
        items = [(i[0], i[1], (i[2] / total_chance) * 100.) for i in items]
        items = [("%s" % i[0], "%0.2f%%" % float(i[2])) for i in items]
        if len(items) == 0:
            items = set([("(huh... can't identify)", "100%")])

        width = 2 + max([len(i[0]) + len(i[1]) + 4 for i in items])

        identify_frame = curses.newwin(len(items) + 1, width, 1, 0)
        identify_frame.border("|", "|", " ", "-", "|", "|", "+", "+")
        identify_frame.addstr(len(items), 2, " identify ")
        identify_frame.chgat(len(items), 2, len(" identify "),
                             get_color(curses.COLOR_CYAN))

        for row, item in enumerate(items):
            identify_frame.addstr(row, 2, item[0])
            identify_frame.addstr(row, width - len(item[1]) - 2, item[1])

        return identify_frame
Exemple #5
0
 def _write_attrs(self, window, row):
     row_a = self.term.attributes[row]
     for col, (char_style, foreground, background) in enumerate(row_a):
         char_style = set(char_style)
         foreground = colors.get(foreground, -1)
         background = colors.get(background, -1)
         char_style = [styles.get(s, curses.A_NORMAL) for s in char_style]
         attrs = char_style + [get_color(foreground, background)]
         window.chgat(row, col, 1, reduce(lambda a, b: a | b, attrs)) 
Exemple #6
0
    def _intrinsic_box(self):
        """
        Create the pane with information with the player's current intrinsics.
        """

        default = "(none)"

        def res_color(res):
            """Return the color of a intrinsic."""
            if res == "fire": 
                return curses.COLOR_RED
            elif res == "cold": 
                return curses.COLOR_BLUE 
            elif res == "poison": 
                return curses.COLOR_GREEN
            elif res == "disintegration": 
                return curses.COLOR_YELLOW
            else: 
                return -1

        res_frame = curses.newwin(
            self._height(), 
            self.intrinsic_width, 
            self._top(), 
            self.level_width + self.status_width - 2
        )

        res_frame.erase()
        res_frame.border("|", "|", "-", " ", "+", "+", "|", "|")
        res_frame.addstr(0, 2, " intrinsic ")
        res_frame.chgat(0, 2, len(" intrinsic "), get_color(curses.COLOR_CYAN))
        intrinsics = sorted(self.player.intrinsics)
        for row, res in enumerate(intrinsics, 1):
            color = get_color(res_color(res))
            res_frame.addnstr(row, 1, res, self.intrinsic_width-2)
            res_frame.chgat(row, 1, min(len(res), self.intrinsic_width-2), color)

        if len(intrinsics) == 0:
            center = (self.intrinsic_width / 2) - (len(default) / 2)
            res_frame.addstr(1, center, default)

        return res_frame
Exemple #7
0
    def _intrinsic_box(self):
        """
        Create the pane with information with the player's current intrinsics.
        """

        default = "(none)"

        def res_color(res):
            """Return the color of a intrinsic."""
            if res == "fire":
                return curses.COLOR_RED
            elif res == "cold":
                return curses.COLOR_BLUE
            elif res == "poison":
                return curses.COLOR_GREEN
            elif res == "disintegration":
                return curses.COLOR_YELLOW
            else:
                return -1

        res_frame = curses.newwin(self._height(), self.intrinsic_width,
                                  self._top(),
                                  self.level_width + self.status_width - 2)

        res_frame.erase()
        res_frame.border("|", "|", "-", " ", "+", "+", "|", "|")
        res_frame.addstr(0, 2, " intrinsic ")
        res_frame.chgat(0, 2, len(" intrinsic "), get_color(curses.COLOR_CYAN))
        intrinsics = sorted(self.player.intrinsics)
        for row, res in enumerate(intrinsics, 1):
            color = get_color(res_color(res))
            res_frame.addnstr(row, 1, res, self.intrinsic_width - 2)
            res_frame.chgat(row, 1, min(len(res), self.intrinsic_width - 2),
                            color)

        if len(intrinsics) == 0:
            center = (self.intrinsic_width / 2) - (len(default) / 2)
            res_frame.addstr(1, center, default)

        return res_frame
Exemple #8
0
    def _breadcrumbs(self, window):
        breadcrumbs = self.dungeon.current_level().breadcrumbs

        for crumb in breadcrumbs:
            x, y = crumb
            if self.manager.char_at(x, y) not in [".", "#", " "]: 
                # Ignore anything that's not something we can step on.
                continue

            if self.manager.char_at(x, y) == " ":
                window.addch(y, x, ".")

            window.chgat(y, x, 1, curses.A_BOLD | get_color(curses.COLOR_MAGENTA))

        cur_x, cur_y = self.manager.term.cursor()
        window.move(cur_y, cur_x)
Exemple #9
0
    def _breadcrumbs(self, window):
        breadcrumbs = self.dungeon.current_level().breadcrumbs

        for crumb in breadcrumbs:
            x, y = crumb
            if self.manager.char_at(x, y) not in [".", "#", " "]:
                # Ignore anything that's not something we can step on.
                continue

            if self.manager.char_at(x, y) == " ":
                window.addch(y, x, ".")

            window.chgat(y, x, 1,
                         curses.A_BOLD | get_color(curses.COLOR_MAGENTA))

        cur_x, cur_y = self.manager.term.cursor()
        window.move(cur_y, cur_x)
Exemple #10
0
    def _level_box(self):
        """
        Create the pane with information about this dungeon level.
        """

        level = self.dungeon.current_level()
        default = "(none)"

        dungeon_frame = curses.newwin(
            self._height(), 
            self.level_width, 
            self._top(), 
            0
        )

        dungeon_frame.erase()
        dungeon_frame.border("|", "|", "-", " ", "+", "+", "|", "|")
        dungeon_frame.addstr(0, 2, " this level ")
        dungeon_frame.chgat(0, 2, len(" this level "), get_color(curses.COLOR_CYAN))

        features = sorted(level.features)
        row = 1
        i = 0
        while i < len(features):
            feature = features[i]
            dungeon_frame.addnstr(row, 1, feature, self.level_width-2)
            row += 1
            i += 1

            if feature == "shop":
                for shop in sorted(level.shops):
                    dungeon_frame.addnstr(row, 3, "* " + shop, self.level_width-5)
                    row += 1

        if len(features) == 0:
            center = (self.level_width / 2) - (len(default) / 2)
            dungeon_frame.addstr(1, center, default)

        return dungeon_frame
Exemple #11
0
    def _level_box(self):
        """
        Create the pane with information about this dungeon level.
        """

        level = self.dungeon.current_level()
        default = "(none)"

        dungeon_frame = curses.newwin(self._height(), self.level_width,
                                      self._top(), 0)

        dungeon_frame.erase()
        dungeon_frame.border("|", "|", "-", " ", "+", "+", "|", "|")
        dungeon_frame.addstr(0, 2, " this level ")
        dungeon_frame.chgat(0, 2, len(" this level "),
                            get_color(curses.COLOR_CYAN))

        features = sorted(level.features)
        row = 1
        i = 0
        while i < len(features):
            feature = features[i]
            dungeon_frame.addnstr(row, 1, feature, self.level_width - 2)
            row += 1
            i += 1

            if feature == "shop":
                for shop in sorted(level.shops):
                    dungeon_frame.addnstr(row, 3, "* " + shop,
                                          self.level_width - 5)
                    row += 1

        if len(features) == 0:
            center = (self.level_width / 2) - (len(default) / 2)
            dungeon_frame.addstr(1, center, default)

        return dungeon_frame
Exemple #12
0
    def _identify_box(self, items):
        """
        Create the pain with information about price identifying something.
        """

        items = sorted(items, lambda a, b: cmp(b[2], a[2]))
        total_chance = sum(float(i[2]) for i in items)
        items = [(i[0], i[1], (i[2] / total_chance) * 100.) for i in items]
        items = [("%s" % i[0], "%0.2f%%" % float(i[2])) for i in items]
        if len(items) == 0:
            items = set([("(huh... can't identify)", "100%")])

        width = 2 + max([len(i[0]) + len(i[1]) + 4 for i in items])

        identify_frame = curses.newwin(len(items) + 1, width, 1, 0)
        identify_frame.border("|", "|", " ", "-", "|", "|", "+", "+")
        identify_frame.addstr(len(items), 2, " identify ")
        identify_frame.chgat(len(items), 2, len(" identify "), get_color(curses.COLOR_CYAN))

        for row, item in enumerate(items):
            identify_frame.addstr(row, 2, item[0])
            identify_frame.addstr(row, width - len(item[1]) - 2, item[1])

        return identify_frame