开发者

updating score in card game

I am a total beginner with python.

I need help updating the score of a card game.

The scoring works as follows:

Player A or B has a pair: score += 1

Player A asks Player B (vice versa) for a card and that player has it: score += 1

Player B doesn't have it, Pl开发者_Go百科ayer A has to draw a card. If there is pair after draw: score += 2

I have the logic down but I don't really know how to connect it together.

I tried manually adding the scores in my functions, but it get's messy and complicated :(

I assume I would have to make a new function for the score and call them in my other functions?

I would appreciate the guidance,

Thank-you!


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)    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