Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Simple game "Guess what number I mean" in Ruby written by Mrowqa
- class String
- def is_integer? # add our test
- self =~ /^[-+]?([0-9]*)?$/
- end
- end
- times = 0
- Random::srand Integer(Time.now)
- number = (Random::rand*100).to_i % 100 + 1 # 1..100
- puts "Type number from 1 to 100 range: "
- begin
- times+=1
- input = gets[0..-2]
- if not input.is_integer?
- puts "Wrong! This is *NOT* number. Try one more time:"
- times-=1
- next
- end
- no=Integer(input)
- case
- when no<1 || no>100
- puts "#{no} isn't from given range!"
- times-=1
- when no<number
- puts "#{no} is too small!"
- when no>number
- puts "#{no} is too big!"
- end
- end while no!=number
- puts "You guessed #{number} by #{times} time!"
Advertisement
Add Comment
Please, Sign In to add comment