我正在用pygame编程一个基于回合的策略,比如Fire-symbol,Python中的游戏,但是我遇到了玩家移动的问题。它的工作方式是,你选择一个球员,它会显示所有允许的移动,以蓝色突出显示,但我的问题是,我有一个问题,提出一个清单,所有可能的移动。在
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))
因为我不知道你在想什么,我将在以下假设下继续:
findTileLetter(x, y)
告诉我(x, y)
处的正方形是否可以通过。也就是说,它告诉我一个单位是否可以通过或结束他们在广场上的回合。在PLAYERDISTANCE[unit] + 1
次。每一步都可以上、下、左或右。不允许使用斜踏步,但必须通过向左和向上跨步来完成。在考虑到这一点,我们注意到
迭代}循环中的元素的步进。因此,你忽略了潜在的目的地广场。在
currentNewSpots
的一个元素,因此每一个x
循环都会忽略前面x
中最后一个添加到{换行
^{pr2}$修复此问题。在
此外,您在
y
循环中的delta-y测试并不完全正确:工作测试代码如下。}定义了我们的搜索位置。在每一步之后,我们将地图输出到stdout,说明到目前为止我们找到了哪些方块。在
grid
定义了一个瓷砖的世界:0
瓷砖是不可通行的,而1
瓷砖是可以通行的。MY_X
和{相关问题 更多 >
编程相关推荐