我的问题是,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来玩这个问题的手数。
Ruby 1.8.7已经退役。可能是升级的时间... https://www.ruby-lang.org/zh/news/2013/06/30/we-retire-1-8-7/ –