属性错误:'游戏'对象没有属性' uValue' 有人可以用我的意大利面条代码帮助我吗? 当我运行我的程序时,我想将hit卡值添加到self.uValue(我的用户的总手值)。虽然我得到了上面列出的错误和(self.TotalC)相同的错误(手中的总卡)。我也有问题在self.uValue的Usercards方法中保留值。即使我每次想要打印值时都返回值,但是当我在方法中打印时,它会等于零。
class game():
def __init__(self):
self.TotalC = 2 # total cards in the hand
def Usercards(self):
UC1= cards() # defining both objects
UC2= cards()
UC1.deck() # defingin each card
UC2.deck()
uHand.remove("deal") # removes deal from the hand allowing the user to start hitting
card1v=int(UC1.value) # the value of the card is equal to the self.value of it
card1s=UC1.suit # the suit of the card is definined as a varible from self.suit of the call class
card2v=int(UC2.value) # same for the second card
card2s=UC2.suit
type=UC1.num # type of the card is defined from the call class (self.num) example: (ace, 2, king , 5)
card1 = Image(Point(300,350), (card1s+type+".gif")) # graphics deinfed where to draw and what to draw
card1.draw(win) # draws image
type=UC2.num #type of second card
card2 = Image(Point(225,350), (card2s+type+".gif")) # graphics defined for the second card
card2.draw(win) # draws second card
self.uValue= card1v + card2v # add the value varibles for both cards
print(self.uValue) # prints value
self.TotalC = 2
return card1v, card1s, card2v, card2s,uHand, self.uValue #reurtns card suits and values and hand
def AIhand(self):
back = Image(Point(225, 150),("back.gif"))
back.draw(win)
AIC1= cards()
AIC1.deck()
AIcard1v=int(AIC1.value) # the value of the card is equal to the self.value of it
#second card (visible one)
AIC2= cards()
AIC2.deck()
AIcard2v=int(AIC2.value) # the value of the card is equal to the self.value of it
AIcard2s=AIC2.suit # the suit of the card is definined as a varible from self.suit of the call class
AItype2=AIC2.num # type of the card is defined from the call class (self.num) example: (ace, 2, king , 5)
AIcard2 = Image(Point(300,150), (AIcard2s+AItype2+".gif")) # graphics defined for the second card
AIcard2.draw(win) # draws second card
self.AIvalue = AIcard2v + AIcard1v
print(self.AIvalue)
return self.AIvalue, AIHand # AI2 = "{}{}".format(AIC2.suit, AIC2.num)
def wincon(self):
if self.uValue>AIHV:
print("You win")
uHand.append("deal")
else:
print("You lose")
uHand.append("deal")
def UHit(self):
HC1 = cards()
HC1.deck()
value = int(HC1.value)
suit = HC1.suit
type = HC1.num
print (self.uValue)
if self.TotalC==2:
card1 = Image(Point(375, 350), (suit + type +".gif"))
card1.draw(win)
elif self.TotalC==3:
card1 = Image(Point(450, 350), (suit + type + ".gif"))
card1.draw(win)
elif self.TotalC==4:
card1 = Image(Point(450, 375), (suit + type + ".gif"))
card1.draw(win)