generated from mwc/lab_dice
While working with Yahtzee it was a overall game and everything was build on from one another. Each goal is its own class and knowns hwo to score. I like how I am able to create new classes like the ones for the game without having the change the whole code like other codes. Add the new classes did not change the game it just added to it. This is different with Unit 1 and 2 because if you are to add some code or change it it can alter the whole thing to be complete different.
This commit is contained in:
6
play.py
6
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)
|
||||
|
||||
@@ -40,3 +40,43 @@ 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user