我正在使用 pygame 在 Python 中编写基于回合的策略,例如 Fire Emblem,但我遇到了玩家移动的问题。它的工作方式是您选择一个玩家,它会向您显示以蓝色突出显示的所有允许的移动,但我的问题是我在列出所有可能移动的列表时遇到问题。
def showPerson(tilex, tiley, personAtTile):
global ALLOWEDMOVES
ALLOWEDMOVES = []
prepare = {k:v for v,k in PLAYERSPOSITION.items()}
z = PLAYERDISTANCE[personAtTile]
#get all coords for the possible moves
currentNewSpots = []
oldSpots = []
a = PLAYERSPOSITION[personAtTile][0]
b = PLAYERSPOSITION[personAtTile][1]
c = a + 1
test = findTileLetter(c, b)
if test:
currentNewSpots.append((c, b))
ALLOWEDMOVES.append((c, b))
c = a -1
test = findTileLetter(c, b)
if test:
currentNewSpots.append((c, b))
ALLOWEDMOVES.append((c, b))
c = b + 1
test = findTileLetter(a, c)
if test:
currentNewSpots.append((a, c))
ALLOWEDMOVES.append((a, c))
c = b - 1
test = findTileLetter(a, c)
if test:
currentNewSpots.append((a, c))
ALLOWEDMOVES.append((a, c))
for x in range(PLAYERDISTANCE[prepare[(tilex, tiley)]]):
for y in range(len(currentNewSpots) - 1):
a = currentNewSpots[y][0]
b = currentNewSpots[y][1]
c = a + 1
test = findTileLetter(c, b)
if test and ((c, b)) not in ALLOWEDMOVES:
currentNewSpots.append((c, b))
ALLOWEDMOVES.append((c, b))
c = a -1
test = findTileLetter(c, b)
if test and ((c, b)) not in ALLOWEDMOVES:
currentNewSpots.append((c, b))
ALLOWEDMOVES.append((c, b))
c = b + 1
test = findTileLetter(a, c)
if test and ((c, b)) not in ALLOWEDMOVES:
currentNewSpots.append((a, c))
ALLOWEDMOVES.append((a, c))
c = b - 1
test = findTileLetter(a, c)
if test and ((c, b)) not in ALLOWEDMOVES:
currentNewSpots.append((a, c))
ALLOWEDMOVES.append((a, c))