Files
lab_dice/yahtzee_goals.py
juddin2 8a3d6c00e4 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.
2025-11-09 20:04:59 -05:00

57 lines
1.2 KiB
Python

class GoalOnes:
"One point for each one"
def prompt(self, dice):
potential_score = self.score(dice)
return f"Ones ({potential_score})"
def score(self, dice):
total = 0
for die in dice:
if die.face == 1:
total += 1
return total
class GoalTwos:
"Two points for each two"
def prompt(self, dice):
potential_score = self.score(dice)
return f"Twos ({potential_score})"
def score(self, dice):
total = 0
for die in dice:
if die.face == 2:
total += 2
return total
class GoalThrees:
"Three points for each three"
def prompt(self, dice):
potential_score = self.score(dice)
return f"Threes ({potential_score})"
def score(self, dice):
total = 0
for die in dice:
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