这是我的代码:
import time,sys,random
wpm = 125
userName = ""
global mirror
mirror = False
global knife
knife = False
inventory = []
vial = False
trollHit = 0
playerHit = 0
axe = False
choice2 = False
kitchenAlready = False
def death():
sys.exit()
userInput = ""
def cantPerformAction(userInput):
if userInput == "e" or userInput == "u" or userInput == "w" or userInput == "s" or "t" in userInput:
slow_type("You can't perform that action.")
def checkDirection(userInput):
if any(char in userInput for char in 'nsewudt') == False:
return False
elif any(char in userInput for char in 'nsewudt') == True:
return True
#credit to 'bill gross' for ideas on the slow type
def slow_type(y): #slow typing to make it seem like the computer is typing
for x in y:
sys.stdout.write(x)
sys.stdout.flush()
time.sleep(random.random( )*10.0/wpm)
print (' ')
def clear(): #clear the line so that another line of text can appear below it
print ("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
#CROSSROADS: All directions lead to death except right. Player cannot turn back.
def crossroads():
slow_type("\n\nCrossroads")
slow_type("\n\nA crossroads is in front of you. There is a passage to the west, east, and north.")
global choice2
global choice
choice = None
choice2 = None
youBetterChoose = 0
while choice == None and choice2 == None:
userInput = input("\n>")
if checkDirection(userInput) == False:
while checkDirection == False:
userInput = input("\n>")
checkDirection(userInput)
userInput1 = userInput.lower().strip()
if userInput1 == "s":
clearingalready()
if userInput1 =="n":
slow_type("\n>You walk forward, determined... off a cliff. Tragic!")
death()
if userInput1 == "w":
slow_type("\nYou encounter a giant spider. Without a weapon, it easily tears you to shreds.")
death()
if userInput1 == "e":
fork()
if userInput1 == "d":
slow_type("You can't do down farther than the floor.")
if userInput1 == "u":
slow_type("You can't go that way.")
userInput = ""
def crossroadsalready():
slow_type("\n\nCrossroads")
global choice2
global choice
choice = None
choice2 = None
youBetterChoose = 0
while choice == None and choice2 == None:
userInput = input("\n>")
if checkDirection(userInput) == False:
while checkDirection == False:
userInput = input("\n>")
checkDirection(userInput)
userInput1 = userInput.lower().strip()
if userInput1 == "s":
clearingalready()
if userInput1 =="n":
slow_type("\n>You walk forward, determined... off a cliff. Tragic!")
death()
if userInput1 == "w":
slow_type("\nYou encounter a giant spider. Without a weapon, it easily tears you to shreds.")
death()
if userInput1 == "e":
fork()
if userInput1 == "d":
slow_type("You can't do down farther than the floor.")
if userInput1 == "u":
slow_type("You can't go that way.")
userInput = ""
def fork():
choice2 = False
slow_type("\nFork")
slow_type("\nThere are another two ways to go. One goes north into a cavern, another leads down deeper into the earth.\n\n")
deeperOrFarther = ""
while choice2 == False:
userInput = input(">")
checkDirection(userInput)
if checkDirection(userInput) == False:
while checkDirection(userInput) == False:
userInput = input (">")
checkDirection(userInput)
deepLower = userInput.lower().strip()
if deepLower == "n":
slow_type("You walk forward, determined... off a cliff. Tragic!")
choice2 = True
death()
if deepLower == "d":
slow_type("You descend down into the darker regions of the cave.")
choice2 = True
if deepLower == "w":
crossroadsalready()
cantPerformAction(deepLower)
houseChoice()
wpm = 60
slow_type("Welcome to Zotan! \nn = north \ns = south \nw = west \ne = east \nu = up \nd = down \nt = take")
clear()
wpm = 120
def clearing():
slow_type("Clearing\n")
slow_type("You wake up in the middle of a clearing. There is a passage to the north.")
slow_type("\n\n")
clearingalready = True
choice = None
while choice == None:
userInput = input("\n>")
if checkDirection(userInput) == False:
while checkDirection == False:
userInput = input("\n>")
checkDirection(userInput)
userInput = userInput.lower()
if userInput.strip() == "n":
choice = False
else:
slow_type("You can't go that way.")
userInput = ""
crossroads() #1
def clearingalready():
slow_type("Clearing\n")
slow_type("There is a passage to the north.")
slow_type("\n\n")
choice = None
while choice == None:
userInput = input("\n>")
if checkDirection(userInput) == False:
while checkDirection == False:
userInput = input("\n>")
checkDirection(userInput)
userInput = userInput.lower()
if userInput.strip() == "n":
choice = False
else:
slow_type("You can't go that way.")
userInput = ""
crossroads() #1
def houseChoice():
slow_type("\n\n\n\nHouse Doorway\n\n")
choice = None
while choice == None:
userInput = input(">")
checkDirection(userInput)
if checkDirection(userInput) == False:
while checkDirection(userInput) == False:
userInput = input(">")
checkDirection(userInput)
userInput = userInput.lower().strip()
if userInput == "d" or userInput == "u" or userInput == "w" or userInput == "e":
slow_type("You can't go that way.")
if userInput == "n":
choice = False
if userInput == "s":
choice = False
if userInput == "s":
fork()
elif userInput == "n":
entryway()
def entryway():
slow_type("\nEntryway")
slow_type("\n\nThere is a kitchen to the west and a dark staircase. A back door hangs open in the north, revealing the entry into another dark corridor.")
userInput = input("\n>")
if checkDirection(userInput) == False:
while checkDirection == False:
userInput = input("\n>")
checkDirection(userInput)
userInput = userInput.lower().strip()
if userInput == "w":
kitchen()
if userInput == "u":
attic()
if userInput == "n":
chasm()#4
if userInput == "s":
houseChoice()
def entrywayalready():
slow_type("\nEntryway")
userInput = input("\n>")
if checkDirection(userInput) == False:
while checkDirection == False:
userInput = input("\n>")
checkDirection(userInput)
userInput = userInput.lower().strip()
if userInput == "w":
if kitchenAlready == False:
kitchen()
elif kitchenAlready == True:
kitchenalready()
if userInput == "u":
attic()
if userInput == "n":
chasm()#4
def kitchen():
kitchenAlready = True
slow_type("\n\nKitchen")
slow_type("It seems that the kitchen has been used recently. There is a wicked looking steak knife on the counter, and a mirror on the table.")
userInput = input("\n>")
userInput = userInput.lower().strip()
if userInput == "t knife":
if "knife" not in inventory:
slow_type("Taken.")
inventory.append("knife")
elif "knife" in inventory:
slow_type("You can't take that item.")
elif userInput == "t mirror":
if "mirror" not in inventory:
inventory.append("mirror")
elif "mirror" in inventory:
slow_type("You can't take that item.")
slow_type("You can't perform that action.")
elif userInput == "e":
entrywayalready()
def kitchenalready():
slow_type("\n\nKitchen")
userInput = input("\n>")
userInput = userInput.lower().strip()
if "knife" not in inventory:
inventory.append("knife")
elif "knife" in inventory:
slow_type("You can't take that item.")
if userInput == "t mirror":
if "mirror" not in inventory:
inventory.append("mirror")
elif "mirror" in inventory:
slow_type("You can't take that item.")
if userInput == "e":
entrywayalready()
def attic():
slow_type("\n\nAttic")
choice = None
while choice == None:
userInput = input(">")
if checkDirection(userInput) == False:
while checkDirection == False:
userInput = input(">")
checkDirection(userInput)
userInput = userInput.lower().strip()
if userInput == "n" or userInput == "s" or userInput == "e" or userInput == "w" or userInput == "u":
slow_type("You can't go that way")
if userInput == "t vial":
if "vial" not in inventory:
slow_type("Taken.")
inventory.append("vial")
elif "vial" in inventory:
slow_type("You can't take that item.")
if userInput == "d":
choice = False
entryway()#6
def chasm():
slow_type("\n\nChasm")
slow_type("\nThere is a chasm in front of you, with a rickety wooden bridge crossing the wide and endlessly deep ravine to the north, and a small passage to the west.")
userInput = input(">")
checkDirection(userInput)
if checkDirection(userInput) == False:
while checkDirection(userInput) == False:
userInput = input (">")
checkDirection(userInput)
chasmChoice = userInput.lower().strip()
if chasmChoice == "n":
slow_type("You cross the wooden bridge and it crumbles behind you. There is no turning back.")
cavern()
if chasmChoice == "w":
smallPassage()
if chasmChoice == "s":
entryway()#7
def smallPassage():
slow_type("\n\nSmall Passage")
slow_type("\nThere is a room to the west.")
userInput = input(">")
checkDirection(userInput)
if checkDirection(userInput) == False:
while checkDirection(userInput) == False:
userInput = input (">")
checkDirection(userInput)
userInputLower = userInput.lower().strip()
if userInputLower == "w":
trollRoom()
if userInputLower == "e":
chasm()
if userInputLower == "s" or userInputLower == "n" or userInputLower == "u" or userInputLower == "d" or userInputLower == "t":
slow_type("You can't perform that action.")#8
def trollRoom():
slow_type("\n\nTroll Room")
slow_type("\nThere is a troll in the room with a large blood stained axe.")
lowerr = "l"
while lowerr != "e":
userInput = input(">")
lowerr = userInput.lower().strip()
if lowerr == "attack troll":
if "knife" in inventory:
xRan = random.randint(0,3)
if xRan == "3":
slow_type("The troll parries your attack.")
if xRan == "2":
slow_type("You get a clear hit on the troll. It groans loudly, displaying a look of deep hatred on it's deformed face.")
trollHit = trollHit + 1
if trollHit == 2:
slow_type("The troll falls to the floor, dead. Its axe lays on the floor.")
axe = True
if userInput != "t axe" or userInput != "e":
slow_type("You can't perform that action.")
if xRan == 3:
if playerHit == 0:
slow_type("The troll knocks you back.")
if playerHit == 1:
slow_type("The troll lands a clean graze on your shoulder. You cry out in pain.")
if lowerr == "t axe":
if axe == True:
slow_type("Taken.")
inventory.append("axe")
elif axe != True:
slow_type("There is no axe there.")
if lowerr == "n" or lowerr == "s" or lowerr == "d" or lowerr == "u" or lowerr == "t" or lowerr == "w":
slow_type("You cannot perform that action.")#9
clearingAlready = False #Determines whether or not the player has already been to the crossroads.
clearing()
crossroads()
fork()
当我执行代码的这个特定部分时,似乎计算机没有输出,没有Taken.
或You can't perform that action
。我似乎无法确定错误的确切原因或错误原因。
控制台输出:
House Doorway
>n
Entryway
>w
Kitchen
>t knife
output: nothing