【发布时间】:2022-12-15 12:34:09
【问题描述】:
基本上我只是尝试使用终端创建一个蛇游戏,不是因为它特别有趣,高效(我知道有很多更好的方法来做到这一点)而是习惯使用和理解 python 因为我只是一个初学者.
import keyboard
dirx = 1
diry = 0
x = 0
y = 0
a = ['-', '-', '-', '-', '-']
def getkey():
global x
keyboard.wait('d')
x +=1
while True:
# creates a constantly updating list, which will function as part of the game board
a[x] = 0
a[not x] = '-'
print('\r', a, end='')
getkey()
if x > 4:
x = 0
这是我到达的地方,我遇到了一些障碍,我可以让 0 继续前进,但让其余位置更新回“-”要困难得多,不是x 有点工作,但它在超过 0 后停止,我认为它不考虑更新的值,但我不确定。这可能是一个非常简单的解决方案,但我只是在学习,我无法弄清楚
【问题讨论】:
标签: python