Python House Adventure-如果你已经进入过一个房间,如何给出不同的输出



所以,基本上,我正在使用python制作一个文本冒险游戏,目的是根据线索和谜语在家里的某个地方找到奖品。当你进入房子里的一个房间时,告诉程序你是想去北、南、东还是西,它会给你一个房间的描述,但在某些情况下,当你进入一个房间,除了你刚来的房间之外,没有其他地方可以去,所以我想让它成为一个不同的输出,如果你已经进入了房子里的房间,它会提供给你。我该怎么做?

class bc:
HEADER = '33[95m'
OKBLUE = '33[94m'
OKGREEN = '33[92m'
WARNING = '33[93m'
FAIL = '33[91m'
ENDC = '33[0m'
BOLD = '33[1m'
UNDERLINE = '33[4m'
inventory = []
chest = "Chest"
key = "Key"
book = "Book"
picture = "Picture"
def playGame():
location = "Porch"
show_intro()
while not (location == "Exit"):
showRoom(location)
direction = str(input(bc.BOLD + bc.HEADER + "Which direction 
do you want to go?: n" + bc.ENDC))
location = pickRoom(direction, location)
def show_intro():
print(bc.BOLD + """Welcome to a game with no graphics so you get 
more FPS's!
Old man Mesarosh lived here years ago before he and his wife suddenly 
disappeared.
Before he died, it was said that he left behind a chest full of 
treasure.
It's your job to figure out where he left it, and fast...
Police drive by every 30 minutes searching for teens exploring the 
abandoned house
Find the clues left behind by Mesarosh and find where the treasure is 
hidden.
Type "North", "South", "East" or "West" to decide which way to go.
Good luck! n""" + bc.ENDC)
def pickRoom(direction, room):
while True:
if(direction == "quit") or (direction == "exit"):
print("Better luck next time!")
return "Exit"
elif room == "Porch":
if direction.lower() == "north":
return "Pantry"
elif room == "Pantry":
if direction.lower() == "north":
return "Kitchen"
elif direction.lower() == "east":
return "DiningRoom"
elif room == "DiningRoom":
if direction.lower() == "west":
return "Pantry"
elif room == "Kitchen":
if direction.lower() == "west":
return "LivingRoom"
elif direction.lower() == "east":
return "Bedroom"
elif room == "Bedroom":
if direction.lower() == "west":
return "Kitchen"
elif room == "LivingRoom":
if direction.lower() == "west":
return "Bathroom"
elif direction.lower() == "north":
return "Stairs"
elif room == "Bathroom":
if direction.lower() == "east":
return "LivingRoom"
elif room == "Stairs":
if direction.lower() == "south":
return "Bar"
elif room == "Bar":
if direction.lower() == "east":
return "Shop"
elif room == "Shop":
if direction.lower() == "north":
return "Closet"
elif direction.lower() == "south":
return "Storage"
elif room == "Storage":
if direction.lower() == "north":
return "Shop"
elif room == "Closet":
if direction.lower() == "south":
return "Shop"

def showRoom(room):
if room == "Porch": #Done
showPorch()
elif room == "Pantry": #Done
showPantry()
elif room == "Kitchen": #Done
showKitchen()
elif room == "DiningRoom": #Done
showDining()
elif room == "Bedroom": #Done
showBedroom()
elif room == "LivingRoom": #Done
showLiving()
elif room == "Bathroom": #Done
showBathroom()
elif room == "Stairs": #Done
showStairs()
elif room == "Bar": #Done
showBar()
elif room == "Shop": #Done
showShop()
elif room == "Storage": #Done
showStorage()
elif room == "Closet": #Done
showCloset()
playGame()
玩家进入房间后,您需要一个具有不同值的变量。您可以在游戏开始时初始化标志或计数器,在显示消息之前检查它,然后在玩家进入房间时设置它(用于标志(或递增它(用于计数器(。

输入房间时,设置一个变量。在每个房间中输入if-else语句,检查变量的值,如果变量显示为"你已经去过那里"状态,则显示"你已经过那里"消息。

最新更新