我遇到的主要问题是当我选择stay
on hand_one
,然后hit
on时会发生什么hand_two
。
hit or stay
当我已经选择留在 hand_one 上时,它没有让我再次打开,而是hand_two
让我重新hit or stay
打开hand_one
,所以 hand_one 应该没有更多选项。这会导致出现多个打印语句和不正确的游戏玩法的问题。
我的代码有什么问题,就像导致它循环回hand_one
.
完整代码在这里:http ://labs.codecademy.com/Bjaf/2#:workspace
这是可能导致问题的部分。
def hit_or_stay(person):
hit_or_stay = raw_input("Do you want to hit or stay? You can type h or s.")
if hit_or_stay == 'h' or hit_or_stay == 'hit':
deal_one_card(person)
value_of_current_cards(person)
number_value_of_hand()
elif hit_or_stay == 's'or hit_or_stay == 'stay':
print "You stayed"
return
else:
hit_or_stay(person)
def number_value_of_hand():
if number_of_hands > 0:
value_of_hand_one = value_of_current_cards(hand_one)
if value_of_hand_one < 18:
print "\n" "You have %i" % (value_of_hand_one)
hit_or_stay(hand_one)
elif value_of_hand_one > 18:
print "You Lose"
return
elif value_of_hand_one == 18:
print "You hit HOT 18!!!"
return
if number_of_hands > 1:
value_of_hand_two = value_of_current_cards(hand_two)
if value_of_hand_two < 18:
print "\n" "Your second hand has %i" % (value_of_hand_two)
hit_or_stay(hand_two)
elif value_of_hand_two > 18:
print "You Lose"
return
elif value_of_hand_two == 18:
print "You hit HOT 18!!!"
return
number_value_of_hand()
谁能明白为什么它会循环回来给 hand_one 另一个选择?可能我该如何解决?非常感谢!