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.
This commit is contained in:
juddin2
2025-11-09 20:04:59 -05:00
parent 4b96a94574
commit 8a3d6c00e4
2 changed files with 16 additions and 0 deletions

View File

@@ -3,12 +3,14 @@ from yahtzee_goals import (
GoalOnes,
GoalTwos,
GoalThrees,
GoalFours
)
goals = [
GoalOnes(),
GoalTwos(),
GoalThrees(),
GoalFours(),
]
game = Yahtzee(goals)

View File

@@ -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