击败基于文本的游戏,拥有完整的物品清单



所以这是我在这里发布的第一个问题,所以如果我把所有这些的格式搞砸了,我很抱歉。我正在尝试编写一个基于文本的游戏,从一个房间移动到另一个房间,并将物品添加到您的库存中。我目前的设置是,如果你进入别墅房间,但你没有所有的物品,那么你会输,但如果你有所有的东西,那么你就会赢。有没有一种方法可以编码,一旦你的库存达到6件(所有物品(,你就会自动获胜,而不必去反派房间?我想你可以说,如果我一开始就不必去反派房间的话,它会更好地配合我的叙事。例如,在被恶棍抓住之前试图逃跑,而不一定是为了对抗维廉。

此外,这是我的第一个类,我对Python还很陌生,所以我现在对当前代码的任何指针都会很感激!提前感谢!

rooms = {
'Dining Room': {'South': 'Bedroom', 'North': 'Shop', "East": 'Kitchen', 'West': 'Study', 'item': 'none'},
'Bedroom': {'North': 'Dining Room', 'East': "Innkeepers Suite", 'item': 'Longbow'},
'Garden': {'West': 'Shop', 'item': 'Book'},
'Shop': {'East': 'Garden', 'South': 'Dining Room', 'item': 'Staff'},
'Study': {'East': 'Dining Room', 'item': 'Gold Coins'},
'Kitchen': {'West': 'Dining Room', 'North': 'Stables', 'item': 'Chest'},
'Stables': {'South': 'Kitchen', 'item': 'Horse'},
'Innkeepers Suite': {'West': 'Bedroom', 'item': 'Seeker'}
}
def main():
def instructions():
print('Welcome to the Wandering Lotus Inn Text Based Game')
print("Collect your 6 items hidden around")
print("the inn before you're caught by the Seeker!")
print('Move directions: West, East, North, South')
print("Add item to inventory: 'get item'")
def player_location():
print("-" * 40)
print('You are in the {}'.format(currentRoom))
print('Inventory:', Inventory)
print('Item:', rooms[currentRoom]['item'])
currentRoom = 'Dining Room'
player_move = ''
Inventory = []
while currentRoom in rooms:
player_location()
player_move = input('Enter your move:n')
if player_move in rooms[currentRoom]:
currentRoom = rooms[currentRoom][player_move]
if currentRoom == 'Innkeepers Suite':
if len(Inventory) == 6:
print('You win!')
if len(Inventory) != 6:
print('You lose..')
break
elif player_move == 'get item':
if rooms[currentRoom]['item'] != 'none':
Inventory.append(rooms[currentRoom]['item'])
print("You aquired : ", rooms[currentRoom]['item'])
rooms[currentRoom]['item'] = 'none'
elif rooms[currentRoom]['item'] == 'none':
print("There isn't anything in here!")
else:
print("Not a valid instruction, try again")
main()
print('Game Over! Thanks for playing')

您的代码并没有完全为我运行,所以我很难检查这是否正确。无论如何,您可以在附加项目后获取Inventory的长度。如果CCD_ 2的长度等于6;你赢了"并断开CCD_ 3环路。

所以类似于:

Inventory.append(rooms[currentRoom]['item'])
print("You aquired : ", rooms[currentRoom]['item'])
if len(Inventory) == 6:
print("You win!")
break

相关内容

最新更新