1

我正在编写一个涂鸦跳跃终端游戏,我需要知道玩家是否遇到了障碍物。为此,我使用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)
4

1 回答 1

1

stdscr.instr将返回一个字节对象——字节对象永远不等于strpython 3+中的字符串(类型)

尝试:

        if stdscr.instr(current_y+1, current_x,1) == b"=":
于 2020-09-20T19:11:30.053 回答