コード例 #1
0
 def explore(self, direction, room, next_room=None):
     prev_room = room['room_id']
     if next_room:
         res = post(end['move'], {
             'direction': direction,
             'next_room_id': str(next_room)
         })
     else:
         res = post(end['move'], {'direction': direction})
         self.rooms[prev_room]['exits'][direction] = res['room_id']
         self.add_vertex(res)
         self.rooms[res['room_id']]['exits'][
             reverse_dirs[direction]] = prev_room
     return res
コード例 #2
0
def mine():
    while True:
        last_proof = get(end['lp'])
        next_proof = proof_of_work(last_proof)
        check_proof = post(end['mine'], {'proof': next_proof})
        if not len(check_proof['errors']):
            break
コード例 #3
0
def post_req(endpoint):
    req = post(end[endpoint], {})
    if endpoint == 'warp':
        global snitch
        snitch = True if snitch == False else False
        print_room(req)
    else:
        print_info(req)
コード例 #4
0
def move(direction):
    global data
    room_in_dir = gr.rooms[data['room_id']]['exits'][direction]
    moved = post(end['move'], {
        'direction': direction,
        'next_room_id': str(room_in_dir)
    })
    print_room(moved)
    data = moved
    return moved
コード例 #5
0
def examine(target):
    examined = post(end['examine'], {'name': target})
    print_info(examined)
    if target == 'well':
        ls8 = examined['description'][39:].split('\n')
        with open('ls8.ls8', 'w') as ls:
            ls.truncate()
            for line in ls8:
                if line != '':
                    json.dump(int(line), ls)
                    ls.write('\n')
        os.system('python ls8.py ls8.ls8')
        with open('room.ls8') as room_file:
            return travel(room_file.read())
    return examined
コード例 #6
0
def shop():
    travel(1)
    status = post(end['status'], {})
    inventory = status['inventory']
    while len(inventory):
        print(inventory)
        post(end['sell'], {"name": "treasure"})
        post(end['sell'], {"name": "treasure", "confirm": "yes"})
        status = post(end['status'], {})
        inventory = status['inventory']
コード例 #7
0
def transmogrify(item):
    mog = post(end['change'], {'name': item})
    get_req('status')
    print_room(mog)
    return mog
コード例 #8
0
def take(target):
    taken = post(end['take'], {'name': target})
    print_room(taken)
    return taken
コード例 #9
0
    command = cmd.split(' ')

    if len(command) == 1:
        if cmd == 'room':
            print_room(data)
        elif cmd in cmds:
            cmds[cmd]()
        elif cmd in cmds['self']:
            res = cmds['self'][cmd](cmd)
        elif cmd == 'help':
            print(instructions)
        else:
            print(f'Command "{cmd}" not recognized.')

    elif command[0] in cmds['double']:
        cmds['double'][command[0]](command[1])

    elif command[0] == 'wear':
        item = ' '.join(command[1:])
        wear = post(end['wear'], {'name': item})
        print_info(wear)

    elif command[0] == 'undress':
        item = ' '.join(command[1:])
        undress = post(end['undress'], {'name': item})
        print_info(undress)

    else:
        print(f'Wtf is {cmd}?')
コード例 #10
0
data = get(end['init'])
# print(data)
gr = Graph()
# gr.add_vertex(data)

with open('map.json') as map:
    completed_map = json.load(map)
    for room in completed_map:
        if completed_map[room] == data['room_id']:
            data = completed_map[room]
        gr.add_vertex(completed_map[room])
# print(gr.rooms)
# print(gr.rooms[325]['room_id'], gr.rooms[325]['exits'])
# quit()

status = post(end['status'], {})
inventory = status['inventory']
gold = int(status['gold'])
name = status['name']
encumbrance = int(status['encumbrance'])
strength = int(status['strength'])
# print(gold)
if status['name'][:4] == 'User':
    rooms_with_items = []
    for room_id, room in gr.rooms.items():
        if len(room['items']):
            rooms_with_items.append(room_id)
    while gold < 1000:
        while encumbrance < strength:
            item_room = rooms_with_items.pop()
            room_with_item = gr.get_path_to_room(data, item_room)