0

我是 python 的初学者。

我需要帮助更新纸牌游戏的分数。

评分工作如下:

玩家 A 或 B 有对子: score += 1
玩家 A 向玩家 B(反之亦然)要一张牌,而玩家有: score += 1
玩家 B 没有,玩家 A 必须抽一张牌。如果平局后有对子: score += 2

我有逻辑,但我真的不知道如何将它连接在一起。

我尝试在我的函数中手动添加分数,但它变得混乱和复杂:(

我假设我必须为分数创建一个新函数并在我的其他函数中调用它们?

我会很感激指导,

谢谢!

4

1 回答 1

1

Here is some code to get you started:

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)    
于 2011-03-30T06:17:18.673 回答