Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. from board import board
  2. from sys import stdin
  3. from termios import tcgetattr as getat, tcsetattr as setat, TCSADRAIN
  4. from tty import setraw
  5.  
  6. class game:
  7.  
  8. def __init__(self, **kwargs):
  9. self.board = board() # p1, p2
  10. self.fd = stdin.fileno()
  11. self.old_settings = getat(self.fd)
  12. self.buffer = kwargs.get("key buffer", 4)
  13. if type(self.buffer) is not int or self.buffer < 4:
  14. self.buffer = 4
  15.  
  16.  
  17. def wait(self):
  18. keys = bytearray()
  19. while True:
  20. setraw(self.fd)
  21. keys.insert(0,stdin.read(1))
  22. setat(self.fd, TCSADRAIN, self.old_settings)
  23. #'h'=104, 'j'=106, 'k'=107, 'l'=108, 'd'=100, 'x1b'=27, '['=91
  24. if keys[0] == 104 or keys[0] == 68 and keys[2] == 27 and keys[1] == 91:
  25. print "left"
  26. elif keys[0] == 106 or keys[0] == 66 and keys[2] == 27 and keys[1] == 91:
  27. print "down"
  28. elif keys[0] == 107 or keys[0] == 65 and keys[2] == 27 and keys[1] == 91:
  29. print "up"
  30. elif keys[0] == 108 or keys[0] == 67 and keys[2] == 27 and keys[1] == 91:
  31. print "right"
  32. elif keys[0] == 3:
  33. break
  34. else:
  35. print repr(keys[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement