Re: stop program with entering a key

Use puts to print the screen and gets to get the user’s input.

I’m guessing you want to add something like

puts “pls press -1 to stop game”
answer = gets
if answer.to_i == -1 or answer == randomnumber
puts “Continue or stop? (y/n)”
answer = gets
if answer.chomps == “y”
puts “Thank you for playing, game over.”
Process.exit
end
end

Was that any help?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs