Python 需要帮助制作一个简单的游戏吗

Python 需要帮助制作一个简单的游戏吗,python,Python,我只是想知道如何才能使elif player\u position==1起作用。我想检查函数player\u position()中参数(pos)的值,并根据其值执行代码。我学习Python才一个月左右 def player_position(pos): position = pos if position == goliath.spawn: print('The Goliath Has Attacked!') if goliath.accu

我只是想知道如何才能使
elif player\u position==1
起作用。我想检查函数
player\u position()
中参数(
pos
)的值,并根据其值执行代码。我学习Python才一个月左右

def player_position(pos):

    position = pos

    if position == goliath.spawn:
        print('The Goliath Has Attacked!')

        if goliath.accuracy == 1:
            print('You Have Been Killed!')

        else:
            print('You Killed The Goliath!')

    else:
        print('Nothing Happens...')


def starting_room():

    while True:

        position_update = input('Enter A Direction: ')

        if position_update == 'Forwards':
            player_position(1)

        elif position_update == 'Backwards':
            player_position(3)

        elif position_update == 'Left':
            player_position(4)

        elif position_update == 'Right':
            player_position(2)

        elif player_position == 1:

            if position_update == 'Forwards':
                print('Room 2')

            elif position_update == 'Backwards':
                player_position(0)

            elif position_update == 'Left':
                print('There Are Monsters In the Dark')

            elif position_update == 'Right':
                print('There Are Monsters In The Dark')

starting_room()

您正在调用
player\u position
,该函数不返回任何内容。相反,假设您希望跟踪玩家在
start\u room
功能中的当前位置,您将希望跟踪那里的位置

类似这样的情况:(注意-您需要添加更多代码来打破
循环,而
循环-此代码应该允许您跟踪pos)


player\u position
是一个不返回任何内容的函数。您需要使用变量跟踪位置,并在每次更改方向时进行更新。
def player_position(pos):
        position = pos
        if position == goliath.spawn:

            print('The Goliath Has Attacked!')

            if goliath.accuracy == 1:

                print('You Have Been Killed!')

            else:
                print('You Killed The Goliath!')

        else:
            print('Nothing Happens...')

def starting_room():
    pos = 0 #initialize the pos to 0
    while True:
        position_update = input('Enter A Direction: ')
        if pos == 1: #check to see if current pos is 1
            if position_update == 'Forwards':
                print('Room 2')
                #you may want to add "break" here to stop this while loop

            elif position_update == 'Backwards':
                pos = 0

            elif position_update == 'Left':
                print('There Are Monsters In the Dark')

            elif position_update == 'Right':
                print('There Are Monsters In The Dark')

        elif position_update == 'Forwards':
            pos = 1

        elif position_update == 'Backwards':
            pos = 3

        elif position_update == 'Left':
            pos = 4

        elif position_update == 'Right':
            pos = 2
        player_position(pos) #call the player_position function with the current pos

starting_room()