代码拉取完成,页面将自动刷新
同步操作将从 luohanye/python-core 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#! python3
"""
author: laoxu
"""
# 游戏说明
def showInstructions():
print('''
RPG Game
========
完成游戏条件:拿到钥匙和药水到达花园并躲避怪物。
命令:
go [direction]
get [item]
'''
)
# 打印当前房间和背包信息
def showCurrentRoom(room, bag):
print('You are in the %s' % currentRoom)
print('Inventory: ', bag)
rooms = {
'Hall': {
'south': 'Kitchen',
'east': 'Dinning Room',
'item': 'key'
},
'Kitchen': {
'north': 'Hall',
'item': 'monster'
},
'Dinning Room': {
'west': 'Hall',
'south': 'Garden',
'item': 'potion'
},
'Garden': {
'north': 'Dinning Room'
}
}
# 初始化房间
currentRoom = 'Hall'
# 初始化物品栏
inventory = []
# 打印游戏帮助
showInstructions()
print('You are in the %s' % currentRoom)
print('Inventory: ', inventory)
print('You see a key')
while True:
# 玩家进入厨房,游戏结束
if 'item' in rooms[currentRoom] and 'monster' in rooms[currentRoom]['item']:
print('你被怪物抓住了...游戏结束!')
break
# 玩家拿到钥匙和药水进入花园,游戏结束
if currentRoom == 'Garden' and 'key' in inventory and 'potion' in inventory:
print('你逃脱了房子!你赢了!')
break
# 接收操作步骤
step = input()
# 客厅->厨房
if currentRoom == 'Hall' and step == 'go south':
currentRoom = 'Kitchen'
continue
# 客厅->餐厅
elif currentRoom == 'Hall' and step == 'go east':
currentRoom = 'Dinning Room'
# 厨房->客厅
elif currentRoom == 'Kitchen' and step == 'go north':
currentRoom = 'Hall'
# 餐厅->客厅
elif currentRoom == 'Dinning Room' and step == 'go west':
currentRoom = 'Hall'
# 餐厅->花园
elif currentRoom == 'Dinning Room' and step == 'go south':
currentRoom = 'Garden'
# 花园->餐厅
elif currentRoom == 'Garden' and step == 'go north':
currentRoom = 'Dinning Room'
# 拿到钥匙
elif currentRoom == 'Hall' and 'key' not in inventory and step == 'get key':
inventory.append('key')
print('key got!')
# 拿到药水
elif currentRoom == 'Dinning Room' and 'potion' not in inventory and step == 'get potion':
inventory.append('potion')
print('potion got!')
# 打印房间和物品栏
showCurrentRoom(currentRoom, inventory)
if currentRoom == 'Hall' and 'key' not in inventory:
print('You see a key')
if currentRoom == 'Dinning Room' and 'potion' not in inventory:
print('You see a potion')
continue
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。