-2
我創建了代碼並且遊戲開始正常工作,但是在我放入方向之後,它不會進入房間。我檢查過這兩個函數是否都可以自己工作,並且工作正常,但我不確定它們如何鏈接在一起。遊戲沒有在方向功能之後玩房間部分
import time
import sys
import random
Forward = ["F", "f", "forward", "FORWARD", "Forward"]
Backwards = ["B", "b", "back", "BACK", "backwards", "BACKWARDS"]
Left = ["L", "l", "LEFT", "left", "Left"]
Right = ["R", "r", "right", "RIGHT", "Right"]
directionL = Right + Left + Backwards + Forward
health = 10
def delay_print(s):
for c in s:
sys.stdout.write('%s' % c)
#sys.stdout.flush()
time.sleep(0.10)
def name():
name = input('Hey, Who are you? ')
return name
def direction():
direction = input("What direction would you like to go: Forward, Left, Right or Backwards?")
while direction not in directionL:
direction = input ("Please enter Forward, Left, Right or Backwards.")
else:
print ("You went", direction)
def room():
global health
a=random.randint(1,8) #1=Monster 2=Exit 3-4=Ghost 5-8=Empty
if a==1:
delay_print('You encountered the monster you lose 5HP ')
health=health-5
elif a==2:
delay_print('You escaped the dungeon ')
elif a==3 or a==4:
delay_print('You encountered the ghost ')
x=random.randint(1,11)
y=random.randint(1,11)
print((x),'+',(y))
answer=int(input("What is the answer"))
realanswer = x+y
if answer==realanswer:
print("That's the correct answer")
health = health+2
else:
print("Wrong answer, the answer was",realanswer,"!")
health = health-2
elif a==5 or a==6 or a==7 or a==8:
print ('This room is empty')
health = health-1
return print("You have", health,"HP left ")
if health <1:
print ("Game Over")
print('You hear a voice echo in the background.')
delay_print('H...')
delay_print('Hey...')
delay_print('Welcome %s you are stuck in this labyrinth and you need to
escape.' % name())
print ('\n')
room(direction())
您使用哪個調試器來遍歷代碼? – lit