我写了一个curses代码:
import curses
import time
message = raw_input('Enter a word or phrase: ')
q, vertical, horizontal = -1, 1, 1
y, x = 0, 0
screen = curses.initscr()
screen.nodelay(1)
curses.noecho()
dims = screen.getmaxyx()
while q < 0:
q = screen.getch()
screen.clear()
screen.addstr(y, x, message)
y += vertical
x += horizontal
if y == dims[0]-1:
vertical = -1
elif y == 0:
vertical = 1
if x == dims[1]-len(message)-1:
horizontal = 1
elif x == 0:
horizontal = 1
time.sleep(0.06)
curses.endwin()
当我运行它时它工作正常,直到它到达屏幕的右侧,当它出现故障时。我对诅咒很新,所以我可能会错过一些东西。什么是代码问题?
答案 0 :(得分:1)
你会为此恨自己:),你只是在切换x方向时忘记了否定。它仍然试图向右移动并试图在屏幕外绘制错误。
...
if x == dims[1] - len(message) - 1:
horizontal = -1
...