Skip to content

Commit

Permalink
Merge pull request #1 from ziemek99/shoot-the-moon
Browse files Browse the repository at this point in the history
Implement shooting the moon
  • Loading branch information
danielcorin authored Sep 15, 2021
2 parents ac83f58 + 8b89b42 commit 5b84c08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Hearts.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ def __init__(self):

def handleScoring(self):
p, highestScore = None, 0
for player in self.players:
if player.roundScore == 26:
p = player
player.roundScore = 0
break

if p is not None:
print p.name + " shot the moon!"
for player in self.players:
if player != p:
player.roundScore = 26
p = None

for player in self.players:
player.score += player.roundScore
player.roundScore = 0

print "\nScores:\n"
for player in self.players:
print player.name + ": " + str(player.score)
Expand Down Expand Up @@ -228,6 +245,7 @@ def playTrick(self, start):
def printPlayer(self, i):
p = self.players[i]
print p.name + "'s hand: " + str(p.hand)
print p.name + "'s round score: " + str(p.roundScore)

# print all players' hands
def printPlayers(self):
Expand Down
3 changes: 2 additions & 1 deletion Player.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def __init__(self, name, auto=False):
self.name = name
self.hand = Hand()
self.score = 0
self.roundScore = 0
self.tricksWon = []

def addCard(self, card):
Expand All @@ -30,7 +31,7 @@ def play(self, option='play', c=None, auto=False):


def trickWon(self, trick):
self.score += trick.points
self.roundScore += trick.points


def hasSuit(self, suit):
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Win all the hearts and the queen of spades, or none of these cards. Get as few p

* A player receives one point per heart and 13 points for the queen of spades.

* If a player has all of the points, he or she has "shot the moon" and all other players get 26 points (not yet implemented).
* If a player has all of the points, he or she has "shot the moon" and all other players get 26 points.

* The game ends when the first player gets to 100. The winner is the player with the fewest points.

Expand Down

0 comments on commit 5b84c08

Please sign in to comment.