playingcards
index
/home/chris/src/python/playingcards/playingcards.py

A module to ease the creation of card games in written in python
 
The Card class is the representation of a single card, including it's
image and the back image.
 
The Stack class is the representation of a stack of playing cards.
 
To Use:
from playingcards import Card
from playingcards import Stack

 
Modules
       
os
random

 
Classes
       
Card
Stack

 
class Card
    Representation of a Playing Card
 
  Methods defined here:
__init__(self, index, facedown=False)
Set up the card
 
index: card number between 1 and 51 - 1=Ace of Spades, 15=Two of Diamonds, 27=Ace of Hearts, 40=Two of Clubs
facedown: True or False, default False - when facedown operations that return the image of the card or 
          a string representation of the card return the image of the back of the card or the string 'Facedown'
flip(self)
Flips the card
   Returns the fully-qualified path name of the image file
   representing either the card face or the back of the card
 
input: none
return: string (filename)
image(self)
Return the fully-qualified path name of the image file
   representing this card
 
input: none
return: string (filename)
indexname(self)
Return a string representation of the value of the card
 
input: none
return: string
isdown(self)
Returns True if card is currently facedown
 
input: none
returns: boolean
name(self)
Return a string representation of the card or 'Facedown' if the card is facedown
 
input: none
return: string
suit(self)
Return the suit of the card as string
 
input: none
return: string

 
class Stack
    Representation of a stack of playing cards
 
  Methods defined here:
__init__(self, numberofdecks=0, noaces=0)
Setup the stack
 
numberofdecks: if >0 then the stack will be initialised with that number of 
               decks of cards.
noaces: if >0 then the stack will be initialised with
        a full deck of cards minus the Aces.
 
If both numberofdecks and noaces are used together then a deck of 100 cards
will be created with only 4 Aces in it (probably not what you want).
addcard(self, card)
Adds the card to the bottom of the Stack
 
card: Card to add to the Stack
returns: None
addncards(self, ncards)
Adds the list of cards to the bottom of this Stack
 
ncards: [Cards]
returns: None
addnewcard(self, index)
Creates a new Card and adds it to the bottom of the Stack
 
index: Card number 1-51
returns: None
addtopcard(self, card)
Adds the card to the top of the Stack
 
card: Card to add the Stack
returns: None
bottomcard(self)
Returns the bottom card without removing it from the Stack
 
input: None
returns: Card
getbottomcard(self)
Returns the bottom card removing it from the Stack
 
input: None
returns: Card
getcard(self, index)
Returns the n card and removes it from the Stack
   if index > len(self.cards) then None is returned
 
index: card number to remove from the stack (0 based)
returns: Card or None
getncards(self, n)
Returns the top n cards and removes them from the Stack
   If n > len(self.cards) then len(self.cards) cards are
   returned (or None if there are no cards in this Stack)
 
n: number of cards to remove
returns: [Cards]
gettopcard(self)
Returns the top card removing it from the Stack
 
input: None
returns: Card
initfull(self, numberofdecks=1)
Initialises the Stack with the required number of cards
 
numberofdecks: integer - This number of 52 card decks will be setup
returns: None
initnoaces(self)
Initialiases the Stack with a full deck minus the Aces
 
input: None
returns: None
length(self)
Returns the number of cards in the stack
 
input: None
returns: integer
shuffle(self)
Randomises the order of the cards in the stack
 
input: None
returns: None
status(self)
Returns a string representation of the status of this Stack
   <number of cards in StackCard name of top card
 
   i.e. "12 cards: Five of Clubs"
 
input: None
returns: String
topcard(self)
Returns the top card without removing it from the Stack
 
input: None
returns: Card