From 8a3d6c00e454df42aae47e21a2ca19bc85c72d5c Mon Sep 17 00:00:00 2001 From: juddin2 Date: Sun, 9 Nov 2025 20:04:59 -0500 Subject: [PATCH] Wrote a new goal in yahtzee_goals.py I'm not sure if I underdtood it correctly. But, I found that it broke down a large piece of code into smaller pices like a code for dice, goals, and the game. Additionally, it also made it easier to test and change codes if needed. --- play.py | 2 ++ yahtzee_goals.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/play.py b/play.py index 773f7f3..7c232d9 100644 --- a/play.py +++ b/play.py @@ -3,12 +3,14 @@ from yahtzee_goals import ( GoalOnes, GoalTwos, GoalThrees, + GoalFours ) goals = [ GoalOnes(), GoalTwos(), GoalThrees(), + GoalFours(), ] game = Yahtzee(goals) diff --git a/yahtzee_goals.py b/yahtzee_goals.py index 10af574..682a6c1 100644 --- a/yahtzee_goals.py +++ b/yahtzee_goals.py @@ -40,3 +40,17 @@ class GoalThrees: if die.face == 3: total += 3 return total + +class GoalFours: + "Four points for each four" + + 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