简体   繁体   中英

Python player movement

def playerMove (board,player):
    userInput = input("Enter a direction NSWE: ").upper()
    if userInput == "N":
        if (player == 0):
            board[player] = '.'
            player += 1
            board[player] = '@'
    elif userInput == "S":

        if (player(board)-1):
            board[player] = '.'
            player += 1
            board[player] = '@'
    elif userInput == "E":

        if (player < len(board)-1):
            board[player] = '.'
            player += 1
            board[player] = '@'
    elif userInput == "W":

        if (player['x'] > 0):
            board[player] = '.'
            player -= 1
            board[player] = '@'

I want the single player to move up, down, left,and right. I am so lost. I am a beginner and I do not know where to begin.

It isn't clear from your question what exactly is going on, or supposed to go on.

From your references to a board though, you might want to keep track of ax and y coordinate for your player. It seems there's just the one dimension being tracked right now, which would equate to only being able to move left or right.

You might want to look into classes for Python ( https://docs.python.org/2/tutorial/classes.html ) and define a class for the board, for the player, and so on. It'll be easier to keep track of what's what, and where's where.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM