ruby 中我的 blackjack cli 中的错误消息
Error messages in my blackjack cli in ruby
我正在开发一个 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 方法和命中?方法。
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
希望这是足够的信息
你没有完成作业。
它指定hit?
方法应该接受当前卡片总数的参数,所以它应该是...
def hit?(current_card_total)
然后指定您应该执行 prompt_user
和 get_user_input
然后测试 "h" 或 "s" 的结果或其他并采取适当的行动。
如果你做一个"h"命中,current_card_total会增加,否则如果你做一个"s"它是不变的,但你需要return值,无论是否更改。
如果用户在 "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
的结果存储在任何地方。
我正在开发一个 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 方法和命中?方法。
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
希望这是足够的信息
你没有完成作业。
它指定hit?
方法应该接受当前卡片总数的参数,所以它应该是...
def hit?(current_card_total)
然后指定您应该执行 prompt_user
和 get_user_input
然后测试 "h" 或 "s" 的结果或其他并采取适当的行动。
如果你做一个"h"命中,current_card_total会增加,否则如果你做一个"s"它是不变的,但你需要return值,无论是否更改。
如果用户在 "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
的结果存储在任何地方。