倒计时游戏

import time
import threading
begin = False
def numCounter():
    num = 60
    global begin
    while True:
        if begin:
            num = num -1
            print(f'num={num}, begin={begin}')
            time.sleep(1)
            if num<=0:
                num = 60
        else:
            pass

def keyDectect():
    # TODO:need to be revised by using the threading lock
    global begin
    while True:
        key = input()
        if key == 'b':
            begin = True
        elif key == 't':
            begin = False
        else:
            print('wrong input..')


if __name__ == '__main__':
    t1 = threading.Thread(target=numCounter)
    t2 = threading.Thread(target=keyDectect)
    t1.setDaemon(False)
    t2.setDaemon(False)
    t1.start()
    t2.start()

 

你可能感兴趣的:(游戏,java,html)