Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何让玩家移动一次,然后在到达';瓷砖';_Python - Fatal编程技术网

Python 如何让玩家移动一次,然后在到达';瓷砖';

Python 如何让玩家移动一次,然后在到达';瓷砖';,python,Python,class TileModel: pixel = 64 gap = 5 x1 = 400 x2 = x1 + pixel + gap x3 = x2 + pixel + gap x4 = x3 + pixel + gap x5 = x4 + pixel + gap x6 = x5 + pixel + gap x7 = x6 + pixel + gap x8 = x7 + pixel + gap x9 = x8 + pixel + gap x10 = x9 + pixel + gap y1 = 1

class TileModel:
pixel = 64
gap = 5
x1 = 400
x2 = x1 + pixel + gap
x3 = x2 + pixel + gap
x4 = x3 + pixel + gap
x5 = x4 + pixel + gap
x6 = x5 + pixel + gap
x7 = x6 + pixel + gap
x8 = x7 + pixel + gap
x9 = x8 + pixel + gap
x10 = x9 + pixel + gap
y1 = 100
y2 = y1 + pixel + gap
y3 = y2 + pixel + gap
y4 = y3 + pixel + gap
y5 = y4 + pixel + gap
y6 = y5 + pixel + gap
y7 = y6 + pixel + gap
y8 = y7 + pixel + gap
y9 = y8 + pixel + gap
y10 = y9 + pixel + gap
xCoords = (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)
yCoords = (y1, y2, y3, y4, y5, y6, y7, y8, y9, y10)

我在做一些类似棋盘游戏的东西。我想让它像国际象棋一样移动,不经常移动。我定义了tiles的x和y坐标,并将它们放在xCoords和yCoords元组中。我已经有了这样的东西,如果玩家达到了一个磁贴的x坐标,它就会停止。问题是它在那之后不会移动,因为if条件始终为True。当速度达到一个平铺时,我如何只否定一次速度?

您可能需要缩进代码,特别是对于python。已经这样做了,我在想,如果条件满足,是否有类似于执行一行代码的事情。在这种情况下,如果玩家到达互动程序,if语句将持续出现,因此您无法移动
def game():
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        global running
        running = False
    for i in TileModel.xCoords:
        if player.x == i:
          ` player.xChange = 0
    if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_a:
             player.xChange += -10
        elif event.key == pygame.K_w:
            player.yChange += -10
        elif event.key == pygame.K_d:
            player.xChange += 10
        elif event.key == pygame.K_s:
            player.yChange += 10