本文整理匯總了Python中Card.start方法的典型用法代碼示例。如果您正苦於以下問題:Python Card.start方法的具體用法?Python Card.start怎麽用?Python Card.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Card
的用法示例。
在下文中一共展示了Card.start方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import Card [as 別名]
# 或者: from Card import start [as 別名]
class App:
def __init__(self, interface):
self.player = Card()
self.computer = Card()
self.pscore = 0 #player's score
self.cscore = 0 #computer's score
self.interface = interface
self.hit = 0 # times of player's hitme
def run(self):
#start game
if self.interface.wantToPlay():
self.player.start()
self.computer.start()
self.interface.setPlayerScore(self.pscore)
self.interface.setComputerScore(self.cscore)
self.interface.computergetCards()
self.interface.playergetCards("%s.gif"%(self.player.showcard(1)),"%s.gif"%(self.player.showcard(2)))
winsound.PlaySound("deal.wav",winsound.SND_FILENAME)
self.interface.setMessage("Do you want more card?")
else:
self.interface.close()
def Hit1(self):
# Offer first hitme
if self.interface.wantToHit():
self.hit += 1
self.player.get1Card()
self.interface.Pget1MoreCard("%s.gif"%(self.player.showcard(3)))
winsound.PlaySound("deal.wav",winsound.SND_FILENAME)
else:
self.ComputerHit()
def Hit2(self):
if self.interface.wantToHit() and self.hit == 1:
self.hit += 1
self.player.get2Card()
self.interface.Pget2MoreCard("%s.gif"%(self.player.showcard(4)))
winsound.PlaySound("deal.wav",winsound.SND_FILENAME)
self.ComputerHit()
else:
self.ComputerHit()
def result(self):
#show the winner and loser
winsound.PlaySound("untap.wav",winsound.SND_FILENAME)
if self.player.score() <= 21 and self.computer.score()<=21:
if self.player.score() - self.computer.score() == 0:
self.interface.setMessage("Well, it's a Tie")
self.interface.ShowResult("%s.gif"%(self.computer.showcard(1)),"%s.gif"%(self.computer.showcard(2)),"%s.gif"%(self.computer.showcard(3)),"%s.gif"%(self.computer.showcard(4)))
winsound.PlaySound("laugh.wav",winsound.SND_FILENAME)
self.pscore += 1
self.cscore += 1
elif self.player.score() - self.computer.score() > 0:
self.interface.setMessage("Yeah, You win")
self.interface.ShowResult("%s.gif"%(self.computer.showcard(1)),"%s.gif"%(self.computer.showcard(2)),"%s.gif"%(self.computer.showcard(3)),"%s.gif"%(self.computer.showcard(4)))
winsound.PlaySound("applause.wav",winsound.SND_FILENAME)
self.pscore += 3
self.cscore += 0
else:
self.interface.setMessage("Oops, You lose")
self.interface.ShowResult("%s.gif"%(self.computer.showcard(1)),"%s.gif"%(self.computer.showcard(2)),"%s.gif"%(self.computer.showcard(3)),"%s.gif"%(self.computer.showcard(4)))
winsound.PlaySound("cryout.wav",winsound.SND_FILENAME)
self.pscore += 0
self.cscore += 3
elif self.player.score() > 21:
self.interface.setMessage("Oops, You lose")
self.interface.ShowResult("%s.gif"%(self.computer.showcard(1)),"%s.gif"%(self.computer.showcard(2)),"%s.gif"%(self.computer.showcard(3)),"%s.gif"%(self.computer.showcard(4)))
winsound.PlaySound("cryout.wav",winsound.SND_FILENAME)
self.pscore += 0
self.cscore += 3
elif self.computer.score() >21:
self.interface.setMessage("Yeah, You win")
self.interface.ShowResult("%s.gif"%(self.computer.showcard(1)),"%s.gif"%(self.computer.showcard(2)),"%s.gif"%(self.computer.showcard(3)),"%s.gif"%(self.computer.showcard(4)))
winsound.PlaySound("applause.wav",winsound.SND_FILENAME)
self.pscore += 3
self.cscore += 0
elif self.player.score() > 21 and self.computer.score() >21:
self.interface.setMessage("Well, it's a Tie")
self.interface.ShowResult("%s.gif"%(self.computer.showcard(1)),"%s.gif"%(self.computer.showcard(2)),"%s.gif"%(self.computer.showcard(3)),"%s.gif"%(self.computer.showcard(4)))
winsound.PlaySound("laugh.wav",winsound.SND_FILENAME)
self.pscore += 1
self.cscore += 1
self.interface.setPlayerScore(self.pscore)
self.interface.setComputerScore(self.cscore)
#self.interface.ShowResult("%s.gif"%(self.computer.showcard(1)),"%s.gif"%(self.computer.showcard(2)),"%s.gif"%(self.computer.showcard(3)),"%s.gif"%(self.computer.showcard(4)))
def ComputerHit(self):
# #This is the step that simulate the computer thinking # #
if 1000*random.random() < 1000*self.computer.score()/21.00:
self.computer.get1Card()
self.interface.Cget1MoreCard()
#.........這裏部分代碼省略.........