diff --git a/PyGame/practice/textslot.py b/PyGame/practice/textslot.py index b4bd0b6..76c2857 100644 --- a/PyGame/practice/textslot.py +++ b/PyGame/practice/textslot.py @@ -21,20 +21,18 @@ SYMBOL_VALUE = { "D": 2 } - - -def check_winings(columns, bet, lines, values): +def check_winings(columns: List, my_bet: int, my_lines: int): winnings = 0 winning_lines = [] - for line in range(lines): + for line in range(my_lines): symbol = columns[0][line] for column in columns: symbol_to_check = column[line] if symbol != symbol_to_check: break else: - winnings += values[symbol] * bet - winning_lines.append( +1) + winnings += SYMBOL_VALUE[symbol] * my_bet + winning_lines.append(line + 1) return winnings, winning_lines @@ -102,7 +100,7 @@ def get_bet() -> int: print(" Error: Please enter a number") return bet -def main(): +def roll(): balance = deposit() lines = get_number_of_lines() bet = -1 @@ -116,12 +114,30 @@ def main(): if total_bet == 0: return print(f"You are betting ${bet} on {lines} lines. Total bet is equal to: ${total_bet} ") - + slots = get_slot_machine_spin() print_slotmachine(slots) - winnings, winning_lines = check_winings(slots, lines, bet, SYMBOL_VALUE) + winnings, winning_lines = check_winings(slots, bet, lines) print(f"You won ${winnings}.") - print(f"You won on lines:", *winning_lines) + if len(winning_lines) > 0: + print(f"You won on line" + ("s" if len(winning_lines) > 1 else "") + ":", *winning_lines) + balance += winnings + else: + balance -= bet * lines + print(f"Your balance is now: ${balance}") + return winnings - total_bet + +def main() -> int: + balance = deposit() + while True: + print(f"Current Balance is ${balance}") + answer = input("Press enter to play (q to quit).") + if answer == "q": + break + balance += roll(balance) + + print(f"YOu left with ${balance}") + main() print() print("Thank you for playing!") \ No newline at end of file