From 04803f0e3afe785c8417887963c7b0b0358404a9 Mon Sep 17 00:00:00 2001 From: angelotr Date: Wed, 12 Nov 2025 00:15:13 -0500 Subject: [PATCH] For this last checkpoint, what I did was add a few goals and changed play.py and yahtzee_goals.py by adding the goals I selected. Checkpoint 3: While working on Yahtzee, I got to experience Object-Oriented Programming (OOP) by writing classes that represented different parts of the game, such as dice, goals, and the overall Yahtzee game itself. Each class had its own attributes and methods, which made the program easier to organize and understand. For example, the Die class handled rolling and showing values, while the Yahtzee class managed turns, scoring, and game flow. This style of problem-solving is different from the skills in Unit 1 and 2 was mainly focused more on functions and variables whereas in Unit 3 I was able to write out classes with OOP where each class handles its own part of the game. This ultimately makes it easier to make changes, fix bugs, and add new features later on. --- play.py | 6 ++++++ yahtzee_goals.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/play.py b/play.py index 773f7f3..814e2d3 100644 --- a/play.py +++ b/play.py @@ -3,12 +3,18 @@ from yahtzee_goals import ( GoalOnes, GoalTwos, GoalThrees, + GoalFours, + GoalFives, + GoalSixes, ) goals = [ GoalOnes(), GoalTwos(), GoalThrees(), + GoalFours(), + GoalFives(), + GoalSixes(), ] game = Yahtzee(goals) diff --git a/yahtzee_goals.py b/yahtzee_goals.py index 10af574..0bd599b 100644 --- a/yahtzee_goals.py +++ b/yahtzee_goals.py @@ -40,3 +40,42 @@ 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 + +class GoalFives: + """Five points for each five.""" + def prompt(self, dice): + potential_score = self.score(dice) + return f"Fives ({potential_score})" + + def score(self, dice): + total = 0 + for die in dice: + if die.face == 5: + total += 5 + return total + +class GoalSixes: + """Six points for each six.""" + def prompt(self, dice): + potential_score = self.score(dice) + return f"Sixes ({potential_score})" + + def score(self, dice): + total = 0 + for die in dice: + if die.face == 6: + total += 6 + return total \ No newline at end of file