当前位置: 首页>>代码示例>>Python>>正文


Python Card.get1Card方法代码示例

本文整理汇总了Python中Card.get1Card方法的典型用法代码示例。如果您正苦于以下问题:Python Card.get1Card方法的具体用法?Python Card.get1Card怎么用?Python Card.get1Card使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Card的用法示例。


在下文中一共展示了Card.get1Card方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import Card [as 别名]
# 或者: from Card import get1Card [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()
#.........这里部分代码省略.........
开发者ID:ethanhan2014,项目名称:BlackJack,代码行数:103,代码来源:blackjackapp.py


注:本文中的Card.get1Card方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。