Trying to remove an object from an object list which is a class variable

Discussion in 'Python' started by Deusexnominus, Jan 6, 2022.

Tags:
  1. Deusexnominus

    Deusexnominus New Member

    Joined:
    Jan 5, 2022
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Hello, I'm trying to make a card game with objects.

    Here's my class deck and my class hand:

    Code:
    class Deck:
    
        def __init__(self):
            self.deckcardlist = []
           
        def Populate(self):
            for r in Card.RANK:
                for s in Card.SUIT:
                    card = Card(r, s )
                    deckcardlist.append(card)
            self.deckcardlist = cardlist
    
        def Shuffle(self):
            random.shuffle(self.cardlist)
    
        def Deal(self, Hand):
            if self.deckcardlist != []:
                card = self.deckcardlist[0]
                handlist.append(card)
                self.deckcardlist.remove(deckcardlist[0])      <--------------------------------- 
            else:
                print("Out of cards!")
        def AdditionalCards(self, genericplayer):
            pass
    
    class Hand:
    
        def __init__(self):
            self.hand = []
    
        def AddCard(self):
            self.hand
    
        def Clear(self):
            self.hand = []
           
    

    but now in my deal function I have to remove the card that i deal and the only thing I can imagine is
    self.deckcardlist.remove(deckcardlist[0]) which evidently doesn't make sense. so how do can i do it?

    N.B: I'm just starting to code so please dumb it down
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice