我正在尝试用 Ruby 制作一个老虎机游戏,这就是我所得到的。它仍然无法运行,并说最后一行有错误,我不知道是什么或如何修复它。
我需要它有类似这样的输出:
你今天想玩多少钱?25
总现金:$ 25
您想下注多少?10
樱桃 - 橙子 - 橙子
你赢了 20 美元
你想继续吗?(是继续) 是
总现金:$ 35
您想下注多少?等等……</p>
我已经在那里设置了奖金,比如如果你得到两个,你赢了两倍的赌注,如果你得到三个,你赢了三倍的赌注。
但我得到了错误:33: syntax error, unexpected $end, expecting kEND cash += cash + winnings
我的代码有什么问题,我该如何解决?
def multiplier(s1, s2, s3)
if s1 == s2 and s2 == s3:
multiplier = 3
elsif s1 == s2 or s2 == s3 or s1 == s3:
multiplier = 2
else
multiplier = 0;
return multiplier
def main()
slotImageList = ['Cherry', 'Orange', 'Plum', 'Bell', 'Melon', 'Bar']
cash = gets
puts "How much total money would you like to play with today? " +cash
while True:
puts("Total cash: $", cash)
bet = gets
puts "How much would you like to bet? " +bet
cash = (cash - bet)
slotImage1 = slotImageList.sample
slotImage2 = slotImageList.sample
slotImage3 = slotImageList.sample
puts "slotImage1", " - ", "slotImage2", " - ", "slotImage3"
winnings = bet * multiplier(slotImage1, slotImage2, slotImage3)
puts "You have won $" +winnings
cash = cash + winnings
cont = gets
puts "Would you like to continue? (yes to continue) " +cont
if cont != "yes":
puts "You have ended with $" +cash
else
puts " "
end