I'm working on some homework, where we started OOP and I'm not really confident in it.
Let's say I have X instances of class Card, where Card is parent class for another subclasses like type of the cards etc, but overall I have all of them saved in variable "instances", so for example 20 instances. What I need is to get 10 of these instances into another Class named Deck, where I will create new list "deck" and have those 10 cards in it, where I will afterwords split them in a half to the 2 players.
My problem there is that I just don't know how to move these instances from class Card to the class Deck and also split them afterwords for these two players. Thanks for your help, I hope I made myself clear.
class Card: instances = [] def __init__(self, name): self.__name = name self.__class__.instances.append(self) class Deck: deck = [] def __init__(self): self.__class__.deck.append(Card.instances) class Player(Deck): def __init__(self, name, deck): super().__init__(deck) self.__name = name def main(): card1 = Card('Card1') card2 = Card('Card2') card3 = Card('Card3') p1 = Player('Tim') p2 = Player('Jill') if __name__ == '__main__': main()
Deckclass. Just a plain list of cards seems like it would work fine.