猿问

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

所以基本上,我正在使用 python 制作一个文本冒险游戏,目标是根据线索和谜语在房子的某个地方找到奖品。当你通过告诉程序你想要向北、向南、向东或向西走而进入房子的一个房间时,它会给你一个房间的描述,但在某些情况下,当你进入一个房间时,除了你刚来自的房间,所以如果你已经进入了房子里的房间,我想让它给你一个不同的输出。我该怎么做?


class bc:

    HEADER = '\033[95m'

    OKBLUE = '\033[94m'

    OKGREEN = '\033[92m'

    WARNING = '\033[93m'

    FAIL = '\033[91m'

    ENDC = '\033[0m'

    BOLD = '\033[1m'

    UNDERLINE = '\033[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"

  

凤凰求蛊
浏览 132回答 2
2回答

噜噜哒

当进入房间时,设置一个变量。在每个房间的 if-else 语句中检查变量的值,如果变量显示已更改为 youve-already-been-here 状态,则显示 youve-already-been-here 消息。

Cats萌萌

您需要一个在玩家进入房间后具有不同值的变量。您可以在游戏开始时初始化标志或计数器,在显示消息之前检查它,然后在玩家进入房间时设置它(用于标志)或增加它(用于计数器)。
随时随地看视频慕课网APP

相关分类

Python
我要回答