Adding cmmonets to slot manchine
This commit is contained in:
		
							parent
							
								
									149634339b
								
							
						
					
					
						commit
						4419e4dd3b
					
				| 
						 | 
					@ -1,26 +1,50 @@
 | 
				
			||||||
import random
 | 
					import random
 | 
				
			||||||
from typing import List, Dict, Tuple
 | 
					from typing import List
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					if sys.platform == "win32":
 | 
				
			||||||
 | 
					    from colorama import just_fix_windows_console
 | 
				
			||||||
 | 
					    just_fix_windows_console()
 | 
				
			||||||
 | 
					from colorama import Fore, Back, Style
 | 
				
			||||||
 | 
					from termcolor import colored, cprint
 | 
				
			||||||
 | 
					#GLOBAL variables all caps becasue they are static and do not change.
 | 
				
			||||||
MAX_LINES = 3
 | 
					MAX_LINES = 3
 | 
				
			||||||
MAX_BET = 100
 | 
					MAX_BET = 100
 | 
				
			||||||
MIN_BET = 1
 | 
					MIN_BET = 1
 | 
				
			||||||
ROWS = 3
 | 
					ROWS = 3
 | 
				
			||||||
COLS = 3
 | 
					COLS = 3
 | 
				
			||||||
 | 
					#The list of sybmbols used in the slot machine. 
 | 
				
			||||||
