本文整理汇总了Python中Card.score方法的典型用法代码示例。如果您正苦于以下问题:Python Card.score方法的具体用法?Python Card.score怎么用?Python Card.score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Card
的用法示例。
在下文中一共展示了Card.score方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Card [as 别名]
# 或者: from Card import score [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()
#.........这里部分代码省略.........