From 9aa6b06c24b68448d8e1e107aba100aff8a10111 Mon Sep 17 00:00:00 2001 From: Stephen Deaton Date: Thu, 27 Jun 2024 14:28:33 -0400 Subject: [PATCH] slot prac --- PyGame/practice/textslot.py | 78 +++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/PyGame/practice/textslot.py b/PyGame/practice/textslot.py index 2067882..b4bd0b6 100644 --- a/PyGame/practice/textslot.py +++ b/PyGame/practice/textslot.py @@ -1,5 +1,5 @@ import random - +from typing import List, Dict, Tuple MAX_LINES = 3 MAX_BET = 100 @@ -7,38 +7,63 @@ MIN_BET = 1 ROWS = 3 COLS = 3 -symbol_count = { +SYMBOL_COUNT = { "A": 2, "B": 4, "C": 6, "D": 8 } -def get_slot_machine_spin(rows, cols, symbol): +SYMBOL_VALUE = { + "A": 5, + "B": 4, + "C": 3, + "D": 2 +} + + + +def check_winings(columns, bet, lines, values): + winnings = 0 + winning_lines = [] + for line in range(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) + + return winnings, winning_lines + + +# This function will +def get_slot_machine_spin() -> List: all_symbols = [] - for symbol, symbol_count in symbol.items(): #this is so as it picks from the list it gets the values and the index - for _ in range(symbol_count): # underscore ???? + # this is so as it picks from the list it gets the values and the index + for symbol, count in SYMBOL_COUNT.items(): + for _ in range(count): all_symbols.append(symbol) columns = [] - for _ in range(cols): + for col in range(COLS): column = [] current_symbols = all_symbols[:] - for _ in range(rows): + for row in range(ROWS): value = random.choice(current_symbols) current_symbols.remove(value) column.append(value) - columns.append(column) - return columns -def print_slotmachine(columns): - for row in range(len(columns[0])): - for i, column in enumerate(columns): - if i != len(columns) - 1: - print(column[row], "|") +def print_slotmachine(columns: List): + for row in range(ROWS): + for index, column in enumerate(columns): + if index != COLS - 1: + print(column[row], "| ", end='') else: - print(column[row],) + print(column[row]) def deposit() -> int: amount = 0 @@ -64,6 +89,7 @@ def get_number_of_lines() -> int: print(" Error: Please enter a number") return lines + def get_bet() -> int: bet = 0 while bet < MIN_BET or bet > MAX_BET: @@ -79,19 +105,23 @@ def get_bet() -> int: def main(): balance = deposit() lines = get_number_of_lines() - while True: + bet = -1 + total_bet = balance + 1 + while bet != 0 and total_bet > balance: bet = get_bet() + print(f"___{bet}_{lines}") total_bet = bet * lines if total_bet > balance: print(f" Error: You do not have enough to bet that amount, curent balance is: ${balance} ") - else: - break - total_bet = bet * lines + 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(ROWS, COLS, symbol_count) + slots = get_slot_machine_spin() print_slotmachine(slots) - - - -main() \ No newline at end of file + winnings, winning_lines = check_winings(slots, lines, bet, SYMBOL_VALUE) + print(f"You won ${winnings}.") + print(f"You won on lines:", *winning_lines) +main() +print() +print("Thank you for playing!") \ No newline at end of file