mardi 18 avril 2017

Setting up a class with instances

I'm trying to create a class to represent a deck of cards for a blackjack game. So far I have a class to represent the player's bankroll, and one for the deack. I also have a very clumsy attempt at instantiating the cards individually:

class Player(object):
    def _init_(self,bankroll=100):
        self.bankroll=bankroll
    def add_bankroll(self,amount):
        self.bankroll += amount
        print ("you have won")
        return amount
    def subtract_bankroll(self,amount):
        self.bankroll -= amount
        print ("You have lost")
        return amount

class Deck(object):
    def _init_(self,suit,value):
        self.value=value
        self.suit=suit
    def _del_(self):
        del(self)
     def _getvalue_(self):
        return self.value




two_of_hearts = Deck(suit='hearts',value=2)
three_of_hearts = Deck(suit='hearts',value=3)
four_of_hearts = Deck(suit='hearts',value=4)
five_of_hearts = Deck(suit='hearts',value=5)
six_of_hearts = Deck(suit='hearts',value=6)
seven_of_hearts = Deck(suit='hearts',value=7)
eight_of_hearts = Deck(suit='hearts',value=8)
nine_of_hearts = Deck(suit='hearts',value=9)
ten_of_hearts = Deck(suit='hearts',value=10)
jack_of_hearts = Deck(suit='hearts',value=10)
queen_of_hearts = Deck(suit='hearts',value=10)
king_of_hearts = Deck(suit='hearts',value=10)
ace_of_hearts = Deck(suit='hearts',value=11 or 1)


_getvalue_(two_of_hearts)


I keep getting this error:

---------------------------------------------------------------------------
    TypeError      Traceback (most recent call last)
<ipython-input-13-0a5e1642e9cc> in <module>()
     11         return amount
     12 
---> 13 class Deck(object(())):
     14     def _init_(self,suit,value):
     15         self.value=value

TypeError: object() takes no parameters


Any help would be much appreciated.






Comments
0 Comments

0 commentaires:

Enregistrer un commentaire