generated from mwc/lab_dice
Unit 1 and 2 feels more linear, I had to have a plan and the plan needs to be written in order.
This activity using OOP feels like creating lots of small blokcs, and maybe the idea of the blokcs I have in mind is classes. OOP seems to give a bit more freedome (?) or flexibility. This feelings of having more flexibility would allow me to feel I could fix things more easily. Eveen though I still don't fully use the benefit of OOP, and I still want to write things down on the paper before I type anything. I am still a bit scared to make mistakes.
This commit is contained in:
parent
0e0ffd5cb2
commit
94b22faa38
7
play.py
7
play.py
|
@ -3,12 +3,19 @@ from yahtzee_goals import (
|
||||||
GoalOnes,
|
GoalOnes,
|
||||||
GoalTwos,
|
GoalTwos,
|
||||||
GoalThrees,
|
GoalThrees,
|
||||||
|
GoalFours,
|
||||||
|
GoalThreeOfAKind,
|
||||||
|
GoalYahtzee,
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
goals = [
|
goals = [
|
||||||
GoalOnes(),
|
GoalOnes(),
|
||||||
GoalTwos(),
|
GoalTwos(),
|
||||||
GoalThrees(),
|
GoalThrees(),
|
||||||
|
GoalFours(),
|
||||||
|
GoalThreeOfAKind(),
|
||||||
|
GoalYahtzee(),
|
||||||
]
|
]
|
||||||
|
|
||||||
game = Yachtzee(goals)
|
game = Yachtzee(goals)
|
||||||
|
|
|
@ -43,3 +43,58 @@ class GoalThrees:
|
||||||
if die.face == 3:
|
if die.face == 3:
|
||||||
total += 3
|
total += 3
|
||||||
return total
|
return total
|
||||||
|
|
||||||
|
class GoalFours:
|
||||||
|
"Four points for each four"
|
||||||
|
used = False
|
||||||
|
|
||||||
|
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 GoalThreeOfAKind:
|
||||||
|
"add all dice, if all three dice have the same number"
|
||||||
|
used = False
|
||||||
|
def is_three_of_a_kind(self, dice):
|
||||||
|
if sum([d.face == dice[0].face for d in dice]) == 3:
|
||||||
|
return True
|
||||||
|
if sum([d.face == dice[1].face for d in dice]) == 3:
|
||||||
|
return True
|
||||||
|
if sum([d.face == dice[2].face for d in dice]) == 3:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def prompt(self, dice):
|
||||||
|
potential_score = self.score(dice)
|
||||||
|
return f"Three of a kind ({potential_score})"
|
||||||
|
|
||||||
|
def score(self, dice):
|
||||||
|
total = 0
|
||||||
|
if self.is_three_of_a_kind(dice):
|
||||||
|
total = sum([d.face for d in dice])
|
||||||
|
return total
|
||||||
|
|
||||||
|
class GoalYahtzee:
|
||||||
|
"""50 points if all the dice are all the same numbers"""
|
||||||
|
used = False
|
||||||
|
def is_Yahtzee(self, dice):
|
||||||
|
if sum([d.face == dice[0].face for d in dice]) == 5:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def prompt(self, dice):
|
||||||
|
potential_score = self.score(dice)
|
||||||
|
return f"Yahtzee ({potential_score})"
|
||||||
|
|
||||||
|
def score(self, dice):
|
||||||
|
total = 0
|
||||||
|
if self.is_Yahtzee(dice):
|
||||||
|
total = 50
|
||||||
|
return total
|
Loading…
Reference in New Issue