我的问题是它chips
没有保存为传递的参数的全局变量。我正在通过$h1c
(这是玩家第一手拥有的总筹码数)。因此,如果他赢或输,chips
则应设置为等于chips
+
或-
betamount
。
问题是它没有被保存为全局变量。如果我要写$h1c = 150_000
,那就等于那个。如果稍后我写$h1c = 150_000 + 50_000
,那么 200_000 将是 $h1c 的新值。
由于某种原因,当我声明时这不起作用chips = chips + betamount
,这与说相同$h1c = $h1c + $h1bet
。
def review(hand, chips, betamount)
abc = valueofcards(hand) #player's hand value
klm = valueofcards($handD) #dealer's hand value
if abc == klm and abc < 19
puts "You tied"
chips = chips
elsif abc > 18
puts "You lost"
chips = chips - betamount
elsif abc < 19 and klm > 18
puts "You won"
chips = chips + betamount
elsif abc < 19 and abc > klm
puts "You won"
chips = chips + betamount
elsif abc < 19 and klm < 19 and klm > abc
puts "You lost"
chips = chips - betamount
end
end
这是我通过参数进行审查的地方:
def pre_review(num)
puts "Recap of that round"
puts "First Hand:"
review($hand1, $h1c, $h1bet)
muckcards(num)
end
如果需要,这里是完整代码/游戏的链接以测试问题http://labs.codecademy.com/Bmvl#:workspace 注意:我目前只是想让这部分工作以 $ hand1,因此您将选择 1 作为要玩的手数来重现此问题。