def selectToken (gameArray,arrows,player): WConio.gotoxy(0,23) print "{0:^79}".format("Select one of your tokens to initiate a move.") k=None player=1 while k<>"q": printCursor(gameArray,cursor) if k =="u": printUnicode() if k =="a": printAscii() k = WConio.getkey() if k in arrows[0]: WConio.gotoxy(cursor[0]*2+1+40-len(gameArray),cursor[1]*2+1) printGrid(gameArray) #'erase' cursor icon d=arrows[0].index(k) cursor[0]=(cursor[0]+arrows[1][d])%len(gameArray) cursor[1]=(cursor[1]+arrows[2][d])%len(gameArray[0]) printCursor(gameArray,cursor) if k == " ":# when 'spacebar' entered if ord(gameArray[cursor[0]][cursor[1]])<>player: WConio.gotoxy(0,21) print "{0:^79}".format("Player {0}, you can only select a space that is already yours.".format(player)) else: clearLines() WConio.gotoxy(0,21) print "{0:^79}".format("Token selected.") #print " "*79 gameArray = selectDestination(gameArray,cursor,player,arrows) break
def selectDestination(gameArray,cursor,player,arrows): k=None oldCursor = cursor[:] while k<>"q": k = WConio.getkey() if k in arrows[0]: #WConio.gotoxy(cursor[0]*2+1+40-len(gameArray),cursor[1]*2+1) printGrid(gameArray) #'erase' cursor icon d=arrows[0].index(k) cursor[0]=(cursor[0]+arrows[1][d]) if cursor[0]<0 or cursor[0]>len(gameArray) or abs(cursor[0]-oldCursor[0])>2: cursor[0]=(cursor[0]-arrows[1][d]) cursor[1]=(cursor[1]+arrows[2][d]) if cursor[1]<0 or cursor[1]>len(gameArray[0]) or abs(cursor[1]-oldCursor[1])>2: cursor[1]=(cursor[1]-arrows[2][d]) printCursor(gameArray,oldCursor) printCursor2(gameArray,cursor) if k == " ":# when 'spacebar' entered if ord(gameArray[cursor[0]][cursor[1]])<>250: WConio.gotoxy(0,21) print "{0:^79}".format("Player {0}, you can only move to empty spaces".format(player)) else: finalizeMove(gameArray,oldCursor,cursor,player) break return gameArray
def selectBoard(arrows): WConio.clrscr() k=None comment = None size=[5,5] gameArray=makeArray(size) WConio.gotoxy(0,21) print "{0:^79}".format("Hit the spacebar to accept this board.") while k<>" ": k = WConio.getkey() if k in arrows[0]: d=arrows[0].index(k) size[0]=(size[0]+arrows[1][d]*2) size[1]=(size[1]+arrows[2][d]*2) if size[0]>21: size[0]=21 comment = "That's as wide as you can go." elif size[0]<5: size[0]=5 comment = "That's as narrow as you can go." elif size[1]>9: size[1]=9 comment = "That's as tall as you can go." elif size[1]<5: size[1]=5 comment = "That's as short as you can go." else: comment = "" gameArray=makeArray(size) WConio.gotoxy(0,21) print "{0:^79}".format("{} {}".format(size,comment)) if size[0]*size[1]>50: print "{0:^79}".format("This size board will get some random tokens thrown on.") print "{0:^79}".format(" Hit the spacebar to accept this board.") #init pieces gameArray[0][0]=chr(1) gameArray[0][len(gameArray[0])-1]=chr(2) gameArray[len(gameArray)-1][0]=chr(2) gameArray[len(gameArray)-1][len(gameArray[0])-1]=chr(1) if len(gameArray)*len(gameArray[0])>50: c=0 WConio.gotoxy(0,21) while c< len(gameArray)*len(gameArray[0])-40: m=randint(0,len(gameArray)-1) n=randint(0,len(gameArray[0])-1) p=randint(0,len(gameArray)-1) q=randint(0,len(gameArray[0])-1) if gameArray[m][n]==chr(250) and gameArray[p][q]==chr(250) and m<>p: gameArray[m][n]=chr(1) gameArray[p][q]=chr(2) c=c+2 clearLines() return (gameArray)
def menu(options, deletepreviouslines=0): _sel() _otr() # Initialize terminal conditions home = WConio.wherey() # Gets original y coordinate startup = home - deletepreviouslines - 2 y = 0 draw(options, y) multiple = [] escolha = '' while escolha != '\r': #\r = enter escolha = WConio.getkey() if escolha == 'up': if y != 0: y-=1 if escolha == 'down': if y != len(options)-1: y+=1 if escolha == '+': multiple.append(options[y]) if options[y][-1] != '+': options[y] += '+' # To do: add option to remove from list WConio.gotoxy(0, home) draw(options,y) _otr() for i in range(WConio.wherey(), startup, -1): WConio.gotoxy(0, i) sys.stdout.write(' '*WConio.gettextinfo()[8]) WConio.gotoxy(0, startup) if len(multiple)>0: return multiple else: return [options[y]]
import config v_cmd_history = [] v_cmd_history_current = 0 # append command search path for v_path in config.cmd_search_path: sys.path.append(os.getcwd() + v_path) console.settitle(config.cli_prompt + ' ' + config.cli_version) while True: b_restart = False sys.stdout.write(config.cli_prompt + '>') v_cmd_buf = [] while True: v_key = console.getkey() if v_key == None: continue if (len(v_key) == 1) and (v_key >= '\x20') and (v_key < '\x7F'): sys.stdout.write(v_key) v_cmd_buf.append(v_key) else: # move cursor left if v_key == 'left': # do nothing pass # move cursor right elif v_key == 'right': # do nothing
import config v_cmd_history = [] v_cmd_history_current = 0 # append command search path for v_path in config.cmd_search_path: sys.path.append(os.getcwd() + v_path) console.settitle(config.cli_prompt + ' ' + config.cli_version) while True: b_restart = False sys.stdout.write(config.cli_prompt + '>') v_cmd_buf = [] while True: v_key = console.getkey() if v_key == None: continue if (len(v_key) == 1) and (v_key >= '\x20') and (v_key < '\x7F'): sys.stdout.write(v_key) v_cmd_buf.append(v_key) else: # move cursor left if v_key == 'left': # do nothing pass # move cursor right elif v_key == 'right': # do nothing
""" from pynput.keyboard import Key, Controller keyboard = Controller() # Press and release space keyboard.press(Key.space) keyboard.release(Key.space) # Type a lower case A; this will work even if no key on the # physical keyboard is labelled 'A' keyboard.press('a') keyboard.release('a') # Type two upper case As keyboard.press('A') keyboard.release('A') with keyboard.pressed(Key.shift): keyboard.press('a') keyboard.release('a') import msvcrt msvcrt.putch("s") """ import WConio an = WConio.getkey() print an
def getkey( ) : """Renvoie la touche ou la chaine de caractère saisie par l'utilisateur""" if sys.flags.interactive == 1 : # en execfile return raw_input() else : # en WConio return WConio.getkey( )
def _conio_getkey(self): import WConio #pylint: disable = import-error return WConio.getkey()
# Create Game board = lib2048.Game(4,4) board.set() # Prints the graphics to the console def printGraphics(matrix): s = [[str(e) for e in row] for row in matrix] lens = [max(map(len, col)) for col in zip(*s)] fmt = '\t'.join('{{:{}}}'.format(x) for x in lens) table = [fmt.format(*row) for row in s] print '\n'.join(table) # Enter input loop key = ' ' while key != 'q': # Print the game board clear() print "2048.py (Use arrow keys. Enter 'q' to quit.)" printGraphics(board.grid) # Get the key press key = WConio.getkey() if key == 'up': board.shiftUp() elif key == 'down': board.shiftDown() elif key == 'left': board.shiftLeft() elif key == 'right': board.shiftRight()
def raw_getkey(): key = W.getkey() if key in ('\r', '\n'): key = 'enter' return key