def move(self, direction): try: room = getattr(self.current_room, f'{direction}_to') self.current_room = room except: print_color('red', f'\n\n\nThere is no room to the {self.directions[direction]} of this room.\n\n')
def grab_item(self, item): if item in self.inventory: print_color( 'yellow', f'\n\nYou already have item {item.name} in your inventory.\n') else: self.inventory.append(item) print_color('green', f'\n\nYou picked up the {item.name}\n')
def receive(): while True: try: message = CLIENT_SOCKET.recv(1024).decode('ascii') if message == 'USER': CLIENT_SOCKET.send(USERNAME.encode()) else: print(message) except: print_color('An error occurred!', 'red')
def print_commit(n, commit): hunks_count = len(commit['hunks']) print_color('[{}] '.format(n + 1), fg=2, end='') print_color(commit['msg'][0], end='') print_color(' ({} hunk{})'.format(hunks_count, 's' if hunks_count > 1 else ''), fg=COLOR_GREY)
def print_connections(): os.system('cls') print_color(f'\nReady to receive at {SERVER_IP}:{SERVER_PORT}\n', 'green') if len(ADDRESSES) > 0: print_color(f'\nCONNECTIONS: \n', 'green') for address in ADDRESSES: print_color(f'\tConnected with {address}', 'cyan')
def read_book(self, book): if book not in self.inventory: print_color('red', '\n\nYou do not have that book.') else: if book.is_read == True: print_color('cyan', f"\n\nYou've already read this book") else: print_color('green', f"""\n\nYou read {book.name}. You've aqcuired part of the password to access treasure!""") book.is_read = True self.knowledge.append(f'{book.contents}')
def print_commit_caption(n, commit): print() print_line(COLOR_YELLOW) hunks_count = len(commit['hunks']) print_color('[{}] '.format(n+1), fg=COLOR_YELLOW, end='') print_color(commit['msg'][0], end='') print_color(' ({} hunk{})'.format( hunks_count, 's' if hunks_count>1 else ''), fg=COLOR_GREY_DARK) if len(commit['msg']) == 2: print() for line in commit['msg'][1].split('\n'): print_indented_paragraph(' '*4 + line, COLOR_CAPTION2_FG, 4) print_line(COLOR_GREY_DARK) print()
def print_hunk(hunk, fname=None): for line in hunk: if line.startswith('@@'): line = line.strip()[3:-2] print_caption2(' '*INDENT + '{}{}'.format(fname + ': ' if fname else '', line)) else: if line.startswith('+'): print_color('+'+(INDENT-1)*' ', fg=COLOR_GREEN, end='') print_indented_paragraph(line[1:], COLOR_GREEN) elif line.startswith('-'): print_color('- ', fg=COLOR_RED, end='') print_indented_paragraph(line[1:], COLOR_RED) else: # print_color('.' + ' '*(INDENT-1), end='', fg=COLOR_GREY) print_color(' '*INDENT, end='', fg=COLOR_GREY) print_indented_paragraph(line[1:], COLOR_CONTEXT) print('')
def print_commit_caption(n, commit): print() print_line(COLOR_YELLOW) hunks_count = len(commit['hunks']) print_color('[{}] '.format(n + 1), fg=COLOR_YELLOW, end='') print_color(commit['msg'][0], end='') print_color(' ({} hunk{})'.format(hunks_count, 's' if hunks_count > 1 else ''), fg=COLOR_GREY_DARK) if len(commit['msg']) == 2: print() for line in commit['msg'][1].split('\n'): print_indented_paragraph(' ' * 4 + line, COLOR_CAPTION2_FG, 4) print_line(COLOR_GREY_DARK) print()
def print_hunk(hunk, fname=None): for line in hunk: if line.startswith('@@'): line = line.strip()[3:-2] print_caption2(' ' * INDENT + '{}{}'.format(fname + ': ' if fname else '', line)) else: if line.startswith('+'): print_color('+' + (INDENT - 1) * ' ', fg=COLOR_GREEN, end='') print_indented_paragraph(line[1:], COLOR_GREEN) elif line.startswith('-'): print_color('- ', fg=COLOR_RED, end='') print_indented_paragraph(line[1:], COLOR_RED) else: # print_color('.' + ' '*(INDENT-1), end='', fg=COLOR_GREY) print_color(' ' * INDENT, end='', fg=COLOR_GREY) print_indented_paragraph(line[1:], COLOR_CONTEXT) print('')
def print_caption2(caption): print_color(caption, fg=COLOR_CAPTION2_FG) print()
def pc(s, color): print_color(s, fg=color)
def print_full_length_text_block(text, bg): print_color(('{0: <' + str(TERMINAL_COLUMNS) + '}').format(text), bg=bg)
def prompt(text=None, hint=None): if text: print(text) if hint: print_color(hint, fg=COLOR_GREY) return input('\n> ')
def print_commit(n, commit): hunks_count = len(commit['hunks']) print_color('[{}] '.format(n+1), fg=2, end='') print_color(commit['msg'][0], end='') print_color(' ({} hunk{})'.format( hunks_count, 's' if hunks_count>1 else ''), fg=COLOR_GREY)
def set_connection(): ip = '' port = 0 while True: input_server = input(f'\nSERVER IP [press enter to use default]: ') if input_server == 'localhost': ip = input_server break elif input_server != '': verify = re.fullmatch(r'^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$', input_server) if verify is None: print_color('\nERROR: INVALID SERVER IP', 'red') continue else: ip = input_server print_color(f'\nUSING IP {ip}...', 'yellow') break else: ip = 'localhost' print_color(f'\nUSING IP {ip}...', 'yellow') break while True: input_port = input('\nPORT [press enter to use default]: ') if input_port != '': verify = re.fullmatch(r'^\d*$', input_port) if verify is None: print_color(f'\nERROR: INVALID PORT NUMBER', 'red') continue else: port = int(input_port) print_color(f'\nUSING PORT {port}...', 'yellow') break else: port = 12000 print_color(f'\nUSING PORT {port}...', 'yellow') break return [ip, port]
# * Prints the current room name # * Prints the current description (the textwrap module might be useful here). # * Waits for user input and decides what to do. # # If the user enters a cardinal direction, attempt to move to the room there. # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. player_name = input("What's your name? ") player = Player(player_name, room['outside']) print(f'\nWelcome {player.name}!') print_color('cyan', f'\nWelcome {player.name}!\n\n') # time.sleep(0.5) def location_print(color): print_color( color, f'\033[1m\n\nYour location: {player.current_room.name}\33[00m') print_color(color, f'{player.current_room.description} \n') # time.sleep(0.5) while True: if player.current_room == room['outside']: location_print('green') elif player.current_room == room['foyer']:
os.system('cls') print(" _______ _____ _____ _____ \n" " |__ __/ ____| __ \ / ____| \n" " | | | | | |__) | | (___ ___ _ ____ _____ _ __ \n" " | | | | | ___/ \___ \ / _ \ '__\ \ / / _ \ '__| \n" " | | | |____| | ____) | __/ | \ V / __/ | \n" " |_| \_____|_| |_____/ \___|_| \_/ \___|_| \n" ) input("PRESS ENTER TO START") os.system('cls') if 'default' in sys.argv: SERVER_IP = 'localhost' SERVER_PORT = 12000 else: SERVER_IP, SERVER_PORT = set_connection() print_color('\nOpening server...', color='yellow') try: SERVER_SOCKET.bind((SERVER_IP, SERVER_PORT)) except OSError as e: print_color(f'\n{e}', color='red') exit(-1) SERVER_SOCKET.listen() print_color(f'\nReady to receive at {SERVER_IP}:{SERVER_PORT}\n', color='green') receive()
def location_print(color): print_color( color, f'\033[1m\n\nYour location: {player.current_room.name}\33[00m') print_color(color, f'{player.current_room.description} \n')
print(" _______ _____ _____ _____ _ _ _ \n" " |__ __/ ____| __ \ / ____| (_) | | \n" " | | | | | |__) | | | | |_ ___ _ __ | |_ \n" " | | | | | ___/ | | | | |/ _ \ '_ \| __| \n" " | | | |____| | | |____| | | __/ | | | |_ \n" " |_| \_____|_| \_____|_|_|\___|_| |_|\__| \n") input("PRESS ENTER TO START") os.system('cls') if 'default' in sys.argv: SERVER_IP = 'localhost' SERVER_PORT = 12000 else: SERVER_IP, SERVER_PORT = set_connection() print_color(f'\nOpening server...', 'yellow') try: CLIENT_SOCKET.connect((SERVER_IP, SERVER_PORT)) except OSError as e: print(f'\n{e}', 'red') exit(-1) os.system('cls') USERNAME = input('USERNAME: '******'random') receive_thread = threading.Thread(target=receive) receive_thread.start()
def print_full_length_text_block(text, bg): print_color(('{0: <'+str(TERMINAL_COLUMNS)+'}').format(text), bg=bg)
Book("book3", "A thin, fragile book. Try reading it.", "2h5n"), 'treasure': Treasure("treasure", "One-thousand gold bars and a lifetime supply of burritos!") } # add the items to the rooms room['foyer'].items = [items['key']] room['library'].items = [items['book1'], items['book2'], items['book3']] room['treasure'].items = [items['treasure']] player_name = input('\nWhat is your name? ') player = Player(player_name, room['outside']) print_color('cyan', f'\nWelcome {player.name}!\n\n') # time.sleep(1) def location_print(color): print_color( color, f'\033[1m\n\nYour location: {player.current_room.name}\33[00m') # time.sleep(1) print_color(color, f'{player.current_room.description} \n') # time.sleep(1) # loop that prints the current room name and description while True: if player.current_room == room['outside']: