-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCards.py
More file actions
99 lines (81 loc) · 2.59 KB
/
Cards.py
File metadata and controls
99 lines (81 loc) · 2.59 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
from enum import Enum
import random
class CardType(Enum):
"""
Enum to display the types of cards possible
"""
# TODO herausfinden wie das genau funktioniert wozu die zuweisung eines Wertes
Kreuz = 0 # drei kugeln dinger
Pik = 1 # schwarzes Herz
Karo = 2 # Raute
Herz = 3 # Herz
class BaseCard():
"""
A Class representing a Card
"""
def __init__(self, type, number):
"""
Init a card
:param type: CardType, which type of card ist it (Pik Karo Kreuz Herz)
:param number: Int, which Value the Card has (1 is Ace, 11, 12 and 13 are Bube, Dame, König)
"""
# Kreuz Pik Karo oder Herz
self.type = type
# 1(Ace),2,3,4,5,6,7,8,9,10,11(Bube), 12(Dame), 13(König)
self.number = number
def printCardStats(self):
"""
prints the Type and Value of the Card
:return:
"""
number = self.number
type = ""
# Get Value
if self.number == 1:
number = "Ass"
elif self.number == 11:
number = "Bube" # jack
elif self.number == 12:
number = "Dame"
elif self.number == 13:
number = "König"
# Get Type
if self.type == CardType.Kreuz:
type = "Kreuz"
elif self.type == CardType.Pik:
type = "Pik"
elif self.type == CardType.Karo:
type = "Karo"
elif self.type == CardType.Herz:
type = "Herz"
return f"[{type}|{number}]"
class DeckManager():
def __init__(self):
self.deck = self.__createDeck()
#cardTypesArray = [CardType.Kreuz, CardType.Pik, CardType.Karo, CardType.Herz]
#for type in cardTypesArray:
# for number in range(13):
# self.deck.append(BaseCard(type, number))
def drawCard(self):
"""
Draws a random card from the deck, removes it, and returns it
:return:
"""
card = random.choice(self.deck)
self.deck.remove(card)
print(f"new Decksize {len(self.deck)}")
return card
def __createDeck(self):
deck = []
cardTypesArray = [CardType.Kreuz, CardType.Pik, CardType.Karo, CardType.Herz]
for type in cardTypesArray:
for number in range(13):
deck.append(BaseCard(type, number))
return deck
def printDeckSize(self):
return str(len(self.deck))
def printDeck(self):
returnString = f""
for card in self.deck:
returnString += card.printCardStats() + "\n"
return returnString