First you have to get the basic design of the deck and the hand of cards down:
# basic design of a card game using Python
import random
def show_hand(hand):
"""give drawn cards more detailed descriptions and then display"""
for item in hand:
rank = item[0]
suit = item[1]
if rank == 1:
rank = "Ace"
elif rank == 11:
rank = 'Jack'
elif rank == 12:
rank = 'Queen'
elif rank == 13:
rank = 'King'
if suit == 'h':
suit = "Hearts"
elif suit == 'c':
suit = "Clubs"
elif suit == 's':
suit = "Spades"
elif suit == 'd':
suit = "Diamonds"
print "%s of %s" % (rank, suit)
card_list = [ (rank, suit) for suit in "hcds" for rank in range(1, 14)]
# test
# these could also be the image filenames of the cards for the GUI game
print card_list
print "-"*30
# or make the hand all cards and show detail
show_hand(card_list)
print "-"*30
# pull 5 cards
hand = card_list[:5]
# show the hand
show_hand(hand)
print "-"*30
# now shuffle cards, pull hand of 5 cards and sort hand by rank
random.shuffle(card_list)
# pull 5 cards
hand = card_list[:5]
# sort the hand by rank
hand.sort()
# show the hand
show_hand(hand)
Ene Uran
Posting Virtuoso
1,830 posts since Aug 2005
Reputation Points: 676
Solved Threads: 255
Skill Endorsements: 7
The card_list is a little cryptic and show_hand() flashes out more descriptive card names.
Ene Uran
Posting Virtuoso
1,830 posts since Aug 2005
Reputation Points: 676
Solved Threads: 255
Skill Endorsements: 7