我的二十一点cli中的错误消息在ruby中

时间:2016-08-21 19:01:16

标签: ruby blackjack

我在Learn.co实验室工作Blackjack cli线是https://learn.co/tracks/web-development-fundamentals/intro-to-ruby/looping/blackjack-cli?batch_id=166&track_id=10415然而,需要通过的15个例子我继续得到6个错误我主要遇到麻烦initial_round方法和命中?方法

i keep getting an error in the initial round method asking me to call on the display_card_total method to print the sum of cards and the hit? confuses me a little as to what exact its asking

def deal_card
 rand(11) + 1
end

def display_card_total(card)
    puts "Your cards add up to #{card}"
end

def prompt_user
  puts "Type 'h' to hit or 's' to stay"
end

def get_user_input
  gets.chomp
end

def end_game(card_total)
    puts "Sorry, you hit #{card_total}. Thanks for playing!"
end

def initial_round
    deal_card
    deal_card
    return deal_card + deal_card
    puts display_card_total
end

def hit?
    prompt_user
end

def invalid_command
  puts "Please enter a valid command"
end

希望这是足够的信息

1 个答案:

答案 0 :(得分:0)

你还没有完成任务。

它指定hit?方法应该采用当前卡总数的参数,因此它应该是......

  def hit?(current_card_total)

然后指定您应该执行prompt_user get_user_input,然后测试结果为" h"或" s"或其他,并采取适当的行动。

如果你做了" h"对于命中,current_card_total将增加,否则如果你做了" s"它没有改变,但你需要返回值,无论它是否发生变化。

如果用户在" h"旁边输入了其他内容。或" s"您调用invalid_command方法并再次提示输入正确的值(prompt_user),然后您可以尝试使用get_user_input再次获得回复

所以,像这样......

def hit?(current_card_value)
  prompt_user
  user_input = get_user_input
  while user_input != "h" && user_input != "s"
    invalid_command
    prompt_user
    user_input = get_user_input
  end
  if user_input == "h"
    current_card_value += deal_card
  end
  return current_card_value
end

您的initial_deal出现了一些问题,但首先,您需要在变量中跟踪deal_card结果

current_card_total = deal_card
current_card_total += deal_card

那样current_card_total累计总数。刚做

deal_card
deal_Card

不会将deal_card的结果存储在任何地方。