Beispiel #1
0
def handle_status(config, args):
    if args['clear']:
        clear_status(config.slack, config.default_statuses, config.default_dnd)
    elif args['set']:
        try:
            status = config.statuses[args['<status>']]
        except KeyError:
            print(
                f'{args["<status>"]} is not a vaild status. Valid statuses are:'
            )
            print_statuses_list(config.statuses)
            exit(1)

        set_status(config.slack, status, args['<time>'])
    elif args['show']:
        if args['<status>'] is None:
            print(get_status(config.slack))
        else:
            try:
                print(config.statuses.get(args['<status>']))
            except KeyError:
                print(
                    f'{args["<status>"]} is not a vaild status. Valid statuses are:'
                )
                print_statuses_list(config.statuses)
                exit(1)

    elif args['list']:
        print_statuses_list(config.statuses)
Beispiel #2
0
def pop_default(config):
    try:
        config.default_statuses.pop()
    except IndexError:
        pass

    config.write_config()

    if len(config.default_statuses) > 0:
        set_status(config.slack, config.default_statuses[-1])
    else:
        clear_status(config.slack)
Beispiel #3
0
def close_game(game_id, db):
    player.clear_players(game_id, db)
    dice.clear_dice(game_id, db)
    status.clear_status(game_id, db)
Beispiel #4
0
def handle_keys (key):
    global turncount

    # Has a turn been accomplished?
    turn=False

    # Exit the game on escape.
    if libtcod.KEY_ESCAPE == key.vk:
        return True
    if P.player.health > 0:
        if ord('h') == key.c:
            P.player.move (-1, 0)
            turn = True
        elif ord('j') == key.c :
            P.player.move (0, 1)
            turn = True
        elif ord('k') == key.c :
            P.player.move (0, -1)
            turn = True
        elif ord('l') == key.c :
            P.player.move (1, 0)
            turn = True
        elif ord('y') == key.c :
            P.player.move (-1, -1)
            turn = True
        elif ord('u') == key.c :
            P.player.move (1, -1)
            turn = True
        elif ord('i') == key.c :
            P.player.move (-1, 1)
            turn = True
        elif ord('o') == key.c :
            P.player.move (1, 1)
            turn = True
        elif ord('c') == key.c :
            show_player_stats()
        elif ord(',') == key.c :
            P.player.pick_up()
        elif ord('.') == key.c :
            P.player.show_inventory()
        elif ord('d') == key.c :
            P.player.drop()
        elif ord('z') == key.c :
            P.player.shoot()
            turn = True
        if turn:
            # Move all enemies toward the player.
            characters = []
            for y in range (M.MAP_HEIGHT):
                for x in range (M.MAP_WIDTH):
                    for character in M.gameworld[x][y].characters:
                        characters.append(character)

            for character in characters:
                if character.npc and P.player.health > 0 and random.random() <= M.ZOMBIE_MOVE_CHANCE:
                    path = libtcod.path_new_using_map(P.player.fov)
                    # Compute the path between the hostile object and the player.
                    libtcod.path_compute(path, character.x, character.y,
                      P.player.x, P.player.y)
                    if libtcod.path_size(path) < 100:
                        libtcod.path_walk(path, True)
                        character.move_to_coordinates(libtcod.path_get_origin(path)[0],
                                libtcod.path_get_origin(path)[1])
            #spawn a new zombie
            if random.random() <= M.ENEMY_SPAWN_CHANCE:
                x,y=find_blind_open_tile()
                C.Character('Zombie',
                          random.randint(5,20),
                          x, y,
                          "Z",
                          libtcod.black,
                          npc=True)
                if random.random() <= 0.20:
                    Item ('cheap revolver', x, y, 'r', libtcod.red, gun=Gun(5, 0.6))
                    M.gameworld[x][y].characters[0].pick_up()
                if random.random() <= 0.02:
                    Item ('silver revolver', x, y, 'r', libtcod.cyan, gun=Gun(15, 0.9))
                    M.gameworld[x][y].characters[0].pick_up()
                if random.random() <= 0.10:
                    Item ('medkit', x, y, 'H', libtcod.red, health=Health(100))
                    M.gameworld[x][y].characters[0].pick_up()
            turncount = turncount + 1
            if P.player.health < P.player.max_health:
                P.player.health = P.player.health + 1
    ## Add items in the current tile to the status.
    # for item in M.gameworld[player.x][player.y].items:
    #       add_status("A %s."% (item.name))
    ## Add items in the current tile to the items indicator.
    add_items()
    # Render events.
    R.render()
    # Clear the status string.
    if turn:
        S.clear_status()
    # If there are items on the player's current tile, draw them to the screen.
    if items_here():
        draw_items()
    # Clear the list of current tile items.
    clear_items()
    # Return False if the game should still play.
    return False