Esempio n. 1
0
def handle_keys(level):
    user_input = get_user_input()
    if user_input == "FULLSCREEN":
        toggle_fullscreen()
    elif user_input == "ESCAPE":
        return "EXIT"
    elif (user_input == "TAKE_STAIRS_DOWN"
          and not level.player.has_amulet_of_yendor
          and same_location(level.player.location, level.stairs.location)):
        return "NEXT_LEVEL"
    elif (user_input == "TAKE_STAIRS_UP" and level.player.has_amulet_of_yendor
          and same_location(level.player.location, level.stairs.location)):
        return "NEXT_LEVEL"
    return run_move_logic(level, user_input)
Esempio n. 2
0
def search(level):
    if randint(1, 5) == 1:
        for tile in adjacent_tiles(level.player.location, level):
            if tile.hidden:
                tile.hidden = False
                tile.walkable = True
            hidden_monsters = [m for m in level.monsters if "H" in m.flags
                               and same_location(tile.location, m.location)]
            for hm in hidden_monsters:
                hm.flags = hm.flags.replace("H", "")
            traps = [t for t in level.traps if same_location(t.location,
                                                             tile.location)]
            for trap in traps:
                trap.found = True
        level.map_grid.update_c_map()
Esempio n. 3
0
def pickup(player, item):
    if same_location(player.location, item.location):
        if is_amulet(item):
            player.has_amulet_of_yendor = True
            message("Rogue picked up The Amulet Of Yendor")
            return
        if is_scare_monster(item):
            if item.used_up:
                message("The scroll crumbles away to nothing")
                return
            else:
                item.used_up = True
        # See if existing location
        existing = [l for l, i in player.inventory.items()
                    if i is not None and i.item.name == item.name]
        for e in existing:
            if not player.inventory[e].full:
                more_items(item, player.inventory, e)
                item.picked_up = True
                message("Rogue picked up {} ({})".format(item.name, e))
                return
        # Or add to new slot
        spaces = [l for l, i in player.inventory.items() if i is None]
        overburdened = sum([i.weight for i in player.inventory.values()
                            if i is not None]) >= player.inventory_limit
        if len(spaces) > 0 and not overburdened:
            player.inventory[spaces[0]] = make_inventory_item(item)
            item.picked_up = True
            item.found = False
            if is_amulet(item):
                player.has_amulet_of_yendor = True
            message("Rogue picked up {} ({})".format(item.name, spaces[0]))
        else:
            message("Inventory is full, moved onto {}".format(item.name))
Esempio n. 4
0
def triggertrap(level):
    traps = [
        trap for trap in level.traps
        if same_location(level.player.location, trap.location)
    ]
    for trap in traps:
        trap.found = True
        return trap.function(level)
Esempio n. 5
0
def blind_draw_map(level):
    for tile in chain(*level.map_grid.tiles):
        if not in_fov(tile.location, level):
            tile.explored = False
        elif same_location(level.player.location, tile.location):
            tile.explored = True
        if tile.explored:
            tcod.console_put_char_ex(con, tile.location.x, tile.location.y,
                                     tile_char(level, tile.location),
                                     tcod.color.black,
                                     tile_colour(level, "DARK", tile.location))
Esempio n. 6
0
def find_target(direction, dist, level):
    x, y = level.player.location
    dx, dy = movements[direction]
    for _ in range(dist):
        new_location = Location(x + dx, y + dy)
        if not is_walkable(new_location, level):
            return Location(x, y)
        monsters = [m for m in level.monsters
                    if same_location(m.location, new_location)]
        if len(monsters) > 0:
            return monsters[0]
        x += dx
        y += dy
    return new_location
Esempio n. 7
0
def autopickup(level):
    itms = [item for item in level.items
            if same_location(level.player.location, item.location)]
    for itm in itms:
        pickup(level.player, itm)