オブジェクトのリスト (これはゲーム用です) があり、リスト自体をオブジェクトにしたいと考えています。
最初のオブジェクトはカードです。
class card (object):
def __init__ (self,suit,value):
self.suit = suit
self.value = value
def cardpointvalue(self):
#not relevant, basically says if card is this return this value for it
# there is also a __str__ function and a ___repr___ function, don't think
# they are important
これが私のカード オブジェクトです。問題が発生しているハンド オブジェクトもあります。
class hand (object):
def __init__ (self,list_cards):
self.list_cards = list_cards
def hand_value (self):
for i in list:
handpointvalue += (i.cardpointvalue())
return handpointvalue
私が問題を抱えている私のmain()では。
デッキ内の各カードをカード オブジェクトにするリストがあります。次に、リスト 1 とリスト 2 という人のハンドにそれらを渡します (各プレイヤーについて、簡単にするためにリスト 1 のみを扱います)。
各プレイヤーのカードをリストに渡したら。handpointvalue
リストをハンドオブジェクトにしてから、それらに対して関数を実行しようとします。
そう
for i in range(10):
one_card = card_deck.pop(0) #each card is an object at this point
list1.append(one_card)
print (list1) #just testing, get a list of each card object
ここが私が困っているところです。私は複数のことを試しましたが、最新のものは次のとおりです。
hand(list1)
print (list1.handpointvalue())
なぜこれが機能しないのですか?このオブジェクト リストをオブジェクト自体にするにはどうすればよいですか?