A small module for creating a card deck, used for making card games

Overview

card-deck

This module can be used to create small card games such as BlackJack etc..

To initialize the deck, use:

Deck()

To shuffle the deck, use:

Deck().shuffle()

To restart/renew the deck, use:

Deck().restart()

To draw a card from the deck, use:

Deck().draw()

This returns a list[tuple[str, int]], it could look something like [("Hearts", 5)].

Classes Methods/Properties Paremeters/Arguments
Deck Method: shuffle, draw, restart optional: draw(amount=1), restart(shuffle=True)
Card Properties: name, value, suit required: Card(tuple[str, int])

Try to except EmptyDeckError and CardAmountError when drawing a card since the deck can end up being empty at some point or you maybe try to draw more cards than what the deck has.

Examples

from card_deck import Deck, Card, EmptyDeck

# Instantiating and initializing the deck
deck = Deck()

# Shuffling the deck so it becomes in random orders when drawing a card
deck.shuffle()

# Creating the hand of a player
player_hand = []

while True:
    # Asking if the user wants to draw a card
    inp = input("Do you wanna draw a card? (yes/no): ")
    
    if inp == "yes":
        try:
            player_hand.append(deck.draw())
        except EmptyDeckError: # If the Deck is empty, deck.draw() will raise a EmptyDeckError
            break
    else:
        break

# Lets say we draw a card two times, player_hand would look like: [[("Hearts", 5)], [("Spades", 10)]]
# So what we can do to pretty print it is to iterate through player_hand
for cards in player_hand:
    card = Card(cards[0]) # Since Cards only takes a tuple of str and int, we need to do cards[0]
    print(card.suit, card.name, card.value)
You might also like...
A comprehensive, feature-rich, open source, and portable, collection of Solitaire games.
A comprehensive, feature-rich, open source, and portable, collection of Solitaire games.

PySol Fan Club edition This is an open source and portable (Windows, Linux and Mac OS X) collection of Card Solitaire/Patience games written in Python

To solve games using AI, we will introduce the concept of a game tree followed by minimax algorithm.
To solve games using AI, we will introduce the concept of a game tree followed by minimax algorithm.

To solve games using AI, we will introduce the concept of a game tree followed by minimax algorithm.

Automates cubemap generation for Source Engine games.

AutoCube Automates cubemap generation for Source Engine games during compile-time. Download: see the release page Installation Using with CompilePal A

Gamelib is a pure-Python single-file library/framework for writing simple games.

Gamelib is a pure-Python single-file library/framework for writing simple games. It is intended for educational purposes (e.g. to be used in b

Open source Board Games Like Tic Tac Toe, Connect 4, Ludo, Snakes and Ladder etc...

Board-Games What to do... Add Board games like Tic Tac Toe, Connect 4, Ludo, Snakes and Ladder etc... How to do... Fork the repo Clone the repo git cl

Overview: copain, your friendly AI framework to learn and play games

Overview: copain, your friendly AI framework to learn and play games Interface fceux with python and run reinforcement learning. Compatibility Current

Lutris helps you install and play video games from all eras and from most gaming systems.

Lutris Lutris helps you install and play video games from all eras and from most gaming systems. By leveraging and combining existing emulators, engin

Minesweeper clone with 3 modes of difficulty, UI scaling and custom games feature.

Insect Sweeper Minesweeper clone with 3 modes of difficulty, UI scaling and custom games feature. Mines are replaced with random insects that a player

Editing tool (read/write) .sc files (*_tes.sc , *.sc, *_dl.sc ) from Supercell games (Brawl Stars, Clash Royale, Clash of Clans and others).

SupercellSWF Version 0.1.0.2 About Editing tool (read/write) .sc files (*_tes.sc , *.sc, *_dl.sc ) from Supercell games (Brawl Stars, Clash Royale, Cl

Owner
Hi, I'm 17 (soon 18) and I'm a Python develeoper, currently learning Rust and also working on small Python scripts. Wann be a software engineer in the future :)
null
pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

pygame 5.6k Jan 1, 2023
TwoDMaker (2DMaker) - Simple engine for 2D games making!

TwoDMaker (2DMaker) - Simple engine for 2D games making! Create simple games (or ui) in one hour! About. This is a simple engine for game or gui app c

Ivan Perzhinsky. 1 Jan 3, 2022
A launcher to launch games from Riot Games under Linux

rito-launcher A launcher to launch games from Riot Games under Linux Requirements: Python 3, with the following pip plugins: 'configparser, pathlib, w

null 6 Mar 7, 2022
Datamining of 15 Days of (free) Games at the Epic Games Store (EGS).

EGS: 15 Days of Games This repository contains Python code to data-mine the 15 Days of (free) Games at the Epic Games Store (EGS). Requirements Instal

Wok 9 Dec 27, 2022
Description NerdQuest is a social site for creating events and/or meet ups based on games.

NerdQuest Description NerdQuest is a social site for creating events and/or meet

David Allen 1 Jul 11, 2022
source codes for my(small indie game developer) games

My repository for most of my finished && unfinished games Table of Contents Getting Started Prerequisites Installation Usage License Contact Prerequis

Gustavs Jākobsons 1 Jan 30, 2022
A converter for the .BMR / .RLE bitmap files used in some Neversoft PS1 games.

Requirements python3 pyqt5 - can be installed with pip install PyQt5 pypng - Included Usage Instructions This program can be running py main.py in the

null 4 Jul 30, 2022
Guess Your Card - A Multiplayer Python Game

Guess Your Card - A Multiplayer Python Game This is a guessing card game having two levels - Developed in Python and can be played between two to four

Hammad Ahmed ~ 1 Oct 20, 2021
This is the card game like HearthStone and Magic

Territory War How to use it use pip3 to install django and channels: pip3 install Django pip3 install channels go to CardGame/first/consumers.py and g

Caesar 3 Oct 24, 2022
Generates and prints proxies for the card game Magic: the Gathering

MTG-Proxy-Generator This program generates proxies for the card game Magic: the Gathering. These proxies can then be printed off and used. These copie

Carl L. 1 Jan 31, 2022