本文整理汇总了Python中Deck.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Deck.draw方法的具体用法?Python Deck.draw怎么用?Python Deck.draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Deck
的用法示例。
在下文中一共展示了Deck.draw方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Deck [as 别名]
# 或者: from Deck import draw [as 别名]
#.........这里部分代码省略.........
i = 0
for rp in self.players:
if rp.playNo != '1':
rp.identity = rlst[i]
self.sendData("SetIdentity,"+rp.playNo+","+rp.identity, 0.2)
i += 1
def otherSelectHero(self):
nlst = self.getNoList(self.capacity)
for n in nlst:
self.sendData("SelectHero," + str(n) + self.selectHeroList(False), 0.2)
def handleReady(self, s):
playerid = ''
for rp in self.players:
if rp.username == s[1]:
playerid = int(rp.prepareNo) - 1
self.isReady[playerid] = True
if self.allReady():
self.setRoomSize()
self.setNo()
self.chooseLord()
self.chooseOther()
self.lordSelectHero()
def allChoosedHero(self):
for i in range(self.capacity):
if self.choosedHero[i+1] == False:
return False
return True
def sendAllInitialCard(self):
for i in range(self.capacity):
self.sendData("SendCards,No,"+str(i+1)+",4"+self.deck.draw(4), 0.2)
self.sendData("SendCards,No,1,3,73,98,98", 0.2)
self.sendData("SendCards,No,2,3,72,99,99", 0.2)
def handleChooseHero(self, s):
self.sendData("ChoosedHero,"+s[1]+","+s[2], 0.2)
self.choosedHero[int(s[1])] = True
print(self.choosedHero)
if s[1] == '1':
self.otherSelectHero()
if self.allChoosedHero():
self.sendAllInitialCard()
self.sendData("RoundStart,1", 0.2)
self.nowRoundPlayer = "1"
def handleRoundStartOver(self, s):
self.sendData("Start,"+s[1], 0.2)
def handleStartOver(self, s):
self.sendData("Judge,"+s[1], 0.2)
def handleJudgeOver(self, s):
self.sendData("Draw,"+s[1], 0.2)
def handleDrawOk(self, s):
self.sendData("SendCards,Draw,"+s[1]+",2"+self.deck.draw(2), 0.2)
def handleDrawOver(self, s):
self.sendData("Play,"+s[1], 0.2)
def showCardsAmazingGrace(self):
self.sendData("ShowCards,Grace,"+str(self.capacity)+self.deck.draw(self.capacity), 0.2)
def showCardsAmazingGraceOff(self):
示例2: __init__
# 需要导入模块: import Deck [as 别名]
# 或者: from Deck import draw [as 别名]
class Pondukapall:
def __init__(self):
self.board = [] #cards on the board(hand)
self.on = True
self.deck = Deck() #the deck
self.deck.shuffle()
for i in range(0,4):
self.board.append(self.deck.draw())
self.beginDisplay()
self.redisplay()
def checkSuit(self):
if len(self.board) < 4:
print "not enough cards"
return
if self.board[-1][-1] == self.board[-4][-1]: #if last character in last and fourth last is same
self.board.pop(len(self.board)-2)
self.board.pop(len(self.board)-2)
else:
print "the last and fouth last cards are not the same suit\n"
self.checkWinCondition()
self.redisplay()
def checkRank(self):
if len(self.board) < 4:
print "not enough cards"
return
if self.board[-4][0] == self.board[-1][0]:
if len(self.board[-4]) == 3 or self.board[-4][1] == self.board[-1][1]:
for i in range(0,4):
self.board.pop()
else:
print "\n the last and fourth last cards are not the same rank\n"
self.checkWinCondition()
self.redisplay()
def draw(self):
if len(self.deck.deck) > 0:
if len(self.board) > 3:
if self.board[-4][0] == self.board[-1][0] or self.board[-1][-1] == self.board[-4][-1]:
print "you missed one LOSER, now live with it"
self.board.append(self.deck.deck.pop())
else:
print "deck over"
self.checkWinCondition()
self.redisplay()
def checkWinCondition(self):
if len(self.deck.deck) <= 0:
self.on = False
if len(self.board) >= 4:
if (self.board[-4][0] == self.board[-1][0] or self.board[-1][-1] == self.board[-4][-1]):
return
if len(self.board) <= 2:
print "Game Over: YOU WIN!!\n"
print "type restart to start over or exit to quit"
else:
print "Game Over: You Lose"
print "type restart to start over or exit to quit"
return self.on
def redisplay(self):
print "\n"
print map(str, self.board)
print "\n"
def beginDisplay(self):
print "Welcome to Panda Solitaire\n"
print "Type help for controlls"
def helpDisplay(self):
print "insert commands to play the game\n"
print "d or draw: will draw a card\n"
print "s or suit: will check the last and fourth last cards for same suit\n"
print "r or rank: will check the lst and fourth last cards for the same rank\n"
print "exit or quit: will end the game\n"
print "help: will bring up this help text, but you know that allready"
print "restart: will restart your game"
self.redisplay()
示例3: __init__
# 需要导入模块: import Deck [as 别名]
# 或者: from Deck import draw [as 别名]
class Pyramid:
def __init__(self, difficulty):
self.newGame(difficulty)
def newGame(self, difficulty):
self.deck = Deck() # stokkurinn
self.pyramid = self.buildPyr() # hluti af stokknum verður pýramíddi
self.drawDeck = deque() # fyrri stokkurinn af spilum
self.activeDeck = deque() # seinni stokkurinn af spilum
self.discardPile = deque() # spilin sem að hafa verið tekin út
for i in range(0, len(self.deck.cards)):
self.drawDeck.append(self.deck.draw())
self.score = 0
self.difficulty = difficulty # því hærri tala því auðveldari er leikurinn
self.initPyramid = copy.deepcopy(self.pyramid) # state savefyrir restart same game
for i in range(len(self.pyramid)):
self.initPyramid.append(self.pyramid[i])
self.initDrawDeck = copy.deepcopy(self.drawDeck) # state savefyrir restart same game
for i in range(len(self.drawDeck)):
self.initDrawDeck.append(self.drawDeck[i])
self.initDifficulty = self.difficulty
self.tempPyramid = copy.deepcopy(self.pyramid)
self.tempDrawDeck = deque()
self.tempDiscardpile = deque()
self.tempScore = 0
self.startTime = time.ctime()
# byggir píramídann sjálfann sem lista af listum
# hvert stak í listunum inniheldur spil og hnit fyrir foreldri og börn sbr. tré
def buildPyr(self):
pyr = [] # tímabundin breyta
for i in range(0, 7): # sex hæðir
thisLevel = []
for j in range(0, i + 1):
nxtCard = self.deck.draw()
pyrSpotSpecs = [nxtCard, self.parents(i, j), self.children(i, j), True] # hver eind
thisLevel.append(pyrSpotSpecs)
pyr.append(thisLevel)
return pyr
def saveState(self):
self.tempPyramid = copy.deepcopy(self.pyramid)
self.tempDrawDeck = copy.deepcopy(self.drawDeck)
self.tempDiscardpile = copy.deepcopy(self.discardPile)
self.tempActiveDeck = copy.deepcopy(self.activeDeck)
self.tempDifficulty = self.difficulty
self.tempScore = self.score
# need to save score state
def returnToInit(self):
self.drawDeck = deque()
self.activeDeck = deque()
self.pyramid = []
self.pyramid = copy.deepcopy(self.initPyramid)
self.drawDeck = copy.deepcopy(self.initDrawDeck)
self.activeDeck = deque()
self.difficulty = self.initDifficulty
self.discardPile = deque()
self.score = 0
def Undo(self):
self.pyramid = copy.deepcopy(self.tempPyramid)
self.drawDeck = copy.deepcopy(self.tempDrawDeck)
self.discardPile = copy.deepcopy(self.tempDiscardpile)
self.activeDeck = copy.deepcopy(self.tempActiveDeck)
self.difficulty = self.tempDifficulty
self.score = self.tempScore
def checkWin(self):
if self.pyramid[0][0][3] == True:
return False
return True
# dregur spil úr bunka og setur það í activeDeck
# þá sést næsta spil í drawDeck
def drawDeckdraw(self):
self.saveState()
if len(self.drawDeck) > 1: # ef við eigum spil eftir í drawDeck
self.activeDeck.append(self.drawDeck.popleft())
print len(self.drawDeck)
elif self.difficulty > 0: # ef að við meigum nota spilin aftur
# self.drawDeck = deque()
self.activeDeck.reverse()
self.drawDeck = copy.deepcopy(self.activeDeck)
self.activeDeck = deque()
self.drawDeckdraw()
# for i in range(len(activeDeck)):
# drawDeck.append(self.activeDeck.pop())
self.difficulty = self.difficulty - 1
else:
return -1
# hnit foreldra: -1 er enginn
def parents(self, i, j):
if i == 0:
#.........这里部分代码省略.........