[英]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] = '@'
我希望單個玩家向上,向下,向左和向右移動。 我很迷失。 我是初學者,不知道從哪里開始。
從您的問題尚不清楚究竟發生了什么或應該繼續發生。
不過,從您對木板的參考來看,您可能希望跟蹤玩家的斧頭和斧頭坐標。 似乎現在只跟蹤一個維度,這相當於只能向左或向右移動。
您可能想研究Python的類( https://docs.python.org/2/tutorial/classes.html ),並為棋盤,播放器等定義一個類。 跟蹤什么是什么,什么地方在哪里會更容易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.