def test_clear_shelf(): banker = Banker() banker.shelf(100) banker.bank() banker.shelf(50) banker.clear_shelf() assert banker.balance == 100 assert banker.shelved == 0
def test_deposit(): banker = Banker() banker.shelf(100) banker.bank() assert banker.shelved == 0 assert banker.balance == 100
def play(self): nope_player = Banker() print('Welcome to Game of Greed') res = input('Wanna play?') if res == 'n': print('OK. Maybe another time') elif res == 'y': # we have to path [new round - current round] #initializing Variable round = 1 remaining_dice = 6 new_round = True #looping until reach break ('q') while True: # run this code if we are in a new round if new_round == True: remaining_dice = 6 dice_to_keep, rolled = self.new_round( remaining_dice, round) round += 1 #check the zilch if Game.zilch(round, rolled, nope_player.balance): round += 1 else: # handeling the Integers -> If Not Integers handel execep where the inpu is string ['q' - 'b'] try: dice_to_keep = int(dice_to_keep) user_aside = Game.convert_input_to_tuple(dice_to_keep) #checking cheat cheat = Game.cheatting(rolled, user_aside) while cheat: print('Cheater!!! Or possibly made a typo...') print(','.join([str(i) for i in rolled])) dice_to_keep = input( 'Enter dice to keep (no spaces), or (q)uit: ') user_aside = Game.convert_input_to_tuple( dice_to_keep) cheat = Game.cheatting(rolled, user_aside) nope_player.shelf( GameLogic.calculate_score(user_aside)) # decrese The Remainig Dice if GameLogic.calculate_score(user_aside) == 1500: remaining_dice = 6 print( f"You have {nope_player.shelved} unbanked points and 0 dice remaining" ) else: remaining_dice -= len(str(dice_to_keep)) print( f"You have {nope_player.shelved} unbanked points and {remaining_dice} dice remaining" ) dice_to_keep = input( '(r)oll again, (b)ank your points or (q)uit ') # To Prevent handel the new_round msg when back to hande ['b' or 'q'] if dice_to_keep == 'b' or dice_to_keep == 'q' or dice_to_keep == 'r': new_round = False except ValueError: if dice_to_keep == 'b': current_round = round - 1 print( f'You banked {nope_player.shelved} points in round {current_round}' ) nope_player.bank() print( f'Total score is {nope_player.balance} points') new_round = True remaining_dice = 6 if dice_to_keep == 'r': print(f'Rolling {remaining_dice} dice...') rolled = self.roller(remaining_dice) if len(str(rolled)) == 1: rolled = () + (rolled, ) print(','.join([str(i) for i in rolled])) # print(round,rolled,nope_player.balance,"top") if Game.zilch(round - 1, rolled, nope_player.balance): new_round = True else: dice_to_keep = input( 'Enter dice to keep (no spaces), or (q)uit: ' ) if dice_to_keep == 'q': Game.quit_game(nope_player.balance) break
class Game: def __init__(self, roller=None): self.roller = roller or GameLogic.roll_dice game = GameLogic() banker = Banker() round = 1 remaining_dice = 6 score = 0 to_shelf = 0 stop = False def play(self): print('Welcome to Game of Greed') res = input("Wanna play?") if res == 'n': print('OK. Maybe another time') elif res == 'y': self.start() def start(self): while Game.score < 10000 and Game.stop == False: print(f'Starting round {Game.round}') Game.remaining_dice = 6 self.rolling_again() def end(self): print(f'Total score is {Game.score} points') print(f'Thanks for playing. You earned {Game.score} points') Game.stop = True def validate_in(self, user_in, roll): arr = list(user_in) saved = tuple([int(x) for x in arr]) for x in saved: if x not in roll: return False return True def valid_cases(self, arr): Game.remaining_dice = Game.remaining_dice - len(arr) print( f'You have {Game.to_shelf} unbanked points and {Game.remaining_dice} dice remaining' ) next_step = input("(r)oll again, (b)ank your points or (q)uit ") if len(arr) == 6: Game.remaining_dice = 6 if next_step == 'b': self.banked() elif next_step == 'q': self.end() elif next_step == 'r': Game.to_shelf += Game.banker.shelved self.rolling_again() def banked(self): Game.banker.shelf(Game.to_shelf) banked = Game.banker.bank() Game.to_shelf = 0 Game.score += banked print(f"You banked {banked} points in round {Game.round}") Game.round += 1 print(f'Total score is {Game.score} points') def rolling_again(self): print(f'Rolling {Game.remaining_dice} dice...') roll = self.roller(Game.remaining_dice) print(','.join([str(i) for i in roll])) arr = list(roll) validate = Game.game.calculate_score(tuple([int(x) for x in arr])) if validate == 0: print('Zilch!!! Round over') print(f'You banked {validate} points in round {Game.round}') print(f'Total score is {Game.score} points') Game.round += 1 Game.remaining_dice = 6 print(f'Starting round {Game.round}') self.rolling_again() else: dice_to_keep = input("Enter dice to keep (no spaces), or (q)uit: ") if dice_to_keep == 'q': self.end() else: valid = self.validate_in(dice_to_keep, roll) while valid == False: print('Cheater!!! Or possibly made a typo...') print(','.join([str(i) for i in roll])) dice_to_keep = input( "Enter dice to keep (no spaces), or (q)uit: ") if dice_to_keep == 'q': self.end() break else: valid = self.validate_in(dice_to_keep, roll) arr = list(dice_to_keep) total = Game.game.calculate_score(tuple([int(x) for x in arr])) Game.to_shelf += total self.valid_cases(arr)
def test_shelf(): banker = Banker() banker.shelf(100) assert banker.shelved == 100 assert banker.balance == 0
class Game: """Class for Game of Greed application """ def __init__(self, num_rounds=20): self.banker = Banker() self.num_rounds = num_rounds def play(self, roller=None): """Entry point for playing (or declining) a game Args: roller (function, optional): Allows passing in a custom dice roller function. Defaults to None. """ self.round_num = 0 self._roller = roller or GameLogic.roll_dice print("Welcome to Game of Greed") print("(y)es to play or (n)o to decline") response = input("> ") if response == "y" or response == "yes": self.start_game() else: self.decline_game() def decline_game(self): print("OK. Maybe another time") def quit_game(self, score=0): print(f"Thanks for playing. You earned {self.banker.balance} points") sys.exit() def start_game(self): self.round_num += 1 self.start_round(self.round_num) def start_round(self, round_num, number=6): print(f"Starting round {round_num}") current_round_score = 0 while True: roll = self.rolling_dice(number) if self.farkle(roll): self.start_round # break selection = self.handle_selection(roll) print("(r)oll again, (b)ank your points or (q)uit:") response = input("> ") if response == "q": self.quit_game() return elif response == "b": current_round_score = self.banker.bank() print( f"You banked {str(current_round_score)} points in round {round_num}" ) print(f'Total score is {self.banker.balance} points') self.start_game() # break else: number -= len(selection) if number == 0: number = 6 def handle_selection(self, roll): while True: print("Enter dice to keep, or (q)uit:") response = input("> ") if response == 'q': self.quit_game() saved_dice = self.saved_dice(roll, response) tup = tuple([int(i) for i in response]) score = GameLogic.calculate_score(tup) break self.banker.shelf(score) print( f'You have {self.banker.shelved} unbanked points and {len(roll) - len(saved_dice)} dice remaining' ) return saved_dice def rolling_dice(self, number): print(f"Rolling {number} dice...") roll = self._roller(number) var = ' ' for i in range(0, len(roll)): var += f'{roll[i]} ' print(f"***{var}***") return roll def check_cheater(self, response, roll): tup = tuple([int(i) for i in response]) for x in tup: if x not in roll: return False return True def saved_dice(self, roll, response): tup = tuple([int(i) for i in response]) check = self.check_cheater(response, roll) if check == 0: print("Cheater!!! Or possibly made a typo...") var = ' ' for i in range(0, len(roll)): var += f'{roll[i]} ' if response == "q": sys.exit() print(f"***{var}***") tup = tuple([int(i) for i in response]) # print("Enter dice to keep, or (q)uit:") # response = input("> ") return tup def farkle(self, roll): score = GameLogic.calculate_score(roll) if score == 0: print(f"""**************************************** ** Zilch!!! Round over ** ****************************************""") self.banker.clear_shelf()
def __init__(self, roller=None, num_rounds=20): self._roller = roller or GameLogic.roll_dice self.banker = Banker() self.num_rounds = num_rounds self.round_num = 0
def test_bank_over_ten_thousand(): round_bank = Banker(9000) round_bank.shelf(2000) round_bank.bank() assert round_bank.balance == 0
def test_new_banker(): banker = Banker() assert banker.total == 0 assert banker.shelved == 0
def play(self): nope_player = Banker() print('Welcome to Game of Greed') res = input('Wanna play?') if res == 'n': print('OK. Maybe another time') elif res == 'y': remaining_dice = 6 round = 1 user_input = ' ' action_status = True EndOfGame = True while EndOfGame: if action_status: # Starting New Round remaining_dice = 6 Game.new_round(remaining_dice, round) roll = self.rolling(remaining_dice) while Game.zilch(round, roll, nope_player.balance, remaining_dice): round += 1 Game.new_round(remaining_dice, round) roll = self.rolling(remaining_dice) Game.zilch(round, roll, nope_player.balance, remaining_dice) user_choice = Game.user_input() if user_choice == 'q': Game.quit_game(nope_player.balance) break if user_choice.isdigit(): user_aside = Game.convert_input_to_tuple(int(user_choice)) cheat = Game.cheatting(roll, user_aside) while cheat: print('Cheater!!! Or possibly made a typo...') print(','.join([str(i) for i in roll])) user_choice = Game.user_input() if user_choice.isdigit(): user_aside = Game.convert_input_to_tuple( int(user_choice)) cheat = Game.cheatting(roll, user_aside) nope_player.shelf(GameLogic.calculate_score(user_aside)) Game.unbankmsg(nope_player.shelved, remaining_dice - len(user_choice)) if nope_player.shelved == 1500: remaining_dice = 6 user_choice = '' action = Game.action() while True: if action == 'b': print( f'You banked {nope_player.shelved} points in round {round}' ) nope_player.bank() print(f'Total score is {nope_player.balance} points') round += 1 action_status = True break elif action == 'r': action_status = False print( f'Rolling {remaining_dice-len(user_choice)} dice...' ) roll = self.rolling(remaining_dice - len(user_choice)) while Game.zilch(round, roll, nope_player.balance, remaining_dice): round += 1 remaining_dice = 6 Game.new_round(remaining_dice, round) roll = self.rolling(remaining_dice) Game.zilch(round, roll, nope_player.balance, remaining_dice) remaining_dice = remaining_dice - len(user_choice) break if action == 'q': Game.quit_game(nope_player.balance) action_status = False EndOfGame = False break else: print('Enter Yes (yn) or No (n)')
def test_shelf(): banker = Banker() banker.shelf(100) assert banker.shelved == 100 assert banker.total == 0
def __init__(self, num_rounds=20): self.banker = Banker() self.logic = GameLogic() self.num_rounds = num_rounds self._roller = GameLogic.roll_dice self.round_num = 0
class Game: """Class for Game of Greed application """ def __init__(self, num_rounds=20): self.banker = Banker() self.logic = GameLogic() self.num_rounds = num_rounds self._roller = GameLogic.roll_dice self.round_num = 0 def play(self, roller=None): """Entry point for playing (or declining) a game Args: roller (function, optional): Allows passing in a custom dice roller function. Defaults to None. """ self.round_num = 0 self._roller = roller or GameLogic.roll_dice print("Welcome to Game of Greed") print("(y)es to play or (n)o to decline") response = input("> ") if response == "y" or response == "yes": self.start_game() else: self.decline_game() def decline_game(self): print("OK. Maybe another time") def new_roll(self, remaining_die): print(f"Rolling {remaining_die} dice...") die_roll = self._roller(remaining_die) string_roll = [str(num) for num in die_roll] return (die_roll, string_roll) def check_validity(self, die_roll, string_roll): cheated = True while cheated: cheated = False print(f'*** {" ".join(string_roll)} ***') round_points = self.logic.calculate_score(die_roll) if round_points == 0: return 'Zilch' print("Enter dice to keep, or (q)uit:") kept_die = input("> ") saved_die = list(kept_die) if kept_die == "q": print( f"Thanks for playing. You earned {self.banker.total} points" ) sys.exit() good_input = True for value in saved_die: try: int(value) except: saved_die.remove(value) user_selection = tuple(int(char) for char in saved_die) no_cheats = self.logic.validate_keepers(die_roll, user_selection) if not no_cheats: cheated = True print('Cheater!!! Or possibly made a typo...') return user_selection def round_decisions(self, remaining_die): print( f"You have {self.banker.shelved} unbanked points and {remaining_die} dice remaining" ) print("(r)oll again, (b)ank your points or (q)uit:") round_choice = input("> ") if round_choice == "q": print(f"Thanks for playing. You earned {self.banker.total} points") sys.exit() elif round_choice == "b": round_points = self.banker.bank() remaining_die = 6 print( f"You banked {round_points} points in round {self.round_num}") elif round_choice == "r": if remaining_die == 0: remaining_die = 6 self.full_roll(remaining_die) def full_roll(self, remaining_die): (die_roll, string_roll) = self.new_roll(remaining_die) user_selection = self.check_validity(die_roll, string_roll) if user_selection == 'Zilch': self.banker.clear_shelf() print( '****************************************\n** Zilch!!! Round over **\n****************************************' ) print(f"You banked 0 points in round {self.round_num}") else: remaining_die -= len(user_selection) self.banker.shelf(self.logic.calculate_score(user_selection)) self.round_decisions(remaining_die) def start_game(self): remaining_die = 6 while self.round_num < self.num_rounds: self.round_num += 1 print(f"Starting round {self.round_num}") self.full_roll(remaining_die) print(f"Total score is {self.banker.total} points") print(f"Thanks for playing. You earned {self.banker.total} points") sys.exit()
def test_bank_instance(): round_bank = Banker() assert round_bank.balance == 0
class Game: """Class for Game of Greed application """ def __init__(self, roller=None, num_rounds=20): self._roller = roller or GameLogic.roll_dice self.banker = Banker() self.num_rounds = num_rounds self.round_num = 0 def play(self): """ Entry point for playing (or/not) a game """ print("Welcome to Game of Greed") prompt = "Wanna play?" self.choice(prompt.strip(), self.start_game, self.decline_game) def choice(self, prompt, accept, decline): response = input(prompt) if response == "y" or response == "yes": accept() else: decline() def decline_game(self): print("OK. Maybe another time") def start_game(self): self.round_num = 1 while self.round_num <= self.num_rounds: self.start_round(self.round_num) self.round_num += 1 print(f"Total score is {self.banker.balance} points") self.quit_game() def quit_game(self): print(f"Thanks for playing. You earned {self.banker.balance} points") sys.exit() def start_round(self, round, num_dice=6): print(f"Starting round {round}") round_score = 0 while True: roll = self.roll_dice(num_dice) if self.got_zilch(roll): break keepers = self.handle_keepers(roll) roll_again_response = input( "(r)oll again, (b)ank your points or (q)uit ") if roll_again_response == "q": self.quit_game() return elif roll_again_response == "b": round_score = self.banker.bank() break else: num_dice -= len(keepers) if num_dice == 0: num_dice = 6 print(f"You banked {str(round_score)} points in round {round}") def handle_keepers(self, roll): while True: keeper_string = input( "Enter dice to keep (no spaces), or (q)uit: ") if keeper_string.startswith("q"): self.quit_game() keepers = self.gather_keepers(roll, keeper_string) roll_score = self.calculate_score(keepers) if roll_score == 0: print("Must keep at least one scoring dice") else: break self.banker.shelf(roll_score) print( f"You have {self.banker.shelved} unbanked points and {len(roll) - len(keepers)} dice remaining" ) return keepers def roll_dice(self, num): print(f"Rolling {num} dice...") roll = self._roller(num) print(",".join([str(i) for i in roll])) return roll def got_zilch(self, roll): initial_score = self.calculate_score(roll) if initial_score == 0: print("Zilch!!! Round over") self.banker.clear_shelf() return True return False def calculate_score(self, roll): return GameLogic.calculate_score(roll) def keep_scorers(self, roll): return GameLogic.get_scorers(roll) def gather_keepers(self, roll, keeper_string): keepers = [int(ch) for ch in keeper_string] while not GameLogic.validate_keepers(roll, keepers): print("Cheater!!! Or possibly made a typo...") print(",".join([str(i) for i in roll])) keeper_string = input( "Enter dice to keep (no spaces), or (q)uit: ") if keeper_string.startswith("q"): self.quit_game() keepers = [int(ch) for ch in keeper_string] return keepers
def test_bank_instance_add_from_shelf(): round_bank = Banker(0) round_bank.shelf(300) round_bank.shelf(750) round_bank.bank() assert round_bank.balance == 1050
def play(self): """ * To play the game, this method will keep calling itself untill the game ends, by quitting the game * This method starts the rounds, roll the dice, calculate it's score and so on * Uses all the methods above """ if Game.round == 1 and Game.new_game.shelved == 0: Game.result = Game.welcome() if Game.result == "y" or Game.result == "yes": if not Game.new_game.shelved: print(f"Starting round {Game.round}") print(f"Rolling {Game.num_dice} dice...") roll = self.roller(Game.num_dice) self.print_roll(roll) GameLogic.how_many = 0 if not (GameLogic.calculate_score(roll)): self.zilch(len(roll)) GameLogic.how_many = 0 sys.exit() enter = input("Enter dice to keep (no spaces), or (q)uit: ") # print('yyy') if enter.lower() == "q" or enter.lower() == "quit": self.to_quit() else: roll_list = self.check(roll, enter) if roll_list: roll_tuple = tuple(roll_list) Game.num_dice -= len(roll_tuple) GameLogic.how_many = 0 score = GameLogic.calculate_score(roll_tuple) if len(roll_tuple) == 6 and GameLogic.how_many == 6: # print('hot dice:',GameLogic.how_many) Game.status = False if not score: self.zilch(len(roll_tuple)) Game.new_game.shelved = Banker.shelf(Game.new_game, score) print( f"You have {Game.new_game.shelved} unbanked points and {Game.num_dice} dice remaining" ) enter_again = input( "(r)oll again, (b)ank your points or (q)uit ") if enter_again.lower() == "r" or enter_again.lower( ) == "roll": if not Game.num_dice: Game.num_dice = 6 self.play() if enter_again.lower() == "b" or enter_again.lower( ) == "bank": print( f"You banked {Game.new_game.shelved} points in round {Game.round}" ) Game.round += 1 Game.num_dice = 6 Game.banked_score = Banker.bank(Game.new_game) print(f"Total score is {Game.new_game.balance} points") self.play() if enter_again.lower() == "q" or enter_again.lower( ) == "quit": self.to_quit()
def test_new_banker(): banker = Banker() assert banker.balance == 0 assert banker.shelved == 0
class Game(): new_game = Banker() num_dice = 6 result = "" round = 1 status = True def __init__(self, roller=None): self.roller = roller or GameLogic.roll_dice # self.roller=roller @staticmethod def arguments_reset(): Game.new_game.shelved = 0 Game.num_dice = 6 Game.result = "" Game.round = 1 Game.new_game.balance = 0 Game.status = True @staticmethod def welcome(): """ * This function will appear once, only at the beggining of the game * Will ask the user if he/she wants to play the game or quit """ print("Welcome to Game of Greed") result = input("Wanna play?") result_lower = result.lower() if result_lower == "n" or result_lower == "no": print("OK. Maybe another time") return result_lower def to_quit(self): """ To handle quiting """ if Game.status: print(f"Total score is {Game.new_game.balance} points") print( f"Thanks for playing. You earned {Game.new_game.balance} points" ) else: print( f"Thanks for playing. You earned {Game.new_game.balance} points" ) Game.arguments_reset() def print_roll(self, roll): """ Prints the roll of dice """ print(','.join([str(i) for i in roll])) def is_cheating(self, roll): """ * Will be called if the user cheated, by the check method * Asks the user for anthor input, then calls check method again * This recursive calling back and forth between check and is_cheating will continue untill either stops cheating or just quits the game. * Arguments: roll -- the roll that the user cheated on """ Game.status = False print("Cheater!!! Or possibly made a typo...") self.print_roll(roll) enter = input("Enter dice to keep (no spaces), or (q)uit: ") if enter.lower() == "q" or enter.lower() == "quit": self.to_quit() Game.status = True return [] else: return self.check(roll, enter) def check(self, roll, enter): """ * To check if the user cheated, by comparing the numbers in the roll with what the user picked * Arguments: roll -- the roll to check on enter -- what the user picked """ if not enter.isalpha(): if len(enter) <= 6: roll_list = [] leng = len(enter) for i in range(leng): if roll.count(int(enter[i])): if enter.count(enter[i]) <= roll.count(int(enter[i])): roll_list.append(int(enter[i])) else: roll_list = self.is_cheating(roll) break else: roll_list = self.is_cheating(roll) return (roll_list) def zilch(self, roll): """ When the user scores zero Arguments: roll -- the dice roll that scored zero """ print('Zilch!!! Round over') print(f'You banked 0 points in round {Game.round}') print('Total score is 0 points') Game.round += 1 Game.num_dice = 6 Game.new_game.shelved = 0 if roll == 6: Game.status = False self.play() def play(self): """ * To play the game, this method will keep calling itself untill the game ends, by quitting the game * This method starts the rounds, roll the dice, calculate it's score and so on * Uses all the methods above """ if Game.round == 1 and Game.new_game.shelved == 0: Game.result = Game.welcome() if Game.result == "y" or Game.result == "yes": if not Game.new_game.shelved: print(f"Starting round {Game.round}") print(f"Rolling {Game.num_dice} dice...") roll = self.roller(Game.num_dice) self.print_roll(roll) GameLogic.how_many = 0 if not (GameLogic.calculate_score(roll)): self.zilch(len(roll)) GameLogic.how_many = 0 sys.exit() enter = input("Enter dice to keep (no spaces), or (q)uit: ") # print('yyy') if enter.lower() == "q" or enter.lower() == "quit": self.to_quit() else: roll_list = self.check(roll, enter) if roll_list: roll_tuple = tuple(roll_list) Game.num_dice -= len(roll_tuple) GameLogic.how_many = 0 score = GameLogic.calculate_score(roll_tuple) if len(roll_tuple) == 6 and GameLogic.how_many == 6: # print('hot dice:',GameLogic.how_many) Game.status = False if not score: self.zilch(len(roll_tuple)) Game.new_game.shelved = Banker.shelf(Game.new_game, score) print( f"You have {Game.new_game.shelved} unbanked points and {Game.num_dice} dice remaining" ) enter_again = input( "(r)oll again, (b)ank your points or (q)uit ") if enter_again.lower() == "r" or enter_again.lower( ) == "roll": if not Game.num_dice: Game.num_dice = 6 self.play() if enter_again.lower() == "b" or enter_again.lower( ) == "bank": print( f"You banked {Game.new_game.shelved} points in round {Game.round}" ) Game.round += 1 Game.num_dice = 6 Game.banked_score = Banker.bank(Game.new_game) print(f"Total score is {Game.new_game.balance} points") self.play() if enter_again.lower() == "q" or enter_again.lower( ) == "quit": self.to_quit()
def play(self): is_it_zilch = False is_it_cheater = False is_it_roll_again = 0 #to see if roll again more than 4 round = 0 score = 0 new_banker = Banker() print("Welcome to Game of Greed") response = input("Wanna play?") if response == 'n': print("OK. Maybe another time") elif response == 'y': while True: num_dice = 6 round += 1 print(f"Starting round {round}") print(f"Rolling {num_dice} dice...") roll = self.roller(num_dice) Game.print_roll(roll) if GameLogic.calculate_score(roll) == 0: is_it_zilch = True print('Zilch!!! Round over') print( f"You banked {new_banker.shelved} points in round {round}" ) print(f"Total score is {new_banker.balance} points") continue what_next = input( "Enter dice to keep (no spaces), or (q)uit: ") if what_next == 'q': if is_it_roll_again >= 4: print(f"Total score is {new_banker.balance} points") print( f"Thanks for playing. You earned {new_banker.balance} points" ) break elif is_it_cheater or is_it_zilch: print( f"Thanks for playing. You earned {new_banker.balance} points" ) break else: print(f"Total score is {new_banker.balance} points") print( f"Thanks for playing. You earned {new_banker.balance} points" ) break else: while GameLogic.if_cheater(roll, Game.totuple(what_next)) == 0: is_it_cheater = True print('Cheater!!! Or possibly made a typo...') Game.print_roll(roll) what_next = input( "Enter dice to keep (no spaces), or (q)uit: ") if what_next == 'q' or what_next == 'quit': if is_it_cheater: print( f"Thanks for playing. You earned {new_banker.balance} points" ) break else: print(f"Total score is {new_banker.balance} points") print( f"Thanks for playing. You earned {new_banker.balance} points" ) break else: num_dice = num_dice - len(what_next) what_next = int(what_next) to_topule = Game.totuple(what_next) new_banker.shelved = GameLogic.calculate_score(to_topule) print( f"You have {new_banker.shelved} unbanked points and {num_dice} dice remaining" ) new_responce = input( "(r)oll again, (b)ank your points or (q)uit ") if new_responce == 'b': new_banker.balance = new_banker.balance + new_banker.shelved print( f"You banked {new_banker.shelved} points in round {round}" ) new_banker.shelved = 0 print(f"Total score is {new_banker.balance} points") elif new_responce == 'q': if is_it_cheater: print( f"Thanks for playing. You earned {new_banker.balance} points" ) break else: print( f"Total score is {new_banker.balance} points") print( f"Thanks for playing. You earned {new_banker.balance} points" ) break while new_responce == 'r': is_it_roll_again += 1 print(f"Rolling {num_dice} dice...") roll = self.roller(num_dice) Game.print_roll(roll) if GameLogic.calculate_score(roll) == 0: is_it_zilch = True new_banker.shelved = 0 print('Zilch!!! Round over') print( f"You banked {new_banker.shelved} points in round {round}" ) print( f"Total score is {new_banker.balance} points") break what_next = input( "Enter dice to keep (no spaces), or (q)uit: ") if what_next == 'q': print( f"Thanks for playing. You earned {new_banker.balance} points" ) break else: num_dice = num_dice - len(what_next) what_next = int(what_next) to_topule = Game.totuple(what_next) add_value = GameLogic.calculate_score(to_topule) new_banker.shelved += add_value add_value = 0 print( f"You have {new_banker.shelved} unbanked points and {num_dice} dice remaining" ) new_responce = input( "(r)oll again, (b)ank your points or (q)uit ") if new_responce == 'r': continue elif new_responce == 'b': new_banker.balance = new_banker.balance + new_banker.shelved print( f"You banked {new_banker.shelved} points in round {round}" ) new_banker.shelved = 0 print( f"Total score is {new_banker.balance} points" ) break
def __init__(self, num_rounds=20): self.banker = Banker() self.num_rounds = num_rounds