欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ruby實(shí)現(xiàn)石頭剪刀布游戲示例

 更新時(shí)間:2014年05月05日 11:01:55   作者:  
這篇文章主要介紹了ruby實(shí)現(xiàn)石頭剪刀布游戲示例,需要的朋友可以參考下

ruby實(shí)現(xiàn)石頭剪刀布游戲

復(fù)制代碼 代碼如下:

#encoding: utf-8
arr = ['石頭', '剪刀', '布']
win_arr = [['石頭', '剪刀'], ['剪刀', '布'], ['布', '石頭']]
#隨機(jī)computer的值,放入result數(shù)組中
result = [arr.sample]
while (true)
  puts "請(qǐng)輸入石頭、剪刀、布"
  input_value = gets.force_encoding("GBK").encode("UTF-8").chomp
  if arr.include? input_value
    result << input_value
    if result[0] == result[1]
      puts '平手'
    elsif win_arr.include? result
      puts '電腦獲勝'
    else
      puts '您獲勝了'
      break
    end
  else
    puts '輸入的值有誤,請(qǐng)輸入石頭、剪刀、布'
    next
  end
end

相關(guān)文章

最新評(píng)論