Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class Card:
- def __init__(self, suit, num):
- self.suit = suit
- self.num = num
- def __str__(self):
- print "%i%s" % (num, suit)
- class Deck:
- def __init__(self):
- suits = ['h', 'd', 'c', 's']
- self.cardlist = []
- self.pos = 0
- for s in suits:
- for i in xrange(1, 13):
- self.cardlist.append(Card(s, i))
- self.cardlist = self.shuffle()
- def shuffle(self):
- newlist = []
- done = False
- i = 0
- for i in xrange(52):
- j = random.randint(0, len(self.cardlist))
- newlist.append(self.cardlist.pop(j))
- return newlist
- def deal(self):
- temp = (self.cardlist[self.pos], self.cardlist[self.pos+1])
- pos += 2
- return temp
- class Player:
- def __init__(self, hand):
- self.hand = hand
- def __str__(self):
- print hand[0] + " " + hand[1]
- def main():
- deck = Deck()
- p1 = Player(deck.deal)
- p2 = Player(deck.deal)
- print "Player 1: " + p1 + "\n"
- print "Player 2: " + p2 + "\n"
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment