generated from mwc/lab_dice
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:
2
play.py
2
play.py
@@ -3,12 +3,14 @@ from yahtzee_goals import (
|
||||
GoalOnes,
|
||||
GoalTwos,
|
||||
GoalThrees,
|
||||
GoalFours
|
||||
)
|
||||
|
||||
goals = [
|
||||
GoalOnes(),
|
||||
GoalTwos(),
|
||||
GoalThrees(),
|
||||
GoalFours(),
|
||||
]
|
||||
|
||||
game = Yahtzee(goals)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user