Last active
February 5, 2019 18:39
-
-
Save quantumjim/6ec331054606fc3d676a6bae2a506b78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import select | |
import sys | |
class TimeoutExpired(Exception): | |
pass | |
def timed_input (prompt, timeout): | |
sys.stdout.write(prompt) | |
sys.stdout.flush() | |
ready, _, _ = select.select([sys.stdin], [],[], timeout) | |
if ready: | |
return sys.stdin.readline().rstrip('\n') # expect stdin to be line-buffered | |
raise TimeoutExpired | |
def get_screen (inpt): | |
if inpt: | |
screen = "\n"*10+" v \n...........^..........." | |
else: | |
screen = "\n"*10+" \n...........X..........." | |
return screen | |
inpt = None | |
while True: | |
screen = get_screen(inpt) | |
inpt = timed_input(screen,2) | |
print(inpt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment