11
11
#
12
12
######################################################
13
13
14
+
14
15
class Card :
15
16
def __init__ (self , suit , rank ):
16
17
self .suit = suit
@@ -19,14 +20,14 @@ def __init__(self, suit, rank):
19
20
def __str__ (self ):
20
21
r = self .rank
21
22
if r == 11 :
22
- r = 'J'
23
+ r = "J"
23
24
elif r == 12 :
24
- r = 'Q'
25
+ r = "Q"
25
26
elif r == 13 :
26
- r = 'K'
27
+ r = "K"
27
28
elif r == 14 :
28
- r = 'A'
29
- return f' { r } { self .suit } '
29
+ r = "A"
30
+ return f" { r } { self .suit } "
30
31
31
32
32
33
class Deck :
@@ -35,12 +36,13 @@ def __init__(self):
35
36
self .build ()
36
37
37
38
def build (self ):
38
- for suit in [' \u2665 ' , ' \u2666 ' , ' \u2663 ' , ' \u2660 ' ]:
39
+ for suit in [" \u2665 " , " \u2666 " , " \u2663 " , " \u2660 " ]:
39
40
for rank in range (2 , 15 ):
40
41
self .cards .append (Card (suit , rank ))
41
42
42
43
def shuffle (self ):
43
44
import random
45
+
44
46
random .shuffle (self .cards )
45
47
46
48
def deal (self ):
@@ -69,34 +71,34 @@ def play(self):
69
71
self .card_b = self .deck .deal ()
70
72
card_b = self .card_b
71
73
72
- print (f' You have:\t ${ self .money } ' )
73
- print (f' Your cards:\t { card_a } { card_b } ' )
74
+ print (f" You have:\t ${ self .money } " )
75
+ print (f" Your cards:\t { card_a } { card_b } " )
74
76
75
- bet = int (input (' What is your bet? ' ))
77
+ bet = int (input (" What is your bet? " ))
76
78
player_card = self .deck .deal ()
77
79
if 0 < bet <= self .money :
78
80
79
- print (f' Your deal:\t { player_card } ' )
81
+ print (f" Your deal:\t { player_card } " )
80
82
if card_a .rank < player_card .rank < card_b .rank :
81
- print (' You Win!' )
83
+ print (" You Win!" )
82
84
self .money += bet
83
85
else :
84
- print (' You Lose!' )
86
+ print (" You Lose!" )
85
87
self .money -= bet
86
88
self .not_done = False
87
89
else :
88
- print (' Chicken!' )
89
- print (f' Your deal should have been: { player_card } ' )
90
+ print (" Chicken!" )
91
+ print (f" Your deal should have been: { player_card } " )
90
92
if card_a .rank < player_card .rank < card_b .rank :
91
- print (f' You could have won!' )
93
+ print (f" You could have won!" )
92
94
else :
93
- print (f' You would lose, so it was wise of you to chicken out!' )
95
+ print (f" You would lose, so it was wise of you to chicken out!" )
94
96
95
97
self .not_done = False
96
98
break
97
99
98
100
if len (self .deck .cards ) <= 3 :
99
- print (' You ran out of cards. Game over.' )
101
+ print (" You ran out of cards. Game over." )
100
102
self .not_done = False
101
103
break
102
104
@@ -107,22 +109,24 @@ def play(self):
107
109
self .not_done = False
108
110
109
111
110
- if __name__ == '__main__' :
111
- print ('''
112
+ if __name__ == "__main__" :
113
+ print (
114
+ """
112
115
Acey Ducey is a card game where you play against the computer.
113
116
The Dealer(computer) will deal two cards facing up.
114
- You have an option to bet or not bet depending on whether or not you
117
+ You have an option to bet or not bet depending on whether or not you
115
118
feel the card will have a value between the first two.
116
119
If you do not want to bet input a 0
117
- ''' )
120
+ """
121
+ )
118
122
GAME_OVER = False
119
123
120
124
while not GAME_OVER :
121
125
game = Game ()
122
126
game .play ()
123
- print (f' You have ${ game .money } left' )
124
- print (' Would you like to play again? (y/n)' )
125
- if input () == 'n' :
127
+ print (f" You have ${ game .money } left" )
128
+ print (" Would you like to play again? (y/n)" )
129
+ if input () == "n" :
126
130
GAME_OVER = True
127
131
128
- print (' \n Thanks for playing!' )
132
+ print (" \n Thanks for playing!" )
0 commit comments