SYMBOL_COUNT = {
 | 
					SYMBOL_COUNT = {
 | 
				
			||||||
    "A": 2,
 | 
					    "A": 2,
 | 
				
			||||||
    "B": 4,
 | 
					    "B": 4,
 | 
				
			||||||
    "C": 6,
 | 
					    "C": 6,
 | 
				
			||||||
    "D": 8
 | 
					    "D": 8,
 | 
				
			||||||
 | 
					    "\u06de": 1,
 | 
				
			||||||
 | 
					    "\u16b0": 2,
 | 
				
			||||||
 | 
					    "\u16ca": 2,
 | 
				
			||||||
 | 
					    "\u16d4": 2,
 | 
				
			||||||
 | 
					    "\u16f8": 2
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#The value when calculating bets of sybmbols used in the slot machine.
 | 
				
			||||||
SYMBOL_VALUE = {
 | 
					SYMBOL_VALUE = {
 | 
				
			||||||
    "A": 5,
 | 
					    "A": 5,
 | 
				
			||||||
    "B": 4,
 | 
					    "B": 4,
 | 
				
			||||||
    "C": 3,
 | 
					    "C": 3,
 | 
				
			||||||
    "D": 2
 | 
					    "D": 2,
 | 
				
			||||||
 | 
					    "\u06de": 5,
 | 
				
			||||||
 | 
					    "\u16b0": 5,
 | 
				
			||||||
 | 
					    "\u16ca": 5,
 | 
				
			||||||
 | 
					    "\u16d4": 5,
 | 
				
			||||||
 | 
					    "\u16f8": 5
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#The list of sybmbol colors used used in the slot machine.
 | 
				
			||||||
 | 
					SYMBOL_COLORS = {
 | 
				
			||||||
 | 
					    "A": Fore.CYAN,
 | 
				
			||||||
 | 
					    "B": Fore.GREEN,
 | 
				
			||||||
 | 
					    "C": Fore.LIGHTBLUE_EX,
 | 
				
			||||||
 | 
					    "D": Fore.RED,
 | 
				
			||||||
 | 
					    "\u06de": Fore.MAGENTA
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					# This function does the calculations for the bet to see if the user won or lost.
 | 
				
			||||||
def check_winings(columns: List, my_bet: int, my_lines: int):
 | 
					def check_winings(columns: List, my_bet: int, my_lines: int):
 | 
				
			||||||
    winnings = 0
 | 
					    winnings = 0
 | 
				
			||||||
    winning_lines = []
 | 
					    winning_lines = []
 | 
				
			||||||
| 
						 | 
					@ -37,7 +61,7 @@ def check_winings(columns: List, my_bet: int, my_lines: int):
 | 
				
			||||||
    return winnings, winning_lines
 | 
					    return winnings, winning_lines
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
# This function will 
 | 
					# This function is for getting the symbols randomly
 | 
				
			||||||
def get_slot_machine_spin() -> List:
 | 
					def get_slot_machine_spin() -> List:
 | 
				
			||||||
    all_symbols = []
 | 
					    all_symbols = []
 | 
				
			||||||
    # this is so as it picks from the list it gets the values and the index
 | 
					    # this is so as it picks from the list it gets the values and the index
 | 
				
			||||||
| 
						 | 
					@ -54,15 +78,15 @@ def get_slot_machine_spin() -> List:
 | 
				
			||||||
            column.append(value)
 | 
					            column.append(value)
 | 
				
			||||||
        columns.append(column)
 | 
					        columns.append(column)
 | 
				
			||||||
    return columns
 | 
					    return columns
 | 
				
			||||||
 | 
					#This function shows the rows and cloumns in a display like a real machine.
 | 
				
			||||||
def print_slotmachine(columns: List):
 | 
					def print_slotmachine(columns: List):
 | 
				
			||||||
    for row in range(ROWS):
 | 
					    for row in range(ROWS):
 | 
				
			||||||
        for index, column in enumerate(columns):
 | 
					        for index, column in enumerate(columns):
 | 
				
			||||||
            if index != COLS - 1:
 | 
					            if index != COLS - 1:
 | 
				
			||||||
                print(column[row], "| ", end='')
 | 
					                print(SYMBOL_COLORS[column[row]] + column[row] + Fore.RESET, "| ", end='')
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            print(column[row])
 | 
					            print(SYMBOL_COLORS[column[row]] + column[row] + Fore.RESET)
 | 
				
			||||||
 | 
					#THis function takes the deposit or inoput of dollar amount from user. 
 | 
				
			||||||
def deposit() -> int:
 | 
					def deposit() -> int:
 | 
				
			||||||
    amount = 0 
 | 
					    amount = 0 
 | 
				
			||||||
    while amount == 0:
 | 
					    while amount == 0:
 | 
				
			||||||
| 
						 | 
					@ -70,11 +94,11 @@ def deposit() -> int:
 | 
				
			||||||
        if response.isdigit():
 | 
					        if response.isdigit():
 | 
				
			||||||
            amount = int(response)
 | 
					            amount = int(response)
 | 
				
			||||||
            if amount == 0:
 | 
					            if amount == 0:
 | 
				
			||||||
                print("   Error: Amount must be greater than zero")
 | 
					                print(Fore.RED + "   Error: Amount must be greater than zero" + Fore.RESET)
 | 
				
			||||||
        else: 
 | 
					        else: 
 | 
				
			||||||
            print("   Error: Please enter a number")
 | 
					            print(Fore.RED + "   Error: Please enter a number" + Fore.RESET)
 | 
				
			||||||
    return amount
 | 
					    return amount
 | 
				
			||||||
 | 
					#This function asks the user how many rows are they betting on 1 to 3
 | 
				
			||||||
def get_number_of_lines() -> int:
 | 
					def get_number_of_lines() -> int:
 | 
				
			||||||
    lines = 0
 | 
					    lines = 0
 | 
				
			||||||
    while lines < 1 or lines > MAX_LINES:
 | 
					    while lines < 1 or lines > MAX_LINES:
 | 
				
			||||||
| 
						 | 
					@ -87,7 +111,7 @@ def get_number_of_lines() -> int:
 | 
				
			||||||
                print("   Error: Please enter a number")
 | 
					                print("   Error: Please enter a number")
 | 
				
			||||||
    return lines
 | 
					    return lines
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#This function asks the user how much they want to bet on each line. 
 | 
				
			||||||
def get_bet() -> int:
 | 
					def get_bet() -> int:
 | 
				
			||||||
    bet = 0
 | 
					    bet = 0
 | 
				
			||||||
    while bet < MIN_BET or  bet > MAX_BET:
 | 
					    while bet < MIN_BET or  bet > MAX_BET:
 | 
				
			||||||
| 
						 | 
					@ -99,15 +123,13 @@ def get_bet() -> int:
 | 
				
			||||||
        else: 
 | 
					        else: 
 | 
				
			||||||
            print("  Error: Please enter a number")
 | 
					            print("  Error: Please enter a number")
 | 
				
			||||||
    return bet
 | 
					    return bet
 | 
				
			||||||
 | 
					#This takes the bet rows and random sybmols from other functions and spits out if they win or lose and how much. 
 | 
				
			||||||
def roll(balance) -> int:
 | 
					def roll(balance) -> int:
 | 
				
			||||||
    balance = deposit()
 | 
					 | 
				
			||||||
    lines = get_number_of_lines()
 | 
					    lines = get_number_of_lines()
 | 
				
			||||||
    bet = -1
 | 
					    bet = -1
 | 
				
			||||||
    total_bet = balance + 1
 | 
					    total_bet = balance + 1
 | 
				
			||||||
    while bet != 0 and total_bet > balance:
 | 
					    while bet != 0 and total_bet > balance:
 | 
				
			||||||
        bet = get_bet()
 | 
					        bet = get_bet()
 | 
				
			||||||
        print(f"___{bet}_{lines}")
 | 
					 | 
				
			||||||
        total_bet = bet * lines
 | 
					        total_bet = bet * lines
 | 
				
			||||||
        if total_bet > balance:
 | 
					        if total_bet > balance:
 | 
				
			||||||
            print(f"  Error: You do not have enough to bet that amount, curent balance is: ${balance} ")
 | 
					            print(f"  Error: You do not have enough to bet that amount, curent balance is: ${balance} ")
 | 
				
			||||||
| 
						 | 
					@ -121,26 +143,26 @@ def roll(balance) -> int:
 | 
				
			||||||
    print(f"You won ${winnings}.")
 | 
					    print(f"You won ${winnings}.")
 | 
				
			||||||
    if len(winning_lines) > 0:
 | 
					    if len(winning_lines) > 0:
 | 
				
			||||||
        print(f"You won on line" + ("s" if len(winning_lines) > 1 else "") + ":", *winning_lines)
 | 
					        print(f"You won on line" + ("s" if len(winning_lines) > 1 else "") + ":", *winning_lines)
 | 
				
			||||||
        balance += winnings
 | 
					        balance = balance + winnings
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        balance -= bet * lines
 | 
					        print(f"You lost your bet of ${bet} on {lines} lines for a total loss of ${bet*lines}")
 | 
				
			||||||
    print(f"Your balance is now: ${balance}")
 | 
					        balance = balance - (bet * lines)
 | 
				
			||||||
    # Should be returning "balance"
 | 
					    return balance
 | 
				
			||||||
    # "winnings - total_bet" is not at all correct
 | 
					#This loop is the playing fucntion that takes the bet and seees if they have anymore mony to bet with or if they want to keep going.
 | 
				
			||||||
    return winnings - total_bet
 | 
					def main():
 | 
				
			||||||
 | 
					 | 
				
			||||||
# main() does not return a value so should not be type hinted
 | 
					 | 
				
			||||||
def main() -> int:
 | 
					 | 
				
			||||||
    balance = deposit()
 | 
					    balance = deposit()
 | 
				
			||||||
    # Using "while True" requires a break to exit.
 | 
					    # Using "while True" requires a break to exit.
 | 
				
			||||||
    # Should instead be a conditional that tracks the actual exit conditions
 | 
					    # Should instead be a conditional that tracks the actual exit conditions
 | 
				
			||||||
    while True:
 | 
					    playing = True
 | 
				
			||||||
 | 
					    while playing is True:
 | 
				
			||||||
 | 
					        balance = roll(balance)
 | 
				
			||||||
        print(f"Current Balance is ${balance}")
 | 
					        print(f"Current Balance is ${balance}")
 | 
				
			||||||
 | 
					        if balance > 0:
 | 
				
			||||||
            answer = input("Press enter to play (q to quit).")
 | 
					            answer = input("Press enter to play (q to quit).")
 | 
				
			||||||
        if answer == "q":
 | 
					            if answer.lower() == "q":
 | 
				
			||||||
            break
 | 
					                playing = False
 | 
				
			||||||
        balance += roll(balance)
 | 
					        else:
 | 
				
			||||||
    
 | 
					            playing = False
 | 
				
			||||||
    print(f"You left with ${balance}")
 | 
					    print(f"You left with ${balance}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
main()
 | 
					main()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user