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 = []
- for s in suits:
- for i in xrange(1, 13):
- self.cardlist.append(Card(s, i))
- self.cardlist = self.shuffle()
- def shuffle(self):
- newlist = []
- used = []
- done = False
- i = 0
- while done == False:
- j = random.randint(0, 51)
- if j not in used:
- newlist[i] = self.cardlist[j]
- used.append(j)
- i += 1
- if i == 51:
- done = True
- return newlist
- class Player:
- def __init__(self, hand):
- self.hand = hand
- def __str__(self):
- print hand[0] + " " + hand[1]
- def main():
- deck = Deck()
- p1 = Player((deck.pop(), deck.pop()))
- p2 = Player((deck.pop(), deck.pop()))
- print "Player 1: " + p1 + "\n"
- print "Player 2: " + p2 + "\n"
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment