python-curses 没有注册 instr()
python-curses doesn't register instr()
我正在编写一个涂鸦跳跃终端游戏,我需要知道玩家是否撞到了障碍物。为此,我使用 instr() 函数来告诉我是否遇到了障碍物。但它没有注册,而且在调试期间它也没有激活 if 子句。这是我的播放功能的 python-代码(奇怪的字符串是播放器):
def play(difficulty, resize_w, resize_h):
playing = True
current_x, current_y = 10, resize_h//2
env = create_env(resize_h, resize_w)
counter = 0
while playing:
counter += 1
stdscr.clear()
print_env(env,counter)
stdscr.refresh()
stdscr.addstr(current_y,current_x,"o/00\o")
if stdscr.instr(current_y+1, current_x,1) == "=":
stdscr.addstr(5,5,"Yes")
else:
stdscr.addstr(5,5,"NO")
stdscr.timeout(60)
inp = stdscr.getch()
if inp == curses.KEY_LEFT and current_x > 0:
current_x -= 2
move_left(current_x, current_y)
elif inp == curses.KEY_RIGHT and current_x < (resize_w-6):
current_x += 2
move_right(current_x, current_y)
stdscr.instr
will return a bytes object -- bytes objects are never equal to strings (str
type) in python 3+
尝试:
if stdscr.instr(current_y+1, current_x,1) == b"=":
我正在编写一个涂鸦跳跃终端游戏,我需要知道玩家是否撞到了障碍物。为此,我使用 instr() 函数来告诉我是否遇到了障碍物。但它没有注册,而且在调试期间它也没有激活 if 子句。这是我的播放功能的 python-代码(奇怪的字符串是播放器):
def play(difficulty, resize_w, resize_h):
playing = True
current_x, current_y = 10, resize_h//2
env = create_env(resize_h, resize_w)
counter = 0
while playing:
counter += 1
stdscr.clear()
print_env(env,counter)
stdscr.refresh()
stdscr.addstr(current_y,current_x,"o/00\o")
if stdscr.instr(current_y+1, current_x,1) == "=":
stdscr.addstr(5,5,"Yes")
else:
stdscr.addstr(5,5,"NO")
stdscr.timeout(60)
inp = stdscr.getch()
if inp == curses.KEY_LEFT and current_x > 0:
current_x -= 2
move_left(current_x, current_y)
elif inp == curses.KEY_RIGHT and current_x < (resize_w-6):
current_x += 2
move_right(current_x, current_y)
stdscr.instr
will return a bytes object -- bytes objects are never equal to strings (str
type) in python 3+
尝试:
if stdscr.instr(current_y+1, current_x,1) == b"=":