为什么我的roomChoice一直打印1而不是其他房间的号码



尝试制作游戏。

当我输入去下一个房间的方向时,它会直接带我回到START_room,这就是我设置的,但我希望能够在不同的房间之间切换

我试着改变输入,但什么都不起作用——我就去那个房间,只去那个房间。

只是需要运动功能方面的帮助。

我认为问题是我不知道如何在函数之间正确地分配用户输入。

import random
import sys
START_ROOM = 1
FINAL_ROOM = 6
START_GOLD = 10
goldAmount = START_GOLD
chealth = 10
thealth = 10 
pdamage = 1
roomChoice = START_ROOM
visited_room = False
gameOver = False
global c, t , p, r
p = pdamage
t = thealth
c = chealth
r = roomChoice

def room1(goldAmount, visited_room, chealth):
print("Your health has been set to {0} health".format(chealth))

if visited_room == False:
story1()
gold = 10 # This is the amount of gold the room contains.

print()
print("The room has", gold, "gold pieces in it...")
goldAmount += gold
print("After taking the gold, you currently have", goldAmount, "gold pieces in your posession...")
print()
# Mark the room as 'visited'
visited_room = True
shop()
combat()
else:
print(visited_room)
print("You have already visited room  1 before...")
shop()
print()

direction = input("What direction do you want to go [n]orth, [ns]north south, [s]outh, [se]south east, [e]ast, [w]est?: ")
while direction != "n" and direction != "s" and direction != "e" and direction != "w" and direction != "ns" and direction != "se":
print("Invalid input...")
direction = input("[n]orth, [ns]north south, [s]outh, [se]south east, [e]ast, [w]est: ")
return movement(roomChoice, goldAmount, visited_room, chealth)


def movement(a, b, c, d):
a = roomChoice
b = goldAmount
c = visited_room
d = chealth
while d < 0:
if direction == "n":
a = 2
print("Room 2")
elif direction == "ns":
a = 1
print("Room 5")
elif direction == "s":
a = 3 
print("Room 3")

elif direction == "e":
a = 4 
print("Room 4")

elif direction == "w":
a = 5  
print("Room 5")
elif direction == "se":
a = 6 
print("Room 6")
else:
gameOver == True
return (a,b,c,d)

def main():
gameOver = False
START_GOLD = 0
goldAmount = START_GOLD
currentRoom = START_ROOM
thealth = 10
chealth = 10
pdamage = 1
visited_room1 = False 
visited_room2 = False
visited_room3 = False
visited_room4 = False
visited_room5 = False
visited_room6 = False
print("Welcome to Dungeon Crawl...")
print()


while gameOver == False:
choice = input("MAIN MENU: [p]lay, [i]nstructions, or [q]uit?: ")
print()
if choice == "p": 
print("Your current Health is ", chealth,"/",thealth, " and ", "Your player damage is ", pdamage)

while currentRoom != FINAL_ROOM: 
if currentRoom == 1:
currentRoom, goldAmount, visited_room1,chealth = room1(goldAmount, visited_room1, chealth)
elif currentRoom == 2:
currentRoom, goldAmount, visited_room2,chealth = room2(goldAmount, visited_room2, chealth)
elif currentRoom == 3:
currentRoom, goldAmount, visited_room3,chealth = room3(goldAmount, visited_room3, chealth)
elif currentRoom == 4:
currentRoom, goldAmount, visited_room4,chealth = room4(goldAmount, visited_room4, chealth)
elif currentRoom == 5:
currentRoom, goldAmount, visited_room4,chealth = room4(goldAmount, visited_room5, chealth)
elif currentRoom == 6:
currentRoom, goldAmount, visited_room4,chealth = room4(goldAmount, visited_room6, chealth)
else:
print("Error - currentRoom number", currentRoom, "does not correspond with available rooms")
sys.exit()


if (chealth > 0):
print()
print("You have escaped with", chealth, "and", goldAmount, "gold from the dungeon!")
print()
gameOver = False
goldAmount = START_GOLD
currentRoom = START_ROOM
thealth = 10
chealth = 10
pdamage = 1
visited_room1 = False 
visited_room2 = False
visited_room3 = False
visited_room4 = False
visited_room5 = False
visited_room6 = False
else:
print("You have perished in the dungeon")
print("Game Over")
gameOver == True

thealth = 10
chealth = thealth
pdamage = 1
goldAmount = START_GOLD
currentRoom = START_ROOM
visited_room1 = False
visited_room2 = False
visited_room3 = False
visited_room4 = False
visited_room5 = False
visited_room6 = False
elif choice == "i": 
print()
print("Adventure around the dangerous dungeon and collect the gold")
print("Beware of the dangers that live in the shadows of the dark dungeon")
print()
elif choice == "q": 
gameOver == True
print("Good Bye!")
print()
quit()

else:
print()
print("Please enter [p], [i], or [q]...")
print()
if __name__ == "__main__":
main()
if __name__ == "__main__":
main()

尝试更改

while d < 0:

while d > 0:

目前,只有当健康状况小于0时,您才会移动房间。还有一个额外的错误,即direction没有在movement函数中定义,但这并不是导致特定问题的原因。

最新更新