From a00d27af7e03d61172b238e4db06e12f5094cac7 Mon Sep 17 00:00:00 2001 From: louiscooper136 Date: Sat, 10 Feb 2024 16:49:34 -0500 Subject: [PATCH] Updateed checkpoint 2: Writing comments is about describing what should happen vs. just writing what the code does technically. I will use docstrings and comments, they are great for learning. --- __pycache__/yahtzee.cpython-310.pyc | Bin 0 -> 4482 bytes __pycache__/yahtzee_goals.cpython-310.pyc | Bin 0 -> 1399 bytes dice_stats.py | 1 - yahtzee.py | 39 +++++++++++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 __pycache__/yahtzee.cpython-310.pyc create mode 100644 __pycache__/yahtzee_goals.cpython-310.pyc diff --git a/__pycache__/yahtzee.cpython-310.pyc b/__pycache__/yahtzee.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c6e4127ee8495a028473895119866917f018f548 GIT binary patch literal 4482 zcmb_f&u<&Y6`t8$k}Hb(VOh3iId0ai-GqrlrcG0)uC2JR;r384fo0UNP-C&?ti+X; zTxw=%K?|w~pqvZz90ZWilm3kU8++}^=iG8g`n?&FA}JQlp(N(*?Ci|!yzjmDy|>B2 zLYd+B&%ggGe73~czv*WDXXEA(n)(@pV1mc2&9^vbe`LZE_Sa0<$JUl5oK03Oyu}=L z#&i2g6gH_p{AoN;+P$J(_{hs1v18 z5Jy=kyn`rhd4U&4Dy3OFNf0ZuL6dYJ{-{r=K1NfwAq4L;pY=&{gJ}vpkNFdJOk=iS zgl$7|%x#hw{)RhkVnD4x?65w2RXE})J7)i|_N`5J#w5+ETDevGIJY~!wk+UYi|-%S zTS+^tH|5jDg5p+TqCJ*H0lP18}Kxeq(EghrkC;SwSxaY`K z^sQ4iKBmf;XZP8z{SEupqWRh=P9s}=5ypTZ^wI==VO;8#HdS`zWzv)0cGL-CPiyHN z1j-|wyE5ve`AReCbyC0A>8Vio27q!m4i0^Z2SU!{cxPN9DviCy)OTnaSzM9+F0XL3 zA6KnxVR(ib&6rS~)F#li-#tTTsJgJo^Pr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fPiFds4;1QW`RaQ#Q+k(r!&_IqA%zmU%IFL7X64Mvtas4cF*D7K zN%oYSu@j!LqSFhwN-ih>G|CVCKux%DKsC1jay!+jALW(|RncAvb@XF#xFA#1ICW?Z zguUl<+_);VU}k?(%^e|PzpsSIYeMw397g!NF2u>ukA8WoLP#BenGX{s&FU=4LSkgt z6xngEC{rxKf&5Sbt8;_40A%T)aRI=80loZ1z7G)GGCl@r2oD+23amv1OvD& zgUlNnp^8wHIIk1CxP$fvKsiEucijk06RtxRvj*P_tlw-P+(!5<1rFjK+P45o@{1HD z`R4BOlX+RDy;0znI(cEbM E1j}U%dH?_b literal 0 HcmV?d00001 diff --git a/dice_stats.py b/dice_stats.py index aee761d..52f8924 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -20,7 +20,6 @@ class FiveDice: return False return True - def is_three_of_a_kind(self): count = Counter(self.faces()) for face_count in count.values(): diff --git a/yahtzee.py b/yahtzee.py index 8ae2b41..0944f41 100644 --- a/yahtzee.py +++ b/yahtzee.py @@ -4,17 +4,26 @@ class Yachtzee: """A command-line Yahtzee game. This version of Yahtzee is initialized with a list of goals. """ + + """runs when the object is instantiated, sets attributes for score, goals and dice. Dice is creating a dice roll 5 times + """ def __init__(self, goals): self.score = 0 self.goals = goals self.dice = [Die() for num in range(5)] + + """prints a welcome message and uses a while loop to say if the goal is 0, then run the play_round() method. then print your final score out. + """ def play(self): print("Welcome to Yachtzee!") while self.count_unused_goals() > 0: self.play_round() print(f"Your final score was {self.score}") + + """its prints =*80 then it sets rolls to 3. Then it shows how many rolls you have left. it shows how many rolls you ahve left after thdice roles. adds to the score + """ def play_round(self): print("=" * 80) self.rolls_left = 3 @@ -25,10 +34,14 @@ class Yachtzee: goal.used = True self.score += goal.score(self.dice) + """Used to show score, rolls left and dice in the game. + """ def show_status(self): dice = ', '.join([str(die) for die in self.dice]) print(f"Score: {self.score}. Rolls left: {self.rolls_left}. Dice: {dice}.") + """Used to show score, rolls left and dice in the game. + """ def choose_goal(self): options = [] unused_goals = self.get_unused_goals() @@ -44,7 +57,10 @@ class Yachtzee: return self.choose_goal() else: return unused_goals[choice] - + + """ + Displays options amd prompts user to make choice. If input is valid return the choice. + """ def get_choice(self, options): print("What would you like to do?") for i, option in enumerate(options): @@ -55,6 +71,9 @@ class Yachtzee: choice = input("> ") return int(choice) + """ + Chekcs if the users chouice is valid, returns true or false. + """ def option_choice_is_valid(self, choice, options): if not choice.isdigit(): return False @@ -64,9 +83,15 @@ class Yachtzee: return False return True + """ + counts unused goals + """ def count_unused_goals(self): return len(self.get_unused_goals()) + """ + iterates through sel.goals and ammends unused goals list with unused goals. + """ def get_unused_goals(self): unused_goals = [] for goal in self.goals: @@ -74,6 +99,9 @@ class Yachtzee: unused_goals.append(goal) return unused_goals + """ + rerolls dice, decreased amount of rolls + """ def reroll(self): self.rolls_left -= 1 choices = self.get_reroll_choices() @@ -81,6 +109,9 @@ class Yachtzee: for die in dice_to_reroll: die.roll() + """ + Determiens whcih dice should be rerolled + """ def get_dice_to_reroll(self, choice_ints): dice_to_reroll = [] for die in self.dice: @@ -89,6 +120,9 @@ class Yachtzee: dice_to_reroll.append(die) return dice_to_reroll + """ + Prompts to enter which dice to re-roll + """ def get_reroll_choices(self): print("Which dice do you want to re-roll?") choices = input("> ") @@ -98,6 +132,9 @@ class Yachtzee: choice_ints = [int(digit) for digit in choices] return choice_ints + """ + Validates choices for reroll + """ def reroll_choices_are_valid(self, choices_str): if not choices_str.isdigit(): return False