我的問題是,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/ –