BigSteve/PyGame/practice/textslot.py

97 lines
2.7 KiB
Python

import random
MAX_LINES = 3
MAX_BET = 100
MIN_BET = 1
ROWS = 3
COLS = 3
symbol_count = {
"A": 2,
"B": 4,
"C": 6,
"D": 8
}
def get_slot_machine_spin(rows, cols, symbol):
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 ????
all_symbols.append(symbol)
columns = []
for _ in range(cols):
column = []
current_symbols = all_symbols[:]
for _ 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], "|")
else:
print(column[row],)
def deposit() -> int:
amount = 0
while amount == 0:
response = input("What would you like to depsoit? $")
if response.isdigit():
amount = int(response)
if amount == 0:
print(" Error: Amount must be greater than zero")
else:
print(" Error: Please enter a number")
return amount
def get_number_of_lines() -> int:
lines = 0
while lines < 1 or lines > MAX_LINES:
response = input("Enter the number of lines to bet on (1-" + str(MAX_LINES) + ")? ")
if response.isdigit():
lines = int(response)
if lines < 1 or lines > MAX_LINES:
print(" Error: Enter a valid number of lines.")
else:
print(" Error: Please enter a number")
return lines
def get_bet() -> int:
bet = 0
while bet < MIN_BET or bet > MAX_BET:
amount = input("What would you like to Bet on each line? $")
if amount.isdigit():
bet = int(amount)
if bet < MIN_BET or bet > MAX_BET:
print(f" Error: Amount must be between ${MIN_BET} - ${MAX_BET}.")
else:
print(" Error: Please enter a number")
return bet
def main():
balance = deposit()
lines = get_number_of_lines()
while True:
bet = get_bet()
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
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)
print_slotmachine(slots)
main()