Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check_for_answer(ans)
- guess = ans+1
- while true
- print "[*] Enter a guess... "
- guess = gets.chomp.to_i
- if guess < ans
- puts " [*] Higher..."
- elsif guess > ans
- puts " [*] Lower..."
- else
- puts " [*] Correct!"
- break
- end
- end
- end
- def singleplayer
- puts "[*] You have entered Single Player"
- puts "\n[*] Now please enter the guessing range (i.e., from x to y [inclusive])"
- print "separated by a comma. "
- x,y = gets.chomp.split(',').map(&:to_i)
- check_for_answer(rand(x..y))
- end
- def multiplayer
- puts "[*] You have entered Multiplayer."
- puts "[*] One player should enter a number while the other looks away."
- puts "[*] Enter answer: "
- answer = gets.chomp.to_i
- system("clear")
- puts "[*] Now bring in the guesser..."
- puts "[*] Hey, guesser. The range is #{answer - rand(0..answer)} to #{answer + rand(1..answer)}"
- check_for_answer(answer)
- end
- def main
- puts "#----------------#"
- puts "# Number Guesser #"
- puts "# by oaktree #"
- puts "#----------------#"
- print "\n"*2
- puts "[*] Here are your options:"
- puts "1. Single Player"
- puts "2. Two Players"
- print "[*] Choice? [1/2] "
- input = gets.chomp.to_i
- if input == 1
- singleplayer
- else
- multiplayer
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement