-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
86 lines (78 loc) · 4.17 KB
/
main.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
import datetime as dt
import random
import copy
card_deck = [['Ace of Spades ♠', 'King of Spades ♠', \
'Queen of Spades ♠', 'Jack of Spades ♠', \
'10 of Spades ♠', '9 of Spades ♠', \
'8 of Spades ♠', '7 of Spades ♠', \
'6 of Spades ♠', '5 of Spades ♠', \
'4 of Spades ♠', '3 of Spades ♠', \
'2 of Spades ♠'], \
['Ace of Diamonds <span style="color:red;">♦</span>', 'King of Diamonds <span style="color:red;">♦</span>', \
'Queen of Diamonds <span style="color:red;">♦</span>', 'Jack of Diamonds <span style="color:red;">♦</span>', \
'10 of Diamonds <span style="color:red;">♦</span>', '9 of Diamonds <span style="color:red;">♦</span>', \
'8 of Diamonds <span style="color:red;">♦</span>', '7 of Diamonds <span style="color:red;">♦</span>', \
'6 of Diamonds <span style="color:red;">♦</span>', '5 of Diamonds <span style="color:red;">♦</span>', \
'4 of Diamonds <span style="color:red;">♦</span>', '3 of Diamonds <span style="color:red;">♦</span>', \
'2 of Diamonds <span style="color:red;">♦</span>'],\
['Ace of Clubs ♣', 'King of Clubs ♣', \
'Queen of Clubs ♣', 'Jack of Clubs ♣', \
'10 of Clubs ♣', '9 of Clubs ♣', \
'8 of Clubs ♣', '7 of Clubs ♣', \
'6 of Clubs ♣', '5 of Clubs ♣', \
'4 of Clubs ♣', '3 of Clubs ♣', \
'2 of Clubs ♣'],\
['Ace of Hearts <span style="color:red;">♥</span>', 'King of Hearts <span style="color:red;">♥</span>', \
'Queen of Hearts <span style="color:red;">♥</span>', 'Jack of Hearts <span style="color:red;">♥</span>', \
'10 of Hearts <span style="color:red;">♥</span>', '9 of Hearts <span style="color:red;">♥</span>', \
'8 of Hearts <span style="color:red;">♥</span>', '7 of Hearts <span style="color:red;">♥</span>', \
'6 of Hearts <span style="color:red;">♥</span>', '5 of Hearts <span style="color:red;">♥</span>', \
'4 of Hearts<span style="color:red;">♥</span>', '3 of Hearts <span style="color:red;">♥</span>', \
'2 of Hearts <span style="color:red;">♥</span>']]
game_deck = copy.deepcopy(card_deck)
output_el = Element('cards').element
shuffle_el = Element('shuffled').element
remaining_el = Element('remaining').element
def remaining():
counter = 0
for suite in game_deck:
for card in suite:
counter += 1
if counter > 1:
remaining_el.innerHTML = '<b>There are ' + str(counter) + ' cards remaining.</b>'
else:
remaining_el.innerHTML = '<b>There are no more cards :(</b>'
def shuffle(*args):
global game_deck
game_deck = copy.deepcopy(card_deck)
output_el.innerHTML = ''
remaining_el.innerHTML = '<b>The Deck Has Been Shuffled</b>'
remaining()
def card_draw(*args):
while True:
if len(game_deck) == 0:
break
random_suit = random.randint(0, len(game_deck) - 1)
if len(game_deck[random_suit]) == 0:
del game_deck[random_suit]
continue
random_card = random.randint(0, len(game_deck[random_suit]) -1)
card_selection = game_deck[random_suit][random_card]
output_el.innerHTML += '<li>' + card_selection + '</li>'
del game_deck[random_suit][random_card]
break
def game(*args):
output_el.innerHTML = ''
remaining_el.innerHTML = ''
numCards = Element('num-cards').element.value
try:
int(numCards)
except:
remaining_el.innerHTML = '<b>Please enter an integer.</b>'
numCards = Element('num-cards').element.value = ''
for i in range(int(numCards)):
if game_deck.__len__() > 0:
card_draw()
numCards = Element('num-cards').element.value = ''
remaining()
remaining()