Я очень неопытный и нашел, что эти два метода для реализации комнат в ролевых играх похожи на создание. Id, как некоторые входные данные, какой метод превосходит другой. Мне просто интересно, с какими головными болями я могу столкнуться с каждым. У них обоих, кажется, что-то есть для них. Я просто не уверен в использовании функций таким образом, я не мог найти способ сделать это с классами. Любые входные данные были бы хорошими, спасибо.
Я предпочитаю, как распечатывает этот.
def lobby():
#exits
N = 'n[lounge]'
S = 's[airlock]'
E = 'e[wall]'
W = 'w[wall]'
#room description
print('A quiet and empty lobby')
print('There is a dusty desk in front of a bad painting.')
print('exits-', N, S, E, W)
d = input('go which direction?')
if d == 'n':
lounge()
else:
wall()
def wall():
print('You cant go that way')
#room function
def lounge():
global lounge_action
N = 'n[wall]'
S = 's[lobby]'
E = 'e[wall]'
W = 'w[wall]'
#Room description
print('A few people are having drinks here.')
#Things in the room
print('The bartender says "Hello".')
print('exits-', N, S, E, W)
d = input('go which direction?')
if d == 's':
lobby()
else:
wall()
def start():
lobby()
d = 's'
while d != 'quit':
start()
И это другой вариант, который я видел.
rooms = {
'lobby': {
'name': 'an empty lobby',
'north': 'lounge',
'south': 'airlock',
'text': 'There is an empty desk in the room.'
'The floors are made of cold metal.' },
'lounge': {
'name': 'a quiet lounge',
'south': 'lobby',
'text': 'The bartender asks what you want.'},
'airlock':{
'name': 'a cold landing pad',
'north': 'lobby',
'text': 'there is a ship parked here'
}
}
directions = ['north', 'south', 'east', 'west']
current_room = rooms['lobby']
d = 'lobby'
while d != 'quit':
print(current_room)
d = input('\nWhat do you do?')
if d in directions:
if d in current_room:
current_room = rooms[current_room[d]]
else:
print('Cant go that way')