Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无效移动条件,基于Python文本的游戏_Python - Fatal编程技术网

无效移动条件,基于Python文本的游戏

无效移动条件,基于Python文本的游戏,python,Python,我需要一个基于文本的python游戏的帮助,我已经完成了大部分工作,我可以在所有3个房间之间移动,顶部有“大厅”,然后往南走“卧室”往东走“地窖”我可以往回走,所以往西走“卧室”向北走,最后回到大厅 问题是,如果我在大厅里键入east,它会跳到地窖,而不是说有墙。 我想做什么 显示播放机当前所在房间的输出。 告诉游戏如何处理不同命令的决策分支。命令可以是在房间之间移动(例如向北、向南、向东或向西移动)或退出。 如果玩家输入有效的“移动”命令,游戏应该使用字典将他们移动到新房间。 如果玩家进入“退

我需要一个基于文本的python游戏的帮助,我已经完成了大部分工作,我可以在所有3个房间之间移动,顶部有“大厅”,然后往南走“卧室”往东走“地窖”我可以往回走,所以往西走“卧室”向北走,最后回到大厅

问题是,如果我在大厅里键入east,它会跳到地窖,而不是说有墙。 我想做什么

显示播放机当前所在房间的输出。 告诉游戏如何处理不同命令的决策分支。命令可以是在房间之间移动(例如向北、向南、向东或向西移动)或退出。 如果玩家输入有效的“移动”命令,游戏应该使用字典将他们移动到新房间。 如果玩家进入“退出”,游戏应将其房间设置为一个名为“退出”的房间 如果玩家输入无效命令,游戏应向玩家输出错误消息(输入验证)。 一种在玩家进入“退出”房间后结束游戏循环的方法

这是我到目前为止写的代码

rooms = {
    'Great Hall': {'South': 'Bedroom'},
    'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},
    'Cellar': {'West': 'Bedroom'}
}


def player_stat():
    print("-" * 20)
    print('You are in the {}'.format(currentRoom))
    print("-" * 20)


currentRoom = 'Great Hall'
player_move = ''

while currentRoom != 'Exit':
    player_stat()
    player_move = input('Enter your move:\n')
    if player_move in ['Exit', 'exit']:
        currentRoom = 'Exit'
        print('Play again soon')
    elif player_move in ['South', "south"]:
        currentRoom = 'Bedroom'
    elif player_move in ['North', "north"]:
        currentRoom = 'Great Hall'
        print("You made it back to the Great Hall")
    elif player_move in ['East', 'east']:
        currentRoom = 'Cellar'
        print('YOU MADE IT TO THE CELLAR, try to go back to the Great Hall')
    elif player_move in ['West', "west"]:
        currentRoom = 'Bedroom'
print("You made it back to the Bedroom")

请帮助我

我修改了你的代码以使用字典。它涉及嵌套的条件语句

rooms = {
    'Great Hall': {'South': 'Bedroom'},
    'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},
    'Cellar': {'West': 'Bedroom'}
}


def player_stat():
    print("-" * 20)
    print('You are in the {}'.format(currentRoom))
    print("-" * 20)


currentRoom = 'Great Hall'
player_move = ''

while currentRoom != 'Exit':
    player_stat()
    player_move = input('Enter your move:\n').title()
    if player_move == 'Exit':
        currentRoom = 'Exit'
    else:
        if player_move in rooms[currentRoom]:
            currentRoom = rooms[currentRoom][player_move]
            if currentRoom == 'Great Hall':
                print("You made it back to the Great Hall")
            elif currentRoom == 'Cellar':
                print('YOU MADE IT TO THE CELLAR, try to go back to the Great Hall')
        else:
            print("That is not a valid move, try again.")

print('Play again soon')


我修改了你的代码以使用字典。它涉及嵌套的条件语句

rooms = {
    'Great Hall': {'South': 'Bedroom'},
    'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},
    'Cellar': {'West': 'Bedroom'}
}


def player_stat():
    print("-" * 20)
    print('You are in the {}'.format(currentRoom))
    print("-" * 20)


currentRoom = 'Great Hall'
player_move = ''

while currentRoom != 'Exit':
    player_stat()
    player_move = input('Enter your move:\n').title()
    if player_move == 'Exit':
        currentRoom = 'Exit'
    else:
        if player_move in rooms[currentRoom]:
            currentRoom = rooms[currentRoom][player_move]
            if currentRoom == 'Great Hall':
                print("You made it back to the Great Hall")
            elif currentRoom == 'Cellar':
                print('YOU MADE IT TO THE CELLAR, try to go back to the Great Hall')
        else:
            print("That is not a valid move, try again.")

print('Play again soon')


“如果我在大厅”,那就检查一下你的房间,你根本没用字典!如果玩家当前在
“Great Hall”
,那么他们唯一可用的移动就是相关字典中的键。考虑使用诸如<代码> LealAlgStudio=房间[CurrurnSuoLoo] .PS-作为一个小的优化,使用<代码> PraseRyStudio .LoWror(=)=“Nave'”/“代码>”。这样,任何代码的拼写“<代码>北”<代码>都是可以接受的。我在哪里和如何添加法律动作,我对它很新,它就像一种新的语言。这是为了上课,我不想不及格!“如果我在大厅”,那就检查一下你的房间,你根本没用字典!如果玩家当前在
“Great Hall”
,那么他们唯一可用的移动就是相关字典中的键。考虑使用诸如<代码> LealAlgStudio=房间[CurrurnSuoLoo] .PS-作为一个小的优化,使用<代码> PraseRyStudio .LoWror(=)=“Nave'”/“代码>”。这样,任何代码的拼写“<代码>北”<代码>都是可以接受的。我在哪里和如何添加法律动作,我对它很新,它就像一种新的语言。这是为了上课,我不想不及格!谢谢,谢谢。我不能去南方,我必须去南方。不过我可以解决这个问题。谢谢你,你是个救生员。我真的会为此付出代价。上帝保佑你,我希望你能得到最好的工作谢谢谢谢。我不能去南方,我必须去南方。不过我可以解决这个问题。谢谢你,你是个救生员。我真的会为此付出代价。上帝保佑你,我希望你得到最好的工作,因为我调整了你的字典,它通过降低输入来接受所有输入。我调整了你的字典,它通过降低输入来接受所有输入。