Code: Alles auswählen
class ShopCardGui:
def __init__(self, surface, shopcard):
self.surface = surface
self.shopcard = shopcard
self.font = pygame.font.SysFont('Arial', 25)
def paint_shop_card(self, x, y):
rect = pygame.draw.rect(self.surface, WHITE, (x, y, 190, 250))
self.surface.blit(self.font.render(self.shopcard.name, True, (255, 0, 0)), (x, y))# problem ist hier
self.surface.blit(self.font.render(str(self.shopcard.energycost), True, (255, 0, 0)), (x, y+220))# und hier
return rect
class ShopCard:
def __init__(self, energy_cost, name=str):
self.name = name
self.energy_cost = energy_cost
class Board
def create_shop_cards(board_size=int):
shop_card_deck = list()
for i in range(10000):
if i <= 3000:
shop_card_deck.append(ShopCard(2, "Snack")) # doppelt so viel energie ausgeben wie man bekommt
elif 3000 < i <= 6000:
shop_card_deck.append(ShopCard(random.randint(1, board_size),"Landfahrzeug"))
elif 6000 < i <= 9000:
shop_card_deck.append(ShopCard( random.randint(1, board_size),"Wasserfahrzeug"))
elif 9000 < i <= 10000:
shop_card_deck.append(ShopCard(board_size, "neue Quest"))
return shop_card_deck
AttributeError: 'str' object has no attribute 'name'
Ursache ist wo ich oben hingeschrieben habe
Ich weis einfach nicht mehr was ich da jetzt noch machen sollen wenn ich den type(self.shopcard.name) abfrage ist es ein string bei type(self.shopcard) ist es Shopcard.Shopcard
wenn ich self.shopcard.name und self.shopcard.elexiercost mit einem beliebigen String ersetze funktiert es