首页 > 解决方案 > 蛇游戏不工作我的算法有问题吗?

问题描述

    def move(self, increased):

        
        for x in range(len(self.list), -1, -1):

            if x == 0:
 
                if self.direction == "up":
                    self.list[0].y-=20
                elif self.direction == "down":
                    self.list[0].y+=20
                elif self.direction == "left":
                    self.list[0].x -=20
                elif self.direction == "right":
                    self.list[0].x +=20       
                break
            if x == len(self.list) and increased:
                print("hi")
                break
            else:
                self.list[x-1].x, self.list[x-1].y = self.list[x-2].x, self.list[x-2].y


这是我的代码,我的蛇看起来有点东西像这样。当我只添加 2 个块时它工作正常但我无法弄清楚我做错了什么,请告诉我我是如何成为一个白痴

标签: pythonpygame

解决方案


推荐阅读