-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcard.py
53 lines (42 loc) · 1.51 KB
/
card.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
import random
class Card:
def __init__(self, rank, suit):
self.rank = rank
self.suit = suit
class DeckCards:
def __init__(self):
self.deckOfCards = []
self.suits = ['clubs', 'diamonds', 'hearts', 'spades']
self.ranks = ['ace', 2, 3, 4, 5, 6, 7,
8, 9, 10, 'jack', 'queen', 'king']
def createCards(self):
for suit in self.suits:
for rank in self.ranks:
self.deckOfCards.append(Card(rank, suit))
def printCard(self, rank, suit, postion):
print("The {0} card is the {1} of {2}!".format(postion, rank, suit))
def peekCard(self):
# Example: "The top card is the Ace of Spades!"
peek = len(self.deckOfCards) - 1
self.printCard(self.deckOfCards[peek].rank,
self.deckOfCards[peek].suit, "Top")
def bottomCard(self):
self.printCard(self.deckOfCards[0].rank,
self.deckOfCards[0].suit, "Bottom")
def shuffleCards(self):
# rondom __init__
# array 2,5,6,7,
shuffledcars = []
for i in range(52):
length = len(self.deckOfCards)
randomNumber = random.randint(0, length-1)
shuffledcars.append(self.deckOfCards[randomNumber])
value = self.deckOfCards[randomNumber]
self.deckOfCards.remove(value)
self.deckOfCards = shuffledcars
cards = DeckCards()
cards.createCards()
cards.peekCard()
cards.bottomCard()
cards.shuffleCards()
cards.peekCard()