简体   繁体   English

Python播放器运动

[英]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. 您可能想研究Python的类( https://docs.python.org/2/tutorial/classes.html ),并为棋盘,播放器等定义一个类。 It'll be easier to keep track of what's what, and where's where. 跟踪什么是什么,什么地方在哪里会更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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