Akeuroo Card Deck
A library used for creating a card deck, which provides useful classes and methods for a user who wants to create card games.
Use the package manager pip to install this package:
pip install akeuroo-deck
Start by importing
from akeuroo_deck import Deck, Hand
Deck like the following:
deck = Deck()
There are two classes you can use,
Hand, the following information will be about them:
Deck has two methods, which are
The instance of
Deck and the
shuffle() should not be included inside any loops (unless you need it to). If you were to draw a card from the Deck, the card may not be removed as the order would be repeatedly changing and the deck would be restarting.
draw will return a Card object, you can access a cards rank, value, and the suit like the following:
deck = Deck() card = deck.draw() card_info = (card.suit.value, card.rank.name, card.rank.value)
shuffle will shuffle the deck:
deck = Deck() deck.shuffle()
Hand is callable, and has 3 attributes,
Hand will do the most job for you when it comes to storing the hand of
n amount of player, and you will be able to access the cards easily.
To let the
Hand class have access to the cards, I would recommend to draw every card into the
Hand object instead.
Hand keep in mind that it only takes a
Card object and not a list of cards!
This would look something like:
deck = Deck() deck.shuffle() player_hand = Hand() player_hand(deck.draw()) # Since Hand is callable we can just draw the card directly into it
cards will return a list of all the Card objects in the hand of this class:
player_hand = Hand() player_hand.cards
value will return a sum of integers of all the values for each card in the hand:
player_hand = Hand() player_hand.value
all will return a list of suit, rank name and rank value:
player_hand = Hand() player_hand.all
A Code Example:
from akeuroo_deck import Deck, Hand deck = Deck() # Instantiate the Deck outside of a loop deck.shuffle() # Shuffle the Deck directly after it class Player: def __init__(self): self.hand = Hand() # Creating the hand of the player which inherits from the Hand class def draw(self): self.hand(deck.draw()) # Letting the player draw a card and the Card object will be directly sent into the hand class Game: def __init__(self): x = input("Do you wanna draw a card? (yes/no): ") if x == "yes": player.draw() # If the player wants to draw a card, we call the player.draw() method else: # If the player doesn't want to draw a card, we simply print out the information the hand of the player currently has print(player.hand.cards) print(player.hand.value) print(player.hand.all) player = Player() while True: Game()
Licence & Copyright
Copyright (c) 2021 akeuroo