This question already has an answer here:
My friend and I have spent over 6 hours on this slot machine for class. The only downfall is that it needs to check for a WILD card, for example, cherry, cherry, WILD would give the cherry tier. If i don't have to test for "WILD" this program works great, it's when my IF statements need to check for the wildcard that it get hung up on whatever condition it hits first. For example, cherry, grape, pineapple, will auto-reward the cherry tier despite there only being one. Any sort of insight on this would be great. Thank you.
import random as r
import time
reelOne = ["cherry", "cherry", "cherry", "grape", "grape", "pineapple", "WILD"]
reelTwo = ["cherry", "cherry", "cherry", "grape", "grape", "pineapple", "WILD"]
reelThree = ["cherry", "cherry", "cherry", "grape", "grape", "pineapple", "WILD"]
balance = 50
jackpot = 100
wager = 0
def spinMachine():
global balance, jackpot, wager
r1_choice = r.choice(reelOne)
r2_choice = r.choice(reelTwo)
r3_choice = r.choice(reelThree)
time.sleep(0.4)
print(" (", "<", r1_choice, ">", end=' | ', flush=True)
time.sleep(0.8)
print("<", r2_choice, ">", end=' | ', flush=True)
time.sleep(1.0)
print("<", r3_choice, ">", end=' )', flush=True,)
time.sleep(1.5)
if r1_choice == "WILD" and r1_choice == r2_choice and r2_choice == r3_choice:
print("JACKPOT!")
print("You win", jackpot, "tokens")
balance += jackpot
print("You now have", balance, "tokens")
jackpot = 100
elif r1_choice == "cherry" or "WILD" and r1_choice == r2_choice or "WILD" and r2_choice == r3_choice or "WILD":
print("You win 5 tokens")
balance += (wager + 5)
print("You now have", balance, "tokens")
elif r1_choice == "grape" or "WILD" and r1_choice == r2_choice or "WILD" and r2_choice == r3_choice or "WILD":
print("You win 15 tokens")
balance += (wager + 15)
print("You now have", balance, "tokens")
elif r1_choice == "pineapple" or "WILD" and r1_choice == r2_choice or "WILD" and r2_choice == r3_choice or "WILD":
print("You win 25 tokens")
balance += (wager + 25)
print("You now have", balance, "tokens")
else:
print("You lose!!")
print("Adding lost tokens to Jackpot...")
jackpot += wager
balance = balance - wager
def betMenu():
global balance, wager
wager = int(input("How many credits would you like to bet?: "))
balance = balance - wager
mainMenu()
def mainMenu():
print("Welcome to the Slots")
print("Your balance is", balance)
print("Current inserted credits: ", wager)
print("-------------------------------------------")
print("Press [1] to add credit")
print("Press [2] to spin the slot machine!")
print("Press [3] to quit")
userChoice = int(input("Selection: "))
if userChoice == 1:
betMenu()
elif userChoice == 2:
spinMachine()
elif userChoice == 3:
print("Thanks for playing!")
exit()
while balance > 0:
mainMenu()
Aucun commentaire:
Enregistrer un commentaire