Skip to content

Commit 08b9a81

Browse files
Merge pull request prathimacode-hub#296 from archismansaha/arch
Black Jack Game added
2 parents f18566e + e6535e3 commit 08b9a81

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed
28.8 KB
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Package/Script Name
2+
### **blackjack_game**
3+
## Short description of package/script
4+
5+
<p>This is simple version of the black jack game you have given a list of two when your cards total is greater than 21 it will call black jack and you will loose,if your card's total is less than 17 you have to pick a card mandatory.At the end you will stop picking your card the game will end it will show what the are cards does the computer have.After that who has the greater number in total cards they will win</p> </br>
6+
7+
<p> This project is made to use the concept of list and functions properly></p>
8+
9+
# Setup
10+
Copy the project to your local enviroment and that's all this code can be run on any python IDE.
11+
## Detailed explanation of script, if needed
12+
13+
#### _**OUR GAME RULES**_
14+
><ul>
15+
><li> The deck is unlimited in size. </li>
16+
><li> The Jack/Queen/King all count as 10.</li>
17+
><li> The the Ace can count as 11 or 1.</li>
18+
><li> cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]</li>
19+
><li> The cards in the list have equal probability of being drawn.</li>
20+
><li> Cards are not removed from the deck as they are drawn.</li>
21+
><li> The computer is the dealer.</li>
22+
</ul>
23+
24+
25+
26+
## Output
27+
28+
![black-jack screenshot](https://github.com/prathimacode-hub/Awesome_Python_Scripts/blob/454a24fe369dacdaf32353230621b134f616bd98/PyGamesScripts/Black%20Jack%20Game/image/black_jack.PNG)
29+
30+
31+
## Author(s)
32+
##### _Archisman Saha_
33+

PyGamesScripts/Black Jack Game/art.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
logo = """
2+
.------. _ _ _ _ _
3+
|A_ _ |. | | | | | | (_) | |
4+
|( \/ ).-----. | |__ | | __ _ ___| | ___ __ _ ___| | __
5+
| \ /|K /\ | | '_ \| |/ _` |/ __| |/ / |/ _` |/ __| |/ /
6+
| \/ | / \ | | |_) | | (_| | (__| <| | (_| | (__| <
7+
`-----| \ / | |_.__/|_|\__,_|\___|_|\_\ |\__,_|\___|_|\_\\
8+
| \/ K| _/ |
9+
`------' |__/
10+
"""
11+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import random
2+
import art ## importing logo from that
3+
4+
5+
6+
7+
8+
9+
print (art.logo)
10+
11+
is_start=False
12+
print("Welcome to Blackjack Game")
13+
if input("Do you want to start the game?'y' for yes 'n'for no: " ) =='y':
14+
is_start=True
15+
16+
else:
17+
18+
is_start=False
19+
20+
while is_start:
21+
22+
def deal_card(): ## this function will choose random card
23+
cards=[11,2,3,4,5,6,7,8,9,10,10,10,10] ## list of cards
24+
return random.choice(cards)
25+
26+
def calculate_score(cards): ## it will calculate score
27+
if sum(cards)==21 and len(cards)==2:
28+
return 0
29+
if 11 in cards and sum(cards)>21:
30+
cards.remove(11)
31+
cards.append(1)
32+
return sum(cards)
33+
34+
def compare (user_score,computer_score): ## this is to comapre user and computer score
35+
if user_score==computer_score:
36+
return "Draw!"
37+
elif computer_score==0:
38+
return "Lose!opponent has Blackjack"
39+
elif user_score>21:
40+
return "You went over. You loose!"
41+
elif user_score>computer_score:
42+
return "You won!"
43+
else:
44+
return "You won!"
45+
46+
47+
48+
user_cards=[deal_card(),deal_card()] ## first initialization of user cards
49+
computer_cards=[deal_card(),deal_card()] # and computer cards which will contain two cards at first
50+
is_game_over=False # boolean it will decide when game will stop
51+
52+
while not is_game_over: # until when is_game_over will be false the game will continue
53+
54+
user_score=calculate_score(user_cards) #keeping user score
55+
computer_score=calculate_score(computer_cards) # and computer score in a variable
56+
print(f" Your cards: {user_cards}, current score: {user_score}")
57+
print(f"First card of computer: {computer_cards[0]}")
58+
if user_score==0 or user_score>21 or computer_score==0: # at this condition we will like to exit our game
59+
is_game_over=True
60+
else:
61+
print("You want to draw another card?")
62+
user_choice=input("Type 'y' to draw and 'n'to pass: ") ## asking user to continue or not
63+
if user_choice=='y':
64+
user_cards.append(deal_card()) ## adding new card to list
65+
else:
66+
is_game_over=True
67+
68+
while computer_score!=0 and computer_score<17: ## computer will continue according to condition
69+
computer_cards.append(deal_card())
70+
computer_score=calculate_score(computer_cards) ##calculating computer score
71+
72+
print(f" Your final hand: {user_cards}, final score: {user_score}")
73+
print(f" Your final hand: {computer_cards}, final score: {computer_score}")
74+
75+
print(compare(user_score,computer_score))
76+
if input("Do you want to play another game?'y' for yes 'n'for no: " ) =='y':
77+
is_start=True
78+
else:
79+
is_start=False
80+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libraries used : random

0 commit comments

Comments
 (0)