Created
August 14, 2021 11:18
-
-
Save hokupod/d1f6034abe2b6bd797fc3ca7720ec8bd to your computer and use it in GitHub Desktop.
数当てゲーム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def incorrect_message(mascot, mess) | |
puts "\e[93m#{mascot}\e[0m\e[32m < #{mess}\e[0m" | |
end | |
answer_count = 0 | |
max_value = ARGV[0].to_i | |
incorrect_message '(´,,•ω•,,`)◝', | |
"1 から #{max_value} のあいだで こたえ の すうじ をいれてね" | |
input = STDIN.gets.to_i | |
answer = Random.new.rand(1..max_value) | |
grater_nums = [] | |
less_nums = [] | |
loop do | |
answer_count += 1 | |
case | |
when input == 0 | |
incorrect_message '(p_q)', 'すうじ を いれてね' | |
answer_count -= 1 | |
when input == answer | |
print "\e[7m" | |
puts '🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉' | |
puts "🎉 おめでとう。#{answer_count}かいで せいかいです!! 🎉" | |
puts '🎉 また ちょうせん してね!! 🎉' | |
puts '🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉' | |
print "\e[0m" | |
exit | |
when input < answer | |
less_nums << input | |
when input > answer | |
grater_nums << input | |
else | |
incorrect_message '(p_q)', 'すうじ を いれてね' | |
answer_count -= 1 | |
end | |
if !grater_nums.empty? && !less_nums.empty? | |
incorrect_message '*ଘ(੭*ˊᵕˋ)੭*', | |
"#{less_nums.max} より おおきく、#{grater_nums.min} より ちいさいよ" | |
elsif grater_nums.empty? | |
incorrect_message '*ଘ(੭*ˊᵕˋ)੭*', | |
"#{less_nums.max} より おおきいよ" | |
elsif less_nums.empty? | |
incorrect_message '*ଘ(੭*ˊᵕˋ)੭*', | |
"#{grater_nums.min} より ちいさいよ" | |
end | |
input = STDIN.gets.to_i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment