generated from mwc/lab_dice
Checkpoint 3: I think in Units 1 or 2 I wouldn't have had such specific conditions. So OOP helps me target specific goals or problems that I might encounter. I think OOP makes more sense to me than other targeted code we wrote in Unit 1 or 2. I am struggling a little bit to understand creation of "." conditions/actions. Otherwise this seems to be a super useful tool to know.
69 lines
1.6 KiB
Python
69 lines
1.6 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
|
|
|
|
class LargeStraight:
|
|
"Fourty points for 5 sequential dice"
|
|
|
|
def prompt(self, dice):
|
|
potential_score = self.score(dice)
|
|
return f"Large Straight ({potential_score})"
|
|
def score(self,dice):
|
|
total = 0
|
|
faces = [die.face for die in dice]
|
|
if faces == [1,2,3,4,5] or faces == [2,3,4,5,6]:
|
|
total = 40
|
|
return total
|
|
|