Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: Simultaneous text input/output in a command line game
Gennady Bystritsky
2/12/2006 6:18:00 AM
Just from the tip of my head:
t = Thread.new {
while true
sleep 5
puts "What are you waiting for, dude? Enter something now: "
end
}
puts "Enter something: "
s = gets
t.kill
puts "You entered: #{s.inspect}"
Gennady.
> -----Original Message-----
> From: rubyvic [mailto:rubyvic@gmail.com]
> Sent: Saturday, February 11, 2006 22:08
> To: ruby-talk ML
> Subject: Simultaneous text input/output in a command line game
>
> Hi everyone!
>
> I'm currently learning Ruby, and have made this simple number
> guessing game:
> ____________________________
> puts "I'm thinking of a number from 0 to 10. What's your guess?"
>
> my_number = rand(11)
> user_guess = gets.chomp.to_i
>
> until user_guess == my_number
> if user_guess > my_number
> puts "Too high."
> else my_number > user_guess
> puts "Too low."
> end
> puts "Guess again:"
> user_guess = gets.chomp.to_i
> end
>
> puts "Yep, it was " + my_number.to_s + ". You win!"
> ____________________________
>
> A friend of mine wrote a Java version which you can see here:
>
http://violasong.com/tonyguessin...
. In addition to
> what my script does, his is able to taunt you with a random
> message if you don't input any data for 5 seconds :).
>
> I want to try adding that functionality to my script, and am
> wondering if it's possible in Ruby - to print a message every
> x seconds *while* it's waiting for you to input something. If
> someone could point me in the right direction, that would be
> much appreciated!
>
> Victoria Wang
>
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Simultaneous text input/output in a command line game
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password