Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from board import board
- from sys import stdin
- from termios import tcgetattr as getat, tcsetattr as setat, TCSADRAIN
- from tty import setraw
- class game:
- def __init__(self, **kwargs):
- self.board = board() # p1, p2
- self.fd = stdin.fileno()
- self.old_settings = getat(self.fd)
- self.buffer = kwargs.get("key buffer", 4)
- if type(self.buffer) is not int or self.buffer < 4:
- self.buffer = 4
- def wait(self):
- keys = bytearray()
- while True:
- setraw(self.fd)
- keys.insert(0,stdin.read(1))
- setat(self.fd, TCSADRAIN, self.old_settings)
- #'h'=104, 'j'=106, 'k'=107, 'l'=108, 'd'=100, 'x1b'=27, '['=91
- if keys[0] == 104 or keys[0] == 68 and keys[2] == 27 and keys[1] == 91:
- print "left"
- elif keys[0] == 106 or keys[0] == 66 and keys[2] == 27 and keys[1] == 91:
- print "down"
- elif keys[0] == 107 or keys[0] == 65 and keys[2] == 27 and keys[1] == 91:
- print "up"
- elif keys[0] == 108 or keys[0] == 67 and keys[2] == 27 and keys[1] == 91:
- print "right"
- elif keys[0] == 3:
- break
- else:
- print repr(keys[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement