Skip to content

Commit fce96a9

Browse files
authored
casino games (#78)
Terminal based Casino games using python
1 parent 22f9e3b commit fce96a9

File tree

5 files changed

+350
-0
lines changed

5 files changed

+350
-0
lines changed

terminalcasino-main/Blackjack.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Simple program simulates Blackjack game.
2+
# Using method: Top-Down design, spiral development
3+
4+
from random import randrange
5+
6+
def main():
7+
printIntro()
8+
player_hand = player()
9+
dealer_hand = dealer()
10+
player_win, dealer_win = compare_between(player_hand, dealer_hand)
11+
printResult(player_hand, dealer_hand, player_win, dealer_win)
12+
13+
14+
def printIntro():
15+
print("Blackjack (twenty-one) is a casino game played with cards.")
16+
print("the goal of game is to draw cards that total as close to 21 points, as possible")
17+
print("without going over( whose hand > 21 will bust). All face cards count as 10 points,")
18+
print("aces count as 1 or 11, and all other cards count their numeric value.")
19+
print("\nFirstly, your turn:")
20+
21+
22+
def player():
23+
hand = []
24+
ans = "hit"
25+
hand.append(card())
26+
# Ask user whether Hit or Stand?
27+
# Condition True, if user want to Hit.
28+
while ans[0] == "h" or ans[0] == "H":
29+
hand.append(card())
30+
hand = eval_ace(hand)
31+
print("Your hand: {0} total = {1}".format(hand, sum(hand)))
32+
if bust(hand):
33+
break
34+
if blackjack(hand):
35+
break
36+
ans = input("Do you want to Hit or Stand (H or S)? ")
37+
return hand
38+
39+
40+
def card():
41+
# get arbitrary card from 2 to 11.
42+
shuffle_card = randrange(2, 11 + 1)
43+
return shuffle_card
44+
45+
46+
def eval_ace(hand):
47+
# Determine Ace = 1 or 11, relying on total hand.
48+
total = sum(hand)
49+
for ace in hand:
50+
if ace == 11 and total > 21:
51+
# at position, where Ace == 11, replace by Ace == 1.
52+
position_ace = hand.index(11)
53+
hand[position_ace] = 1
54+
return hand
55+
56+
57+
def bust(hand):
58+
# Condition True: if the hand of player (or dealer) > 21.
59+
total = sum(hand)
60+
if total > 21:
61+
return True
62+
63+
64+
def blackjack(hand):
65+
# Condition True: if the hand of player (or dealer) == 21.
66+
total = sum(hand)
67+
if total == 21:
68+
return True
69+
70+
71+
def dealer():
72+
hand = []
73+
hand.append(card())
74+
while sum(hand) < 18:
75+
hand.append(card())
76+
hand = eval_ace(hand)
77+
return hand
78+
79+
80+
def compare_between(player, dealer):
81+
total_player = sum(player)
82+
total_dealer = sum(dealer)
83+
player_bust = bust(player)
84+
dealer_bust = bust(dealer)
85+
player_blackjack = blackjack(player)
86+
dearler_blackjack = blackjack(dealer)
87+
player_win = 0
88+
dealer_win = 0
89+
# when player (dealer) bust.
90+
if player_bust:
91+
if not dearler_blackjack and total_dealer < 21:
92+
dealer_win += 1
93+
if dealer_bust:
94+
if not player_blackjack and total_player < 21:
95+
player_win += 1
96+
if player_bust and dealer_bust:
97+
if total_player > total_dealer:
98+
player_win += 1
99+
elif total_dealer > total_player:
100+
dealer_win += 1
101+
else:
102+
player_win == dealer_win
103+
# when player (dealer) get blackjack.
104+
if player_blackjack:
105+
player_win += 1
106+
if dearler_blackjack:
107+
dealer_win += 1
108+
if player_blackjack and dearler_blackjack:
109+
player_win == dealer_win
110+
# when total hand of player (dealer) < 21.
111+
if total_player < 21 and total_dealer < 21:
112+
if total_player > total_dealer:
113+
player_win += 1
114+
elif total_dealer > total_player:
115+
dealer_win += 1
116+
else:
117+
player_win == dealer_win
118+
return player_win, dealer_win
119+
120+
121+
def printResult(player_hand, dealer_hand, player_win, dealer_win):
122+
print("\nWe have the result: ")
123+
print("Player has: {0} total = {1}".format(player_hand, sum(player_hand)))
124+
print("Dealer has: {0} total = {1}".format(dealer_hand, sum(dealer_hand)))
125+
print("player: {} | dealer: {}".format(player_win, dealer_win))
126+
127+
128+
if __name__ == "__main__": main()

terminalcasino-main/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Presenting with you the most awaited Project.. "The Terminal Casino"
2+
![Photo_1625234446649](https://user-images.githubusercontent.com/76024137/124350364-f94c1600-dc11-11eb-8735-bcd74dee79c8.jpg)
3+
# Enjoy Multiple games at one stop station.. at your own compiler with 0 pre requisites!!
4+
![IMG_20210703_122743](https://user-images.githubusercontent.com/76024137/124346612-7caf3c80-dbfd-11eb-8723-435d5c9a2d09.jpg)
5+

terminalcasino-main/Roulette.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import random
2+
from time import sleep
3+
import Terminal_Casinogame
4+
import math
5+
6+
7+
8+
game_on = True
9+
10+
while game_on :
11+
print("\nYou start the game with!", total_money, '$ \n')
12+
bet_value = -1
13+
14+
# choose the square on which we put
15+
while bet_value < 0 or bet_value > 50:
16+
try:
17+
print("Choose the bet number[0,50]")
18+
bet_value = int(input("What is your choice? ..."))
19+
except ValueError:
20+
print("you haven't introduced anything.")
21+
bet_value = -1
22+
if bet_value < 0:
23+
print("you must choose a number greater than 0.")
24+
elif bet_value > 50:
25+
print("you must choose a number less than 50.")
26+
27+
print("You chose", bet_value)
28+
29+
# choose the amount to bet on the number
30+
money_to_bet = 0
31+
while money_to_bet <= 0 or money_to_bet > total_money:
32+
money_to_bet = input("\nWhat is your stake?")
33+
try:
34+
money_to_bet = int(money_to_bet)
35+
except ValueError:
36+
print("you did not choose your stake.")
37+
if money_to_bet <= 0:
38+
print("The bet is negative or zero.")
39+
if money_to_bet > total_money:
40+
print("You don't have enough money. You have", total_money)
41+
42+
# start roulette
43+
print("\nThe croupier launches the roulette wheel ...")
44+
number_landed = random.randrange(0, 50)
45+
sleep(2)
46+
print("the roulette wheel stops on", number_landed)
47+
48+
# processing
49+
if number_landed == bet_value:
50+
print("\nYou bet on the right number, you win", money_to_bet *3, '$')
51+
total_money += money_to_bet * 3
52+
elif number_landed % 2 == bet_value % 2:
53+
print("\nYou bet on the right color, you win", math.ceil(money_to_bet * 0.5), '$')
54+
total_money += math.ceil(money_to_bet * 0.5)
55+
else:
56+
print("\nSorry you lost", money_to_bet, '$')
57+
total_money -= money_to_bet
58+
59+
# Game over
60+
if total_money <= 0:
61+
print("\nYou're ruined, it's the end of the party")
62+
game_on = False
63+
else:
64+
print("\nyou have now", total_money, '$')
65+
quitter = input("\nDo you want to quit the game(y/n)?")
66+
if quitter == 'y' or quitter == 'Y':
67+
print("\nYou leave the casino with", total_money, '$')
68+
game_on = False
69+
print("\nThank you for playing ROULETTE")
70+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import Terminal_Casinogame
2+
import random
3+
# START MENU
4+
5+
print(" ")
6+
print(" ~~GET THE FEEL OF CASINO AT YOUR TERMINAL.. TRY HACKING IT!!~~")
7+
print(" THE GAMBLING BOT ")
8+
print(" ")
9+
print(" Red DIAMOND Black ")
10+
print(" | | ")
11+
print(" 2 3 | | 8 9 ")
12+
print(" | | ")
13+
print(" 4 | 7 | 10 ")
14+
print(" | | ")
15+
print(" 5 6 | | 11 12")
16+
print("-- HEY GUYS -- !! \n WE ARE PRESENTING THE MOST SURPRISING AND INNOVATIVE \n"
17+
" GAMBLING GAME OF ALL TIMES FOR YOU"
18+
"\n RULES OF THE GAME "
19+
"\n 1] There are 3 Categories namely.. 'Red', 'DIAMOND', and 'Black' .. As shown above "
20+
"\n 2] Two dice are rolling simultaneously .. "
21+
"\n 3] Dice rolling will stop once you choose a Category to bid in"
22+
"\n 4] Sum of the numbers shown by the dice will be the 'Lucky Number"
23+
"\n 5] Choose any one Category that you predict can contain the 'Lucky Number' "
24+
"\n 6] Enter the amount of money you like to bid in a Category"
25+
"\n 7] If you predicted the right Category containing the Lucky Number .. 'Your money will be DOUBLED' .. "
26+
"\n or else you will loose your money.. Special Case for 7 as here your money gets TRIPLED"
27+
"\n GET STARTED !! HOPE YOU LIKE IT!!"
28+
"\n -----------------------------------"
29+
)
30+
# THE MAIN CODE OF GAME
31+
game_on=True
32+
33+
34+
while game_on:
35+
money_to_bet=0
36+
while money_to_bet <= 0 or money_to_bet > total_money:
37+
money_to_bet = input("\nWhat is your stake?")
38+
try:
39+
money_to_bet = int(money_to_bet)
40+
except ValueError:
41+
print("you did not choose your stake.")
42+
if money_to_bet <= 0:
43+
print("The bet is negative or zero.")
44+
if money_to_bet > total_money:
45+
print("You don't have enough money. You have", total_money)
46+
47+
total_money-=money_to_bet
48+
print("Choose any one Category from the below three as 'r-for red' or 'd- for diamond' or 'b- for black' ")
49+
print(" r) RED \n d) DIAMOND \n b) BLACK")
50+
r="Category RED"
51+
d="Category DIAMOND"
52+
b="Category BLACK"
53+
print(" ")
54+
print(" RED DIAMOND BLACK ")
55+
print(" | | ")
56+
print(" 2 3 | | 8 9 ")
57+
print(" | | ")
58+
print(" 4 | 7 | 10 ")
59+
print(" | | ")
60+
print(" 5 6 | | 11 12")
61+
options=input("Enter the option number you want to take :")
62+
number=random.choice([2,3,4,5,6,7,8,9,10,11,12])
63+
print("The lucky number is",number)
64+
if options== "r" or options=="R":
65+
if number <= 6:
66+
67+
print("YAY!! Your Money is Doubled!!:" ,money_to_bet*2)
68+
total_money =total_money + money_to_bet*2
69+
else:
70+
print("OOPS! Your Money is Lost :" ,money_to_bet*0)
71+
72+
if(options=="d" or options=="D"):
73+
if(number==7):
74+
print("YAY!! Your Money is Tripled:" ,money_to_bet*3)
75+
total_money =total_money + money_to_bet*3
76+
else:
77+
print("OOPS! Your Money is Lost:" ,money_to_bet*0)
78+
79+
if(options=="b" or options=="B"):
80+
if(7<number<=12):
81+
print("YAY!! Your money is Doubled:" ,money_to_bet*2)
82+
total_money =total_money + money_to_bet*2
83+
else:
84+
print("OOPS! Your money is Lost:" ,money_to_bet*0)
85+
86+
print("\n ~~Your wallet contains", total_money, "$")
87+
quitter = input("\nDo you want to quit the game(y/n)?")
88+
if quitter == 'n' or quitter == 'N':
89+
game_on = True
90+
elif quitter == 'y' or quitter == 'Y':
91+
game_on=False
92+
print("\nThank you for playing 7UP 7 DOWN")
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
total_money = 10000
2+
if __name__=='__main__':
3+
4+
print(" █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█\n"
5+
" █░░╦─╦ ╔╗ ╦ ╔╗ ╔╗ ╔╦╗ ╔╗░░█\n"
6+
" █░░║║║ ╠─ ║ ║ ║║ ║║║ ╠─░░█\n"
7+
" █░░╚╩╝ ╚╝ ╚╝ ╚╝ ╚╝ ╩─╩ ╚╝░░█\n"
8+
" █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█\n")
9+
print('~~WELCOME TO THE CASINO TERMINAL.... '
10+
'\n ..THE ALL NEW GAMING PLATFORM! ')
11+
name = str(input('\n ~~Please enter your name: '))
12+
age = int(input('\n What is your age : '))
13+
14+
15+
print("\n ")
16+
17+
18+
game=True
19+
20+
while game:
21+
if age>18:
22+
print("\n ~~HELLO", name, ",your wallet contains", total_money, "$")
23+
choice = -1
24+
print('\n Enter 1 for Playing the 7UP-7DOWN Game \n')
25+
print('Enter 2 for Playing Blackjack Game\n')
26+
print('Enter 3 for Playing Roulette Wheel Game\n')
27+
while choice>3 or choice<1:
28+
choice = int(input('Enter your choice:'))
29+
if (choice == 1):
30+
exec(open('SevenUP_SevenDOWN.py').read())
31+
if (choice == 2):
32+
exec(open('Blackjack.py').read())
33+
if (choice == 3):
34+
exec(open('Roulette.py').read())
35+
36+
quitter = input("\nDo you want to play another game(y/n)?")
37+
if quitter == 'y' or quitter == 'Y':
38+
game = True
39+
elif quitter == 'n' or quitter == 'N':
40+
game= False
41+
print("\n ~~HELLO", name, ",your wallet contains", total_money, "$")
42+
print("\nThank you for playing with TERMINAL CASINO and hope to see you again", name)
43+
44+
else:
45+
print('You can only play Blackjack as you are underage !')
46+
exec(open('Blackjack.py').read())
47+
quitter = input("\nDo you want to play another game(y/n)?")
48+
if quitter == 'y' or quitter == 'Y':
49+
game = True
50+
51+
elif quitter == 'n' or quitter == 'N':
52+
game = False
53+
54+
print("\nThank you for playing with TERMINAL CASINO and hope to see you again", name)
55+

0 commit comments

Comments
 (0)