我只是想知道我怎样才能让它工作。我想检查函数player_position()
中参数(pos
)的值,并根据其值执行代码。我学习Python才一个月左右
def player_position(pos):
position = pos
if position == goliath.spawn:
print('The Goliath Has Attacked!')
if goliath.accuracy == 1:
print('You Have Been Killed!')
else:
print('You Killed The Goliath!')
else:
print('Nothing Happens...')
def starting_room():
while True:
position_update = input('Enter A Direction: ')
if position_update == 'Forwards':
player_position(1)
elif position_update == 'Backwards':
player_position(3)
elif position_update == 'Left':
player_position(4)
elif position_update == 'Right':
player_position(2)
elif player_position == 1:
if position_update == 'Forwards':
print('Room 2')
elif position_update == 'Backwards':
player_position(0)
elif position_update == 'Left':
print('There Are Monsters In the Dark')
elif position_update == 'Right':
print('There Are Monsters In The Dark')
starting_room()
您正在调用
player_position
,这是一个不返回任何内容的函数。相反,假设您希望跟踪玩家在starting_room
函数中的当前位置,您将希望跟踪那里的位置类似这样的内容:(注意-您需要添加更多代码来打破
while
循环-此代码应该允许您跟踪pos)相关问题 更多 >
编程相关推荐