如何解决python-curses没有注册instr
我正在写一个Doodle-jump终端游戏,我需要了解这个游戏玩家是否遇到障碍。为此,我使用 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,1) == "=":
stdscr.addstr(5,5,"Yes")
else:
stdscr.addstr(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
将返回a bytes object-python 3+中字节对象从不等于字符串(str
类型)
尝试:
if stdscr.instr(current_y+1,current_x,1) == b"=":
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。