Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Welcome to Nathan's Casino!! The program gets executed at the very bottom.
- #import module
- import random
- #List of Available Games - and their command keys
- games_available = {
- 0: ["Leave Nathan's Casino"],
- 1: ["Heads or Tails"],
- 2: ["Cho Han"],
- 3: ["Casino War"]
- }
- #Valid player inputs
- yes_answers = ["y", "yes", "Y", "Yes", "YES"]
- no_answers = ["n", "no", "N", "NO", "No"]
- even_input = ["e", "even", "E", "Even"]
- odd_input = ["o", "O", "Odd", "odd"]
- help_input = ["h", "help", "Help", "help", "?"]
- #Global stuff to make it run properly
- #Variables for counting and printing the number of games available
- count = 3
- games = str(count)
- #Values
- starting_money = 100
- money = 100
- def number_of_games():
- print(games)
- def print_games():
- for key in games_available.keys():
- for value in games_available[key]:
- print(key,value)
- Card_deck = [
- "2 of Spades",
- "3 of Spades",
- "4 of Spades",
- "5 of Spades",
- "6 of Spades",
- "7 of Spades",
- "8 of Spades",
- "9 of Spades",
- "10 of Spades",
- "Jack of Spades",
- "Queen of Spades",
- "King of Spades",
- "Ace of Spades",
- "2 of Clubs",
- "3 of Clubs",
- "4 of Clubs",
- "5 of Clubs",
- "6 of Clubs",
- "7 of Clubs",
- "8 of Clubs",
- "9 of Clubs",
- "10 of Clubs",
- "Jack of Clubs",
- "Queen of Clubs",
- "King of Clubs",
- "Ace of Clubs",
- "2 of Diamonds",
- "3 of Diamonds",
- "4 of Diamonds",
- "5 of Diamonds",
- "6 of Diamonds",
- "7 of Diamonds",
- "8 of Diamonds",
- "9 of Diamonds",
- "10 of Diamonds",
- "Jack of Diamonds",
- "Queen of Diamonds",
- "King of Diamonds",
- "Ace of Diamonds",
- "2 of Hearts",
- "3 of Hearts",
- "4 of Hearts",
- "5 of Hearts",
- "6 of Hearts",
- "7 of Hearts",
- "8 of Hearts",
- "9 of Hearts",
- "10 of Hearts",
- "Jack of Hearts",
- "Queen of Hearts",
- "King of Hearts",
- "Ace of Hearts",
- ]
- random1 = 1
- random2 = 1
- def casino_war_points():
- global random1point
- global random1
- global random2
- global random2point
- if "2" in random1:
- random1point = 2
- elif "3" in random1:
- random1point = 3
- elif "4" in random1:
- random1point = 4
- elif "5" in random1:
- random1point = 5
- elif "6" in random1:
- random1point = 6
- elif "7" in random1:
- random1point = 7
- elif "8" in random1:
- random1point = 8
- elif "9" in random1:
- random1point = 9
- else:
- random1point = 10
- if "2" in random2:
- random2point = 2
- elif "3" in random2:
- random2point = 3
- elif "4" in random2:
- random2point = 4
- elif "5" in random2:
- random2point = 5
- elif "6" in random2:
- random2point = 6
- elif "7" in random2:
- random2point = 7
- elif "8" in random2:
- random2point = 8
- elif "9" in random2:
- random2point = 9
- else:
- random2point = 10
- def print_casino_war_result():
- global random1point
- global random1
- global random2
- global random2point
- random1 = random.choice(Card_deck)
- random2 = random.choice(Card_deck)
- casino_war_points()
- games_played()
- print("You drew " + random1 + " for a value of " + str(random1point))
- print("The house draws " + random2 + " for " + str(random2point) + " points")
- casino_war_win_or_lose()
- def unique_random2():
- global random1
- global random2
- if random2 == random1:
- random2 = random.choice(Card_deck)
- unique_random2()
- else:
- random2 = random2
- def casino_war_win_or_lose():
- global random1point
- global random2point
- if random1point > random2point:
- win()
- elif random2point > random1point:
- lose()
- else:
- tie()
- def games_won():
- wins = 0
- wins += 1
- return wins
- win_percent = 0
- def games_won_percent():
- global wins
- global win_percent
- win_percent = wins / games_played()
- return win_percent
- #Betting scenarios! Wins and losses
- #What happens if player wins
- def win():
- global money
- global bet
- money = money + bet
- print("You win! New total: $" + str(money))
- dividers()
- games_won()
- return money
- #What happens if player loses
- def lose():
- global money
- global bet
- money = money - bet
- if money > 0:
- print("Sorry, you lost. New total: $" + str(money))
- dividers()
- else:
- print("Oh oh! Looks like you're all out of money. Well, it was nice having you, be sure to come back again soon.")
- print("But we sure had some fun playing those " + str(games_number) + " games together, didn't we?")
- print("Btw, if you are keeping track - you won " + str(win_percent) + "% of games.")
- exit()
- return money
- def tie():
- global money
- global bet
- money = money
- print("Wow! A tie. You don't see that often. Here's your bet back for a total of: $" + str(money))
- dividers()
- return money
- #How I standardised the spacing to make life simpler
- def dividers():
- print("-------------------------------")
- #Asking the user how much they want to bet and checking if it is valid
- def bet_amount():
- global bet
- global money
- bet = input("How much would you like to bet? ")
- if bet in help_input:
- helpall()
- bet_amount()
- else:
- try:
- bet = int(bet)
- #Do they have sufficient funds?
- if money - bet < 0:
- dividers()
- print("Insufficient funds. You have: $" + str(money))
- bet_amount()
- else:
- dividers()
- print("Okay, betting $" + str(bet))
- #Did they put in a valid whole number?
- except ValueError:
- try:
- bet = float(bet)
- if int(bet) - bet != 0:
- print("Sorry, the Casino doesn't do half bets")
- bet_amount()
- else:
- bet = int(bet)
- dividers()
- print("Okay, betting $" + str(bet))
- except ValueError:
- print("Sorry, this Casino accepts cash only.")
- bet_amount()
- return bet
- #Standardised printing of starting cash
- def current_balance():
- print("Cash: $" + str(money))
- #Specifically for Heads or Tails - is there a valid bet? If it was all one function if there was an invalid bet it would
- #return the player to the bet amount not the bet type
- def headsortails_validbet():
- global money
- global bet
- heads_input = ["h", "H", "Heads", "heads", "Heads!" "heads!"]
- tails_input = ["t", "T", "Tails", "tails", "Tails!", "tails!"]
- guess = input("Heads of Tails?: ")
- num = random.randint(1, 2)
- # Checks to see if valid guess
- if guess in heads_input or guess in tails_input:
- dividers()
- print("Dealer flips coin")
- if num == 1:
- print("Heads!")
- else:
- print("Tails!")
- dividers()
- games_played()
- if guess in heads_input or guess in tails_input:
- # Coin = Heads
- if num == 1 and guess in heads_input or num == 2 and guess in tails_input:
- win()
- else:
- lose()
- # Invalid Bet
- elif guess in help_input:
- helpall()
- headsortails_validbet()
- else:
- dividers()
- print("Sorry, that is an invalid bet! Please, heads or tails only")
- headsortails_validbet()
- #Heads or Tails: The Game
- def headsortails():
- #Pulls Players Cash and allows function to rewrite the money value
- global money
- global bet
- dividers()
- print("You chose the classic Heads or Tails game")
- current_balance()
- bet_amount()
- headsortails_validbet()
- play_again()
- def casino_war():
- global money
- global bet
- dividers()
- print("Time to play a war!!")
- current_balance()
- bet_amount()
- print_casino_war_result()
- play_again()
- #Checking to see if it is a valid guess in cho han
- def cho_han_guess():
- global guess
- guess = input("Odd or Even?: ")
- if guess in even_input:
- dividers()
- print("Even it is!")
- elif guess in odd_input:
- dividers()
- print("You're betting odd")
- elif guess in help_input:
- helpall()
- else:
- dividers()
- print("Sorry, that is an invalid bet! Please, even or odd only")
- cho_han_guess()
- games_number = 0
- def games_played():
- global games_number
- games_number += 1
- return games_number
- #Cho Han - The Game
- def cho_han():
- #Gives function access to global variables
- global money
- global bet
- global guess
- #prints nice lines, game name and cash balance
- dividers()
- print("You chose Cho Han")
- current_balance()
- #Player enters bet
- bet_amount()
- #Player enters guess - seperate function in case of invalid guess so they don't have to restart at top of this and reprint game selection and cash balance
- cho_han_guess()
- #print nice
- dividers()
- #random numbers chosen
- num1 = random.randint(1, 6)
- num2 = random.randint(1, 6)
- #total number
- num = num1 + num2
- games_played()
- #inofrms player of number chosen
- print("Dealer rolls the dice. They are: " + str(num1) + " & " + str(num2) + "..... The total is " + str(num))
- #Was it even or odd
- if num % 2 == 0:
- print("That's an even number!")
- else:
- print("That's an odd number!")
- #Did player win or lose?
- if num % 2 == 0 and guess in even_input or num % 2 != 0 and guess in odd_input:
- win()
- else:
- lose()
- #Offers choice to try again
- play_again()
- #Converts the player entry into a game to run
- def game_choice():
- global game_selected
- if str(game_selected) == "1":
- headsortails()
- elif str(game_selected) == "2":
- cho_han()
- elif str(game_selected) == "0":
- dividers()
- print("Sorry to see you go!")
- print("You left Nathan's Casino with $" + str(money) + " after playing " + str(games_number) + " games")
- print("Btw, if you are keeping track - you won " + str(win_percent) + "% of games")
- dividers()
- exit()
- elif str(game_selected) == "3":
- casino_war()
- elif game_selected in help_input:
- helpall()
- else:
- dividers()
- print("That was not a valid game entry.")
- dividers()
- print_games()
- game_selected = input("What game would you like to play?: ")
- run_casino_game()
- #How the program knows which game to run
- def run_casino_game():
- global game_selected
- game_selected = input("Okay, what game would you like to play?: ")
- if game_selected in help_input:
- helpall()
- else:
- game_choice()
- play_again = input("Would you like to play again?: ")
- if play_again in yes_answers:
- run_casino_game()
- elif play_again in no_answers:
- game_selected = input("Okay, what game would you like to play?: \nOr do you want to leave? (0)")
- elif play_again in help_input:
- helpall()
- run_casino_game()
- def play_again():
- global game_selected
- again_input = input("Would you like to play again?: ")
- if again_input in yes_answers:
- print("Okay, let's play again")
- game_choice()
- elif again_input in no_answers:
- print_games()
- run_casino_game()
- elif again_input in help_input:
- helpall()
- else:
- print("Sorry, I didn't get that. What did you say?")
- play_again()
- def welcome():
- global game_selected
- global count
- dividers()
- print("Welcome to Nathan's Casino! I see you bought $" + str(money) + " with you. \nWe have " + str(games) + " games that you can play. These are: ")
- #List of games
- print_games()
- #Player Chooses Game Selection
- #Run the appropriate game based on player input
- print("If you don't understand something, just ask for help")
- run_casino_game()
- def helpall():
- global game_help
- dividers()
- print_games()
- game_help = input("Welcome to Nathan's Help Desk.\nWhat game would you like help with?: ")
- help_type()
- def help_leave():
- print("This is how you leave my casino. \nWhen selecting a game, you can type the 0 in to leave. But don't go!\n.................\n.................at least\n.................\nnot while you still have money anyway")
- dividers()
- help_still()
- def help_type():
- global game_help
- if game_help == "1":
- dividers()
- help_heads()
- elif game_help == "2":
- dividers()
- help_cho_han()
- elif game_help == "3":
- dividers()
- help_casino_war()
- elif game_help == "0":
- dividers()
- help_leave()
- else:
- dividers()
- print("Sorry, I didn't get that. What did you say?")
- game_help = input("What game would you like help with?: ")
- help_type()
- def help_heads():
- print("Heads or Tails?\nIt's literally flipping a coin.")
- dividers()
- help_still()
- def help_cho_han():
- print("In Cho Han, two 6 sided dice are rolled. \nYou bet on whether the result will be odd or even")
- dividers()
- help_still()
- def help_casino_war():
- print("This game is a battle between the house and you.\nWe each draw a card and see who has the highest value card.\nPicture cards and Aces are worth 10 (J, Q, K, A)")
- dividers()
- help_still()
- def help_still():
- more_help = input("Do you still need help?")
- if more_help in yes_answers:
- helpall()
- elif more_help in no_answers:
- print("Okay, got it.")
- else:
- print("Sorry, I didn't get that.")
- help_still()
- dividers()
- def help_start():
- if input == help_input:
- helpall()
- #ONE COMMAND TO RULE THEM ALLLLLLLL
- welcome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement