-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
173 lines (158 loc) · 5.64 KB
/
main.py
File metadata and controls
173 lines (158 loc) · 5.64 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from random import choice
class Game_Handler:
"""
Tool to assist in building card games\n
Dealer Class:
---
`Holds the deck of cards and deals with card disribution.`
Player Class:
---
`Object that stores the player variables.`
"""
class Dealer:
"""
Holds the deck of cards and deals with card disribution.
Functions:
---
`random_card()` - `Selects a random card within the deck.`
`deal_cards(player, cards=2)` - `Deals an amount, cards, to a player.`
"""
def __init__(self):
self.Dealer = Game_Handler.Dealer
# We'll store the buy in money within the Dealer class.
self.prize_pool = 0
# This is the deck of cards. 1 means the card is in the deck, 0 means the card is somewhere else.
self.Deck = {
"Clubs": {
"Ace": 1,
"Two": 1,
"Three": 1,
"Four": 1,
"Five": 1,
"Six": 1,
"Seven": 1,
"Eight": 1,
"Nine": 1,
"Ten": 1,
"Jack": 1,
"Queen": 1,
"King": 1
},
"Diamonds": {
"Ace": 1,
"Two": 1,
"Three": 1,
"Four": 1,
"Five": 1,
"Six": 1,
"Seven": 1,
"Eight": 1,
"Nine": 1,
"Ten": 1,
"Jack": 1,
"Queen": 1,
"King": 1
},
"Spades": {
"Ace": 1,
"Two": 1,
"Three": 1,
"Four": 1,
"Five": 1,
"Six": 1,
"Seven": 1,
"Eight": 1,
"Nine": 1,
"Ten": 1,
"Jack": 1,
"Queen": 1,
"King": 1
},
"Hearts": {
"Ace": 1,
"Two": 1,
"Three": 1,
"Four": 1,
"Five": 1,
"Six": 1,
"Seven": 1,
"Eight": 1,
"Nine": 1,
"Ten": 1,
"Jack": 1,
"Queen": 1,
"King": 1
}
}
def random_card(self):
"""Selects a random card from the deck."""
# Creates a list containing the suites with cards left.
active_suites = []
for suite in self.Deck:
suite_total = 0
for card in self.Deck[suite]:
suite_total += self.Deck[suite][card]
if suite_total > 0:
active_suites.append(suite)
# Picks a suite from the list created above.
self.suite = choice(active_suites)
# Creates a list of active cards from the suite chosen from above.
active_cards_in_list = []
for card in self.Deck[self.suite]:
if self.Deck[self.suite][card] == 1:
active_cards_in_list.append(card)
# Picks a card from the list created above.
self.card = choice(active_cards_in_list)
# Removes card from Deck
self.Deck[self.suite][self.card] = 0
# Returns the card that has been chosen.
return self.suite, self.card
def deal_cards(self, player, cards=2):
"""Deals cards."""
for _ in range(cards):
suite, card = self.random_card()
player.hand[suite].update({card: 1})
class Player:
"""
Object that stores the player variables.
Functions:
---
`play_card(player, card: tuple)` - `Transfers a card to another player object.`\n
`get_cards()` - `Returns a neater dictionary only containing the cards in the player hand.`
"""
def __init__(self, player_name):
self.name = player_name
self.hand = {
"Clubs": {},
"Diamonds": {},
"Spades": {},
"Hearts": {}
}
def play_card(self, player, card: tuple):
"""
Transfers a card to another player object.\n
Recieves the card in the tuple format: (Suite, Card). `Ex:("Hearts", "Ace")`.
"""
suite, card = card[0], card[1]
if self.hand[suite][card] == 1:
self.hand[suite].update({card: 0})
player.hand[suite].update({card: 1})
else:
print(f"Card does not exist within {self.name}'s hand.")
def get_cards(self):
"""Returns a neater dictionary only containing the cards in the player hand."""
cards = dict()
# Updates the active suites in the cards dictionary.
for suite in self.hand:
suite_total = 0
for card in self.hand[suite]:
suite_total += self.hand[suite][card]
if suite_total > 0:
cards.update({suite: {}})
# Updates the active cards to the proper suite in the cards dictionary.
for suite in self.hand:
for card in self.hand[suite]:
if self.hand[suite][card] == 1:
cards[suite].update({card: 1})
# Return the updated cards dictionary.
return cards