python / pygame:str没有属性成本

时间:2018-04-05 03:46:07

标签: python class pygame

在我的游戏循环中,我试图绘制数字来代表卡的成本。从我的手中,我正在拉出卡片的名称,这是一个类的一部分,其中.cost会调用一个数字但是当我把它扔到下面的函数中时它表示str没有属性成本:

class Text:
    def __init__(self, text, font, surface, x, y):
        self.text = text
        self.font = font
        self.surface = surface
        self.x = x
        self.y = y

    def draw_text(self):
        text_obj = textPromptFont.render(self.text, 1, (0,0,0))
        text_rect = text_obj.get_rect()
        text_rect.topleft = (self.x, self.y)
        self.surface.blit(text_obj, text_rect)

x= hand[currentHandImageIndex][:-4] #wont show code but printing results something like: Card_Name
text_card_stats_cost = Text(x.cost, textCardStatsFont, DISPLAYSURF, 1050, 200)

Text(x.cost, textCardStatsFont, DISPLAYSURF, 1050, 200).draw_text()

以下是相关卡片类的代码:

class Card_Details_Players:
    def __init__(self, trait, pos, cost, attack, defense, ability, act_type, act_act, sig_type, sig_act, extra1, extra2):
        self.trait = trait
        self.pos = pos
        self.cost = cost
        self.attack = attack
        self.defense = defense
        self.ability = ability
        self.act_type = act_type
        self.act_act = act_act
        self.sig_type = sig_type
        self.sig_act = sig_act
        self.extra1 = extra1
        self.extra2 = extra2

0 个答案:

没有答案