forked from SwaminathanSK/Python_Blackjack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonProjects.py
109 lines (104 loc) · 2.73 KB
/
PythonProjects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""!--BLACKJACK--!"""
import random
import os
#top = tkinter.Tk()
class Card:
def __init__(self,value,suit):
self.value = value
self.suit = '♥♦♣♠'[suit-1] # 1,2,3,4 = ♥♦♣♠
def print(self, bool):
if bool == 0:
print('┌───────┐')
print(f'| {self.value:<2} |')
print('| |')
print(f'| {self.suit} |')
print('| |')
print(f'| {self.value:>2} |')
print('└───────┘')
cards = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, "A"]
suits = ["Hearts", "Diamonds", "Clubs", "Spades"]
special = ["J", "Q", "K"]
taken = []
i = 1
sum1 = 0
sum2 = 0
hit = 0
status = 0
nohit = 0
p1cards = []
p2cards = []
while(i!=0):
i+=1
if i % 2 == 0:
print("Player1, Your score is ", str(sum1))
print("Your Cards:")
for a in p1cards:
a.print(0)
else:
print("Player2, Your score is ", str(sum2))
print("Your Cards:")
for a in p2cards:
a.print(0)
print("Do you want to hit?[Yes/No]", end = " ")
hit = input()
if hit == "Yes":
allow = True
while(allow):
x = random.choice(cards)
y = random.choice(suits)
if x == 10:
z = random.choice(special)
else:
z = x
s = str(z) + " of " + y
if s not in taken:
allow = False
taken.append(s)
card = Card(z, suits.index(y) + 1)
if i % 2 == 0:
p1cards.append(card)
else:
p2cards.append(card)
print("You got ", s)
card.print(0)
if x != 'A':
if i%2 == 0:
sum1 += x
else:
sum2 += x
else:
print("What do you want to set as the value of A?", end = " ")
player_choice = int(input())
if i%2 == 0:
sum1 += player_choice
else:
sum2 += player_choice
if sum1 > 21:
print("Busted")
status = 2
i = 0
if sum2 > 21:
print("Busted")
status = 1
i = 0
if sum2 == 21:
print("Blackjack!")
status = 2
i = 0
if sum1 == 21 and sum2 == 21:
status = 3
i = 0
else:
nohit += 1
if nohit == 3:
i = 0
if sum2 > sum1:
status = 2
elif sum1 > sum2:
status = 1
else:
status = 3
print("\n")
print("Type C to continue...")
if(input() == 'C'):
os.system('cls')