2011-03-30 67 views
0

我是一個Python初學者。更新紙牌遊戲的分數

我需要幫助更新紙牌遊戲的分數。

刻劃的工作原理如下:

播放機A或B具有一對:得分+ = 1
玩家A詢問玩家B(反之亦然),用於卡和該玩家有它:得分+ = 1
玩家B沒有它,玩家A必須抽牌。如果在抽籤後有一對:得分+ = 2

我有邏輯,但我真的不知道如何將它連接在一起。

我嘗試手動添加在我的職務分數,但它得到的混亂和複雜:(

我想我將不得不作出一個新的功能分數,並呼籲他們在我的其他功能?

我將不勝感激指導,

感謝信

+4

請發佈您已有的代碼,以便我們可以(a)更好地理解您嘗試實現的目標,以及(b)無需重寫您已完成的所有任務即可爲您提供幫助。 – Blair 2011-03-30 04:28:32

回答

1

下面是一些代碼,讓你開始:

class Player: 
    def hasPair(self): 
    haveIt = False 
    #write logic here to see if you have it 
    return haveIt 
    def hasCard(self,card): 
    haveIt = False 
    #write logic here to see if this player has the card 
    return haveIt 
    def drawCard(self): 
    #write logic here 
    pass 
    def ask(self,player,card): 
    return player.hasCard(card) 
    def increment_score(self,by=1): 
    self.score += by 

def updateScores(a,b,card):   
    if a.hasPair(): a.increment_score() 
    if b.hasPair(): b.increment_score() 
    if a.ask(b,card): 
    a.increment_score() 
    else: 
    a.drawCard() 
    if a.hasPair(): a.increment_score(2) 
    if b.ask(a,card): 
    b.increment_score() 
    else: 
    b.drawCard() 
    if b.hasPair(): b.increment_score(2)