Skip to content

Instantly share code, notes, and snippets.

@gouf
Forked from murajun1978/じゃんけん.rb
Last active August 29, 2015 14:21
Show Gist options
  • Save gouf/22ca4acd06be0769f2db to your computer and use it in GitHub Desktop.
Save gouf/22ca4acd06be0769f2db to your computer and use it in GitHub Desktop.
あいて = %w(ぐー ちょき ぱー)
じゃんけん = { :"ぐー" => 0,
:"ちょき" => 1,
:"ぱー" => 2}
loop do
print 'じゃんけん... :'
ぷれいやーの手 = gets.chomp
break if ぷれいやーの手 == 'やめる'
あいての手 = あいて.sample
puts "相手の手#{あいての手}"
result_num = (じゃんけん[ぷれいやーの手.to_sym] -
じゃんけん[あいての手.to_sym])
if あいての手 == ぷれいやーの手
puts 'あいこ!'
elsif [-1, 2].include?(result_num)
puts 'かち!'
else
puts 'まけ!'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment