Beispiel #1
0
def create_player(player_name = None, player_type = None):

    if player_name is None:
        print_slowly("Hello, what is your name?")
        player_name = input("> ")

    while player_type not in player_templates:
        print_slowly("What type of player are you?")
        player_type = input("{} > ".format(" -*- ".join(list(player_templates.keys()))))

    player = player_templates[player_type].copy()
    player['name'] = player_name
    # replace ac, strength, and hp with values
    set_stat(player, 'ac')
    set_stat(player, 'damage_die')
    set_stat(player, 'hp')
    return player
Beispiel #2
0
def print_situation():
    print("######################################")
    print_slowly(world[CURRENT_ROOM]['description'])
    print("")
    print_slowly("You see:")
    for item in world[CURRENT_ROOM]['items']:
        print_slowly("    " + item)

    exits = list(world[CURRENT_ROOM]['exits'].keys())

    print_slowly("exits: " + ", ".join(exits))
Beispiel #3
0
def command_go(to_room):
    global CURRENT_ROOM
    # is the destination room in the list of exists?
    if to_room in world[CURRENT_ROOM]['exits']:
        next_room = world[CURRENT_ROOM]['exits'][to_room]
        # check to make sure that we have any required items to use this exit
        for required_item in next_room['require']:
            if required_item not in player['inventory']:
                print_slowly("You do not have a " + required_item)
                return

        if len(world[to_room]['enemies']) == 0:
            # there are no enemies in the room
            # spawn some
            for enemy_type in world[to_room]['possible_enemies']:
                if random.randint(0, 100) < enemy_type['spawn_chance']:
                    print('spawned {}'.format(enemy_type['type']))
                    world[to_room]['enemies'].append(
                        create_enemy(enemy_type['type']))

        CURRENT_ROOM = to_room
    else:
        print_slowly("that isn't really an option")
Beispiel #4
0
def process_combat(player, enemy):
    print_slowly("A {} has appeared!  You must do battle!".format(enemy['name']))
    # determine the order that everyone attacks
    combat_list = determine_combat_order(player, enemy)

    while player['hp'] > 0 and enemy['hp'] > 0:
        for participant in combat_list:
            if participant['hp'] > 0:
                # player is alive
                if participant['type'] is 'player':
                    user_input = input("[attack|run] > ")
                    if user_input == 'attack':
                        process_attack(player, enemy)
                    elif user_input == 'run':
                        return "run"
                    else:
                        print("sorry, you can't do that")
                else:
                    process_attack(enemy, player)
        print("{} has {} hp remaining".format(player['name'], player['hp']))
        print("{} has {} hp remaining".format(enemy['name'], enemy['hp']))

    return 'complete'
Beispiel #5
0
def command_look(arg):
    if arg is None:
        # list the item descriptions
        print_slowly("what do you want to look at?")
    elif arg not in world[CURRENT_ROOM]['items']:
        print_slowly("I don't see one of those")
    else:
        item = items_list[arg]
        print_slowly(item['description'])
Beispiel #6
0
def process_attack(attacker, defender):
    if defender['hp'] <= 0:
        # defender is already dead
        return

    # get the ac from the defender
    ac = get_stat(defender, 'ac')

    if hit(ac):
        damage = 0
        num_damage_die = get_stat(attacker, 'damage_die')
        for die in range(0, num_damage_die):
            damage += random.randint(1, 6)
        print_slowly("{} attacks {} and deals {} damage!".format(attacker['name'], defender['name'], damage))
        defender['hp'] -= damage
        if defender['hp'] <= 0:
            defender['hp'] = 0
            print_slowly("{} died".format(defender['name']))
    else:
        print_slowly("{} attacks {} and misses".format(attacker['name'], defender['name']))
Beispiel #7
0
def command_pickup(item):
    if item in world[CURRENT_ROOM]['items']:
        give_item(item)
        world[CURRENT_ROOM]['items'].remove(item)
    else:
        print_slowly("I don't see a " + item)
Beispiel #8
0
def command_quit(arg):
    print_slowly("Abandon ye all hope, for you have quit...")
    exit(0)
Beispiel #9
0
def command_drop(item_name):
    if item_name in player['inventory']:
        player['inventory'].remove(item_name)
        world[CURRENT_ROOM]['items'].append(item_name)
    else:
        print_slowly("you don't have a " + item_name)