From 94b22faa38c58fb2905c797ea1b93671d726f4c9 Mon Sep 17 00:00:00 2001 From: Seoyeon Lee Date: Thu, 12 Dec 2024 23:51:02 -0500 Subject: [PATCH] Unit 1 and 2 feels more linear, I had to have a plan and the plan needs to be written in order. This activity using OOP feels like creating lots of small blokcs, and maybe the idea of the blokcs I have in mind is classes. OOP seems to give a bit more freedome (?) or flexibility. This feelings of having more flexibility would allow me to feel I could fix things more easily. Eveen though I still don't fully use the benefit of OOP, and I still want to write things down on the paper before I type anything. I am still a bit scared to make mistakes. --- play.py | 7 ++++++ yahtzee_goals.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) 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