Цветислав обнови решението на 26.03.2014 16:35 (преди над 10 години)
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ @classmethod
+ def getClass(cls):
+ return cls
+ def __str__(self):
+ return self.__class__.__name__
+class Suit:
+ def __init__(self, color):
+ self.color = color
+ def __eq__(self, other):
+ return self.color == other.color
+ def __str__(self):
+ return self.color
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self,"2")
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self,"3")
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self,"4")
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self,"5")
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self,"6")
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self,"7")
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self,"8")
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self,"9")
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self,"10")
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self,"J")
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self,"Q")
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self,"K")
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self,"A")
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self,"red")
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self,"red")
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self,"black")
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self,"black")
+
+
+class Cardx:
+ def __init__(self, rank, suit):
+ object.__setattr__(self, 'rank', rank())
+ object.__setattr__(self, 'suit', suit())
+ def __setattr__(self,*ignore):
+ raise AttributeError("can't set attribute")
+ def __str__(self):
+ return "{} of {}".format(self.rank, self.suit)
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __str__(self):
+ return "{} of {}".format(self.rank, self.suit)
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+class CardCollection(Card):
+ def __init__(self, collection=[]):
+ self.collection = collection
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop()
+
+ def draw_from_bottom(self):
+ return self.collection.pop(0)
+
+ def top_card(self):
+ return self.collection[len(self.collection) - 1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ return self.collection.index(card)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+
+RANKS = {"Two":Two,
+ "Three":Three,
+ "Four":Four,
+ "Five":Five,
+ "Six":Six,
+ "Seven":Seven,
+ "Eight":Eight,
+ "Nine":Nine,
+ "Ten":Ten,
+ "Jack":Jack,
+ "Queen":Queen,
+ "King":King,
+ "Ace":Ace,
+ }
+SUITS = {"Hearts":Hearts,
+ "Diamonds":Diamonds,
+ "Clubs":Clubs,
+ "Spades":Spades
+ }