diff --git a/play.py b/play.py index a8e683c..373451b 100644 --- a/play.py +++ b/play.py @@ -3,12 +3,19 @@ from yahtzee_goals import ( GoalOnes, GoalTwos, GoalThrees, + GoalFours, + GoalThreeOfAKind, + GoalYahtzee, + ) goals = [ GoalOnes(), GoalTwos(), GoalThrees(), + GoalFours(), + GoalThreeOfAKind(), + GoalYahtzee(), ] game = Yachtzee(goals) diff --git a/yahtzee_goals.py b/yahtzee_goals.py index fce4e5a..7ee7ae3 100644 --- a/yahtzee_goals.py +++ b/yahtzee_goals.py @@ -43,3 +43,58 @@ class GoalThrees: if die.face == 3: total += 3 return total + +class GoalFours: + "Four points for each four" + used = False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Fours ({potential_score})" + + def score(self, dice): + total = 0 + for die in dice: + if die.face == 4: + total += 4 + return total + +class GoalThreeOfAKind: + "add all dice, if all three dice have the same number" + used = False + def is_three_of_a_kind(self, dice): + if sum([d.face == dice[0].face for d in dice]) == 3: + return True + if sum([d.face == dice[1].face for d in dice]) == 3: + return True + if sum([d.face == dice[2].face for d in dice]) == 3: + return True + return False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Three of a kind ({potential_score})" + + def score(self, dice): + total = 0 + if self.is_three_of_a_kind(dice): + total = sum([d.face for d in dice]) + return total + +class GoalYahtzee: + """50 points if all the dice are all the same numbers""" + used = False + def is_Yahtzee(self, dice): + if sum([d.face == dice[0].face for d in dice]) == 5: + return True + return False + + def prompt(self, dice): + potential_score = self.score(dice) + return f"Yahtzee ({potential_score})" + + def score(self, dice): + total = 0 + if self.is_Yahtzee(dice): + total = 50 + return total \ No newline at end of file