added Card class
This commit is contained in:
24
src/pyjack/card.py
Normal file
24
src/pyjack/card.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
class Card:
|
||||||
|
"""Class to represent an single card of a full deck"""
|
||||||
|
|
||||||
|
# TODO: - write tests
|
||||||
|
|
||||||
|
def __init__(self, suit: str, rank: str) -> None:
|
||||||
|
"""Initializes the card and calculating its value"""
|
||||||
|
self.suit = suit
|
||||||
|
self.rank = rank
|
||||||
|
|
||||||
|
# determine the initial card value
|
||||||
|
if rank == "J" or rank == "Q" or rank == "K":
|
||||||
|
self.value = 10
|
||||||
|
elif rank == "A":
|
||||||
|
self.value = 11
|
||||||
|
else:
|
||||||
|
self.value = int(rank)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.rank + " of " + self.suit
|
||||||
|
|
||||||
|
def get_value(self) -> int:
|
||||||
|
"""Returns the value of the card"""
|
||||||
|
return self.value
|
||||||
Reference in New Issue
Block a user