Poker Hand
def dealHand(n):
import random
#Deal a poker hand using random.shuffle(range)
dir = 'I:\Documents and Settings\Cedric Stallworth\Desktop\Job CoC\Classes\Spring 2007\CS1315\modules\cards'
hand = makeEmptyPicture(n*80, 100)
deck = range(1,52+1)
random.shuffle(deck)
for index in range(1,n+1):
card = makePicture(dir+"//"+ str(deck[index])+'.jpg')
insertCard(card,1,getWidth(card),1,getHeight(card),hand,80*(index-1)+1,1)
show(hand)
######################################################################## Helper Functions
def insertCard(source, sx_start, sx_end, sy_start, sy_end, target, tx, ty):
targetX = tx
for sourceX in range(sx_start, sx_end+1):
targetY = ty
for sourceY in range(sy_start, sy_end+1):
sourcePixel = getPixel(source, sourceX, sourceY)
sourceColor = getColor(sourcePixel)
targetPixel = getPixel(target, targetX, targetY)
setColor(targetPixel, sourceColor)
targetY = targetY + 1
targetX = targetX + 1
Link to this Page