示例#1
0
    def draw(self, game: Game, extra_status=''):
        stdscr, pad = self.stdscr, self.pad

        def char(p, char, fgcolor):
            offset = Pt(1, 1)
            if game.in_bounds(p) and game.is_wrapped(p):
                bg_color = curses.COLOR_BLUE
            else:
                bg_color = curses.COLOR_BLACK
            p = p + offset
            pad.addstr(self.height - p.y + 1, p.x * 2, char + ' ',
                       colormapping[fgcolor, bg_color])

        bot = game.bots[(self.current - 1) % len(game.bots)]
        area = max(
            bot.pos.manhattan_dist(bot.pos + m) for m in bot.manipulator)

        for y in range(bot.pos.y - area, bot.pos.y + area + 1):
            for x in range(bot.pos.x - area, bot.pos.x + area + 1):
                p = Pt(x, y)
                if not game.in_bounds(p):
                    continue
                char(p, game.grid[p], FgColors.Dungeon)

        for b in game.boosters:
            char(b.pos, b.code, FgColors.Booster)

        for t in game.teleport_spots:
            char(t, '+', FgColors.Spot)

        for c in game.clone_spawn:
            char(c, 'X', FgColors.Spot)

        for b in game.bots:
            for m in bot.manipulator:
                w = b.pos + m
                if game.in_bounds(w) and geom.visible(game.grid, b.pos, w):
                    char(m, '*', FgColors.Manipulator)

        for b in game.bots:
            char(b.pos, '@', FgColors.InactivePlayer)

        char(game.bots[self.current].pos, '@', FgColors.Player)

        offset = self.screen_offset(game.size(), bot.pos)
        pad.refresh(offset.y, offset.x, 0, 0, curses.LINES - 2,
                    curses.COLS - 1)

        if self.last_error:
            status_line = self.last_error.ljust(curses.COLS)[:curses.COLS - 1]
            self.last_error = ''
            stdscr.addstr(
                curses.LINES - 1, 0, status_line,
                colormapping[curses.COLOR_YELLOW | BRIGHT, curses.COLOR_RED])
        else:
            status_line = f'turn={game.turn} ' + \
                          f'pos=({bot.pos.x}, {bot.pos.y}) ' + \
                          f'unwrapped={game.remaining_unwrapped} '
            status_line += ' '.join(f'{b}={game.inventory[b]}'
                                    for b in Booster.PICKABLE)

            if game.bots[self.current].wheels_timer:
                status_line += f' WHEELS({game.bots[self.current].wheels_timer})'

            if game.bots[self.current].drill_timer:
                status_line += f' DRILL({game.bots[self.current].drill_timer})'

            if extra_status:
                status_line += ' '
                status_line += extra_status
            # LMAO: "It looks like simply writing the last character of a window is impossible with curses, for historical reasons."
            status_line = status_line.ljust(curses.COLS)[:curses.COLS - 1]
            stdscr.addstr(
                curses.LINES - 1, 0, status_line,
                colormapping[curses.COLOR_YELLOW | BRIGHT, curses.COLOR_BLUE])

        stdscr.refresh()