我制作Blackjack游戏时方法count_card()和count_house()正在工作,当我定义一个对象然后我调用方法并且它工作但是当我调用Game()方法并且我玩它时给我一个TypeError。 我认为因为当随机卡给我'K'或'Q'时它会给我错误,但它会尝试使用该方法并且它可以工作并再次对Game()方法不起作用
谢谢你......
import random
class House(对象):
def __init__(self, house_amount = 0, house_check = 0):
self.deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'K', 'Q', 'j']
self.house_card = [random.choice(self.deck), random.choice(self.deck)]
self.house_stach = 100
self.house_amount = house_amount
self.house_check = house_check
def first_check(self):
self.first_check = 0
for num in self.house_card:
if num in ['K', 'Q', 'J']:
num = 10
self.house_check += num
return self.house_check
def count_house(self):
self.house_amount = 0
for num in self.house_card:
if num in ['K', 'Q', 'J']:
num = 10
self.house_amount += num
return self.house_amount
def house_hit(self):
card = random.choice(self.deck)
self.house_card.append(card)
print self.house_card
return self.house_card
班主任(众议院):
def __init__(self, player_bet, player_amount = 0, house_amount=0, house_check = 0):
super(Player, self).__init__(house_amount, house_check)
self.player_bet = player_bet
self.player_card = [random.choice(self.deck), random.choice(self.deck)]
self.player_stach = 10
self.player_amount = player_amount
def hit(self):
card = random.choice(self.deck)
self.player_card.append(card)
print self.player_card
return self.player_card
def stand(self):
return self.player_card
def player_win(self, amount):
self.player_stach += amount
def player_lose(self, amount):
self.player_stach -= amount
def count_card(self):
self.player_amount = 0
for num in self.player_card:
if num in ['K', 'Q', 'J']:
num = 10
self.player_amount += num
return self.player_amount
类二十一点(玩家):
def __init__(self, player_bet, house_amount=0, player_amount=0, house_check = 0):
super(Blackjack, self).__init__(player_bet, player_amount, house_amount, house_check)
self.Game()
def win_check(self):
if self.house_amount > 21:
print 'Player Has Won Cong...'
elif self.player_amount > 21:
print 'House Has Won'
elif self.player_amount <= 21 and self.player_amount > self.house_amount :
print 'The Player Has Won :D'
elif self.house_amount <= 21 and self.house_amount > self.player_amount:
print 'The House Has Won Gave me your Mony '
else:
print 'Shit'
def Game(self):
while self.player_stach != 0:
print 'Your Cards (%s)'%(self.player_card)
print 'The House Cards (%s) '%(self.house_card)
ask = raw_input('Do you want A Hit or Stand or Done ?').title()
if ask == 'Hit':
self.hit()
elif ask=='Stand':
self.stand()
elif ask == 'Done':
self.count_card()
self.first_check()
if self.house_check <= 17:
self.house_hit()
self.count_house()
self.win_check()
break
else:
print 'Please Choice the right....!'
.