import threading, time
import sys
import random
from queue import Queue

MIN, MAX = 0, 100  # number range in which random integer is created
THRESHOLD = 15  # time given to a player


def countdown(n: int):
    '''Countdown function. From n to 0'''
    while n > 0:
	    sys.stderr.write(f'\n{n}')
	    time.sleep(1)
	    n -= 1
    sys.stderr.write(f'\nOVER')


def game():
    '''Represents the game. Must be executed in daemon'''
    num = random.randint(MIN, MAX)
    print(f'Game started. Enter your number (from {MIN} to {MAX})')
    while True:
        guess = int(input('Your guess: '))
        if guess > num:
            print(f'Wrong! {guess} is GREATER than the target')
        elif guess < num:
            print(f'Wrong! {guess} is SMALLER than the target')
        elif guess == num:
            print(f'You are RIGHT! {guess} is the number')
            break


def main():
    counter = threading.Thread(target=countdown, args=[THRESHOLD])
    daemon_game = threading.Thread(target=game, daemon=True)
    counter.start()
    daemon_game.start()


if __name__ == '__main__':
    main()