python - 蛇游戏不工作我的算法有问题吗?
问题描述
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 个块时它工作正常但我无法弄清楚我做错了什么,请告诉我我是如何成为一个白痴
解决方案
推荐阅读
- javascript - 函数调用的左手边赋值如何在 JScript 中工作?
- python - 如何使用 tkinter 更新按键上的变量?
- python - boto 模块是访问 Heroku 应用程序中配置变量的唯一方法吗?
- django - 找不到无法重命名表的原因
- javascript - 自动完成区分大小写
- excel - 连续填充单元的选择和MAX、MIN、AVG的计算
- javascript - 在jquery中获取输入字段数组索引
- azure - 修正现有的 kql
- ruby - 如何在 XY 坐标的指定半径内搜索对象(没有宝石)?
- javascript - Firefox C# Selenium Can't set a value using sendKeys and JavaExecutor 似乎没有影响它