本文整理汇总了Python中WConio.getkey方法的典型用法代码示例。如果您正苦于以下问题:Python WConio.getkey方法的具体用法?Python WConio.getkey怎么用?Python WConio.getkey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WConio
的用法示例。
在下文中一共展示了WConio.getkey方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: selectToken
# 需要导入模块: import WConio [as 别名]
# 或者: from WConio import getkey [as 别名]
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
示例2: selectDestination
# 需要导入模块: import WConio [as 别名]
# 或者: from WConio import getkey [as 别名]
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
示例3: selectBoard
# 需要导入模块: import WConio [as 别名]
# 或者: from WConio import getkey [as 别名]
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)
示例4: menu
# 需要导入模块: import WConio [as 别名]
# 或者: from WConio import getkey [as 别名]
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]]
示例5:
# 需要导入模块: import WConio [as 别名]
# 或者: from WConio import getkey [as 别名]
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
示例6: getkey
# 需要导入模块: import WConio [as 别名]
# 或者: from WConio import getkey [as 别名]
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( )
示例7: printGraphics
# 需要导入模块: import WConio [as 别名]
# 或者: from WConio import getkey [as 别名]
# 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()
示例8: raw_getkey
# 需要导入模块: import WConio [as 别名]
# 或者: from WConio import getkey [as 别名]
def raw_getkey():
key = W.getkey()
if key in ('\r', '\n'):
key = 'enter'
return key