Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.13 KB | None | 0 0
  1. #Welcome to Nathan's Casino!! The program gets executed at the very bottom.
  2.  
  3. #import module
  4. import random
  5.  
  6. #List of Available Games - and their command keys
  7. games_available = {
  8. 0: ["Leave Nathan's Casino"],
  9. 1: ["Heads or Tails"],
  10. 2: ["Cho Han"],
  11. 3: ["Casino War"]
  12. }
  13.  
  14. #Valid player inputs
  15. yes_answers = ["y", "yes", "Y", "Yes", "YES"]
  16. no_answers = ["n", "no", "N", "NO", "No"]
  17. even_input = ["e", "even", "E", "Even"]
  18. odd_input = ["o", "O", "Odd", "odd"]
  19. help_input = ["h", "help", "Help", "help", "?"]
  20.  
  21. #Global stuff to make it run properly
  22. #Variables for counting and printing the number of games available
  23. count = 3
  24. games = str(count)
  25. #Values
  26. starting_money = 100
  27. money = 100
  28.  
  29. def number_of_games():
  30. print(games)
  31.  
  32. def print_games():
  33. for key in games_available.keys():
  34. for value in games_available[key]:
  35. print(key,value)
  36.  
  37. Card_deck = [
  38. "2 of Spades",
  39. "3 of Spades",
  40. "4 of Spades",
  41. "5 of Spades",
  42. "6 of Spades",
  43. "7 of Spades",
  44. "8 of Spades",
  45. "9 of Spades",
  46. "10 of Spades",
  47. "Jack of Spades",
  48. "Queen of Spades",
  49. "King of Spades",
  50. "Ace of Spades",
  51. "2 of Clubs",
  52. "3 of Clubs",
  53. "4 of Clubs",
  54. "5 of Clubs",
  55. "6 of Clubs",
  56. "7 of Clubs",
  57. "8 of Clubs",
  58. "9 of Clubs",
  59. "10 of Clubs",
  60. "Jack of Clubs",
  61. "Queen of Clubs",
  62. "King of Clubs",
  63. "Ace of Clubs",
  64. "2 of Diamonds",
  65. "3 of Diamonds",
  66. "4 of Diamonds",
  67. "5 of Diamonds",
  68. "6 of Diamonds",
  69. "7 of Diamonds",
  70. "8 of Diamonds",
  71. "9 of Diamonds",
  72. "10 of Diamonds",
  73. "Jack of Diamonds",
  74. "Queen of Diamonds",
  75. "King of Diamonds",
  76. "Ace of Diamonds",
  77. "2 of Hearts",
  78. "3 of Hearts",
  79. "4 of Hearts",
  80. "5 of Hearts",
  81. "6 of Hearts",
  82. "7 of Hearts",
  83. "8 of Hearts",
  84. "9 of Hearts",
  85. "10 of Hearts",
  86. "Jack of Hearts",
  87. "Queen of Hearts",
  88. "King of Hearts",
  89. "Ace of Hearts",
  90. ]
  91.  
  92. random1 = 1
  93. random2 = 1
  94.  
  95. def casino_war_points():
  96. global random1point
  97. global random1
  98. global random2
  99. global random2point
  100. if "2" in random1:
  101. random1point = 2
  102. elif "3" in random1:
  103. random1point = 3
  104. elif "4" in random1:
  105. random1point = 4
  106. elif "5" in random1:
  107. random1point = 5
  108. elif "6" in random1:
  109. random1point = 6
  110. elif "7" in random1:
  111. random1point = 7
  112. elif "8" in random1:
  113. random1point = 8
  114. elif "9" in random1:
  115. random1point = 9
  116. else:
  117. random1point = 10
  118. if "2" in random2:
  119. random2point = 2
  120. elif "3" in random2:
  121. random2point = 3
  122. elif "4" in random2:
  123. random2point = 4
  124. elif "5" in random2:
  125. random2point = 5
  126. elif "6" in random2:
  127. random2point = 6
  128. elif "7" in random2:
  129. random2point = 7
  130. elif "8" in random2:
  131. random2point = 8
  132. elif "9" in random2:
  133. random2point = 9
  134. else:
  135. random2point = 10
  136.  
  137. def print_casino_war_result():
  138. global random1point
  139. global random1
  140. global random2
  141. global random2point
  142. random1 = random.choice(Card_deck)
  143. random2 = random.choice(Card_deck)
  144. casino_war_points()
  145. games_played()
  146. print("You drew " + random1 + " for a value of " + str(random1point))
  147. print("The house draws " + random2 + " for " + str(random2point) + " points")
  148. casino_war_win_or_lose()
  149. def unique_random2():
  150. global random1
  151. global random2
  152. if random2 == random1:
  153. random2 = random.choice(Card_deck)
  154. unique_random2()
  155. else:
  156. random2 = random2
  157. def casino_war_win_or_lose():
  158. global random1point
  159. global random2point
  160. if random1point > random2point:
  161. win()
  162. elif random2point > random1point:
  163. lose()
  164. else:
  165. tie()
  166.  
  167. def games_won():
  168. wins = 0
  169. wins += 1
  170. return wins
  171.  
  172. win_percent = 0
  173.  
  174. def games_won_percent():
  175. global wins
  176. global win_percent
  177. win_percent = wins / games_played()
  178. return win_percent
  179.  
  180. #Betting scenarios! Wins and losses
  181. #What happens if player wins
  182. def win():
  183. global money
  184. global bet
  185. money = money + bet
  186. print("You win! New total: $" + str(money))
  187. dividers()
  188. games_won()
  189. return money
  190. #What happens if player loses
  191. def lose():
  192. global money
  193. global bet
  194. money = money - bet
  195. if money > 0:
  196. print("Sorry, you lost. New total: $" + str(money))
  197. dividers()
  198. else:
  199. print("Oh oh! Looks like you're all out of money. Well, it was nice having you, be sure to come back again soon.")
  200. print("But we sure had some fun playing those " + str(games_number) + " games together, didn't we?")
  201. print("Btw, if you are keeping track - you won " + str(win_percent) + "% of games.")
  202. exit()
  203. return money
  204.  
  205. def tie():
  206. global money
  207. global bet
  208. money = money
  209. print("Wow! A tie. You don't see that often. Here's your bet back for a total of: $" + str(money))
  210. dividers()
  211. return money
  212.  
  213. #How I standardised the spacing to make life simpler
  214. def dividers():
  215. print("-------------------------------")
  216.  
  217. #Asking the user how much they want to bet and checking if it is valid
  218. def bet_amount():
  219. global bet
  220. global money
  221. bet = input("How much would you like to bet? ")
  222. if bet in help_input:
  223. helpall()
  224. bet_amount()
  225. else:
  226. try:
  227. bet = int(bet)
  228. #Do they have sufficient funds?
  229. if money - bet < 0:
  230. dividers()
  231. print("Insufficient funds. You have: $" + str(money))
  232. bet_amount()
  233. else:
  234. dividers()
  235. print("Okay, betting $" + str(bet))
  236. #Did they put in a valid whole number?
  237. except ValueError:
  238. try:
  239. bet = float(bet)
  240. if int(bet) - bet != 0:
  241. print("Sorry, the Casino doesn't do half bets")
  242. bet_amount()
  243. else:
  244. bet = int(bet)
  245. dividers()
  246. print("Okay, betting $" + str(bet))
  247. except ValueError:
  248. print("Sorry, this Casino accepts cash only.")
  249. bet_amount()
  250. return bet
  251.  
  252. #Standardised printing of starting cash
  253. def current_balance():
  254. print("Cash: $" + str(money))
  255.  
  256. #Specifically for Heads or Tails - is there a valid bet? If it was all one function if there was an invalid bet it would
  257. #return the player to the bet amount not the bet type
  258. def headsortails_validbet():
  259. global money
  260. global bet
  261. heads_input = ["h", "H", "Heads", "heads", "Heads!" "heads!"]
  262. tails_input = ["t", "T", "Tails", "tails", "Tails!", "tails!"]
  263. guess = input("Heads of Tails?: ")
  264. num = random.randint(1, 2)
  265. # Checks to see if valid guess
  266. if guess in heads_input or guess in tails_input:
  267. dividers()
  268. print("Dealer flips coin")
  269. if num == 1:
  270. print("Heads!")
  271. else:
  272. print("Tails!")
  273. dividers()
  274. games_played()
  275. if guess in heads_input or guess in tails_input:
  276. # Coin = Heads
  277. if num == 1 and guess in heads_input or num == 2 and guess in tails_input:
  278. win()
  279. else:
  280. lose()
  281. # Invalid Bet
  282. elif guess in help_input:
  283. helpall()
  284. headsortails_validbet()
  285. else:
  286. dividers()
  287. print("Sorry, that is an invalid bet! Please, heads or tails only")
  288. headsortails_validbet()
  289.  
  290. #Heads or Tails: The Game
  291. def headsortails():
  292. #Pulls Players Cash and allows function to rewrite the money value
  293. global money
  294. global bet
  295. dividers()
  296. print("You chose the classic Heads or Tails game")
  297. current_balance()
  298. bet_amount()
  299. headsortails_validbet()
  300. play_again()
  301.  
  302. def casino_war():
  303. global money
  304. global bet
  305. dividers()
  306. print("Time to play a war!!")
  307. current_balance()
  308. bet_amount()
  309. print_casino_war_result()
  310. play_again()
  311.  
  312.  
  313. #Checking to see if it is a valid guess in cho han
  314. def cho_han_guess():
  315. global guess
  316. guess = input("Odd or Even?: ")
  317. if guess in even_input:
  318. dividers()
  319. print("Even it is!")
  320. elif guess in odd_input:
  321. dividers()
  322. print("You're betting odd")
  323. elif guess in help_input:
  324. helpall()
  325. else:
  326. dividers()
  327. print("Sorry, that is an invalid bet! Please, even or odd only")
  328. cho_han_guess()
  329.  
  330. games_number = 0
  331.  
  332. def games_played():
  333. global games_number
  334. games_number += 1
  335. return games_number
  336.  
  337. #Cho Han - The Game
  338. def cho_han():
  339. #Gives function access to global variables
  340. global money
  341. global bet
  342. global guess
  343. #prints nice lines, game name and cash balance
  344. dividers()
  345. print("You chose Cho Han")
  346. current_balance()
  347. #Player enters bet
  348. bet_amount()
  349. #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
  350. cho_han_guess()
  351. #print nice
  352. dividers()
  353. #random numbers chosen
  354. num1 = random.randint(1, 6)
  355. num2 = random.randint(1, 6)
  356. #total number
  357. num = num1 + num2
  358. games_played()
  359. #inofrms player of number chosen
  360. print("Dealer rolls the dice. They are: " + str(num1) + " & " + str(num2) + "..... The total is " + str(num))
  361. #Was it even or odd
  362. if num % 2 == 0:
  363. print("That's an even number!")
  364. else:
  365. print("That's an odd number!")
  366. #Did player win or lose?
  367. if num % 2 == 0 and guess in even_input or num % 2 != 0 and guess in odd_input:
  368. win()
  369. else:
  370. lose()
  371. #Offers choice to try again
  372. play_again()
  373.  
  374. #Converts the player entry into a game to run
  375. def game_choice():
  376. global game_selected
  377. if str(game_selected) == "1":
  378. headsortails()
  379. elif str(game_selected) == "2":
  380. cho_han()
  381. elif str(game_selected) == "0":
  382. dividers()
  383. print("Sorry to see you go!")
  384. print("You left Nathan's Casino with $" + str(money) + " after playing " + str(games_number) + " games")
  385. print("Btw, if you are keeping track - you won " + str(win_percent) + "% of games")
  386. dividers()
  387. exit()
  388. elif str(game_selected) == "3":
  389. casino_war()
  390. elif game_selected in help_input:
  391. helpall()
  392. else:
  393. dividers()
  394. print("That was not a valid game entry.")
  395. dividers()
  396. print_games()
  397. game_selected = input("What game would you like to play?: ")
  398. run_casino_game()
  399.  
  400.  
  401. #How the program knows which game to run
  402. def run_casino_game():
  403. global game_selected
  404. game_selected = input("Okay, what game would you like to play?: ")
  405. if game_selected in help_input:
  406. helpall()
  407. else:
  408. game_choice()
  409. play_again = input("Would you like to play again?: ")
  410. if play_again in yes_answers:
  411. run_casino_game()
  412. elif play_again in no_answers:
  413. game_selected = input("Okay, what game would you like to play?: \nOr do you want to leave? (0)")
  414. elif play_again in help_input:
  415. helpall()
  416. run_casino_game()
  417.  
  418. def play_again():
  419. global game_selected
  420. again_input = input("Would you like to play again?: ")
  421. if again_input in yes_answers:
  422. print("Okay, let's play again")
  423. game_choice()
  424. elif again_input in no_answers:
  425. print_games()
  426. run_casino_game()
  427. elif again_input in help_input:
  428. helpall()
  429. else:
  430. print("Sorry, I didn't get that. What did you say?")
  431. play_again()
  432.  
  433. def welcome():
  434. global game_selected
  435. global count
  436. dividers()
  437. 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: ")
  438. #List of games
  439. print_games()
  440. #Player Chooses Game Selection
  441. #Run the appropriate game based on player input
  442. print("If you don't understand something, just ask for help")
  443. run_casino_game()
  444.  
  445. def helpall():
  446. global game_help
  447. dividers()
  448. print_games()
  449. game_help = input("Welcome to Nathan's Help Desk.\nWhat game would you like help with?: ")
  450. help_type()
  451.  
  452. def help_leave():
  453. 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")
  454. dividers()
  455. help_still()
  456.  
  457. def help_type():
  458. global game_help
  459. if game_help == "1":
  460. dividers()
  461. help_heads()
  462. elif game_help == "2":
  463. dividers()
  464. help_cho_han()
  465. elif game_help == "3":
  466. dividers()
  467. help_casino_war()
  468. elif game_help == "0":
  469. dividers()
  470. help_leave()
  471. else:
  472. dividers()
  473. print("Sorry, I didn't get that. What did you say?")
  474. game_help = input("What game would you like help with?: ")
  475. help_type()
  476.  
  477. def help_heads():
  478. print("Heads or Tails?\nIt's literally flipping a coin.")
  479. dividers()
  480. help_still()
  481.  
  482. def help_cho_han():
  483. print("In Cho Han, two 6 sided dice are rolled. \nYou bet on whether the result will be odd or even")
  484. dividers()
  485. help_still()
  486.  
  487. def help_casino_war():
  488. 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)")
  489. dividers()
  490. help_still()
  491.  
  492. def help_still():
  493. more_help = input("Do you still need help?")
  494. if more_help in yes_answers:
  495. helpall()
  496. elif more_help in no_answers:
  497. print("Okay, got it.")
  498. else:
  499. print("Sorry, I didn't get that.")
  500. help_still()
  501. dividers()
  502.  
  503. def help_start():
  504. if input == help_input:
  505. helpall()
  506.  
  507. #ONE COMMAND TO RULE THEM ALLLLLLLL
  508. welcome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement