class Card: """ This class is a model of map data that contains the type of map, the suit of the map, the appearance of the map, the width, height, position on the screen, and methods for working with them """ data = {'type_card': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], 'card_in_deck': 52, 'card_in_pyr': 28, 'card_in_last_pyr': 7, 'card_sum': 13, 'start_open_pyr': 21} def __init__(self, atype, suit, visible=False, close=False, width=100, height=150): """ The method initializes the creation of the class, passes the type of the map, an integer value from 1 to 13. The card's value, string value, diamonds, hearts, spades, clubs. map visibility, Boolean value. width and height integer value :param atype: integer 1<= atype <= 13 :param suit: string diamonds, hearts, spades, clubs :param visible: Boolean True or False :param width: integer :param height: integer """ if type(atype) is int and atype in Card.data['type_card']: self.catype = atype else: raise Exception("Type not integral or not within 1..13") if type(suit) is str and suit in ['diamonds', 'hearts', 'spades', 'clubs']: self.csuit = suit else: raise Exception("The suit must be a string, and enters the sheet diamonds, hearts, spades, clubs") if type(visible) is bool: self.cvisible = visible else: raise Exception("The visibility parameter must be a Boolean value") if type(close) is bool: self.cclose = close else: raise Exception("The visibility parameter must be a Boolean value") if type(width) is int: self.cwidth = width else: raise Exception("Width must be an integer value") if type(height) is int: self.cheight = height else: raise Exception("Height must be an integer value") self.position = [0, 0] @property def x(self): """ Card position by x :return: x integer """ return self.position[0] @property def y(self): """ Card position by y :return: y integer """ return self.position[1] @x.setter def x(self, value): """ Set position x. if type value not integer raise Exception :param value: integer """ if type(value) is int: self.position[0] = value else: raise Exception("Position 'x' must be an integer value") @y.setter def y(self, value): """ Set position y. if type value not integer raise Exception :param value: integer """ if type(value) is int: self.position[1] = value else: raise Exception("Position 'y' must be an integer value") @property def img(self): """ Create and return image by format :return: ATYPE_of_SUIT.png """ return "%i_of_%s.png" % (self.catype, self.csuit) @property def atype(self): """ This method has been return a type of card :return: integer """ return self.catype @property def suit(self): """ This method has been return a suite of card :return: string """ return self.csuit @property def visible(self): """ This method has been return a visible of card :return: boolean """ return self.cvisible @visible.setter def visible(self, value): """ This method set a visible of card, if value not boolean raise exception :param value: bool """ if type(value) is bool: self.cvisible = value else: raise Exception("The visibility parameter must be a Boolean value") @property def close(self): """ This method return closed card or not close :return: bool """ return self.cclose @close.setter def close(self, close): """ This method set closed or not closed card. If close not boolean value raise exception :param close: bool """ if type(close) is bool: self.cclose = close else: raise Exception("The close parameter must be a Boolean value") # @property # def clicked(self, x, y): # """ # This method return clicked in card or not clicked # if x or y not integer raise exception # :param x: Integer # :param y: Integer # :return: Boolean # """ # if type(x) is int and type(y) is int: # if self.x < x < self.x + self.width and self.y < y < self.y + self.height: # return True # return False # raise Exception("Position 'x' and 'y' must be an integer value") # # @property # def width(self): # """ # This method return a width of card # :return: integer # """ # return self.width # # @property # def height(self): # """ # This method return a height of card # :return: integer # """ # return self.height class Deck: """ This class is model deck """ def __init__(self, cards): self.__cards = cards @property def getdiamonds(self): """ This mwthod return only diamonds card :return: list of object Card """ temp = [] for i in range(len(self.__cards)): if self.__cards[i].atype == "diamonds": temp.append(self.__cards[i]) return temp @property def gethearts(self): """ This method return only spades card :return: list of object Card """ temp = [] for i in range(len(self.__cards)): if self.__cards[i].atype == "hearts": temp.append(self.__cards[i]) return temp @property def getspades(self): """ This method return only spades card :return: list of object Card """ temp = [] for i in range(len(self.__cards)): if self.__cards[i].atype == "spades": temp.append(self.__cards[i]) return temp @property def getclubs(self): """ This method return only clubs card :return: list of object Card """ temp = [] for i in range(len(self.__cards)): if self.__cards[i].atype == "clubs": temp.append(self.__cards[i]) return temp @property def mix(self): """ This method suffle cards in deck """ from random import shuffle shuffle(self.__cards) @property def get(self): """ This method return a cards of deck :return: list of object Card """ return self.__cards