How can I make the following loop end when the user writes stop, otherwise if they answer correctly how can it call the method again so that the number to be guessed is different? The idea of the game is that the user tries to get the number from the class, if they get it correctly then the game asks if they want to guess a new number generated by the class or if they want to stop;if so they write Stop and the game would end. Thanks in advance for the help
class NumberGuessingGame
#clase NumberGuessingGame
def initialize
#metodo que inicia
@number= rand(0..9)
#number es igual a un numero random entre 0 y 9
end
def guess(numer)
#metodo guess que dice que hay una condicion dada por el usuario, si no se da entonces se pide que el usuario la escriba manualmente
if numer<@number
#si el numero es mas pequeño que el numero entonces "Too low"
"Too low"
elsif numer>@number
#si el numero es mayor a el numero entonces "too high"
"Too high"
elsif numer == @number
#si el numero es igual al numero random que pone la computadora entonces "you got it!"
"you got it!"
end
end
end
game = NumberGuessingGame.new
# Pruebas
a = ""
p "Welcome to Guess the Number"
p "Human VS Machine"
while a != "Stop"
x = ""
while x != "you got it!"
p"Write a number between 0 and 9"
y = gets.chomp.to_i
p x = game.guess(y)
end
p "WOOOOW!! Very Impresive. Want to defeat the machine again? If not write
stop or guess the new number"
NumberGuessingGame
a = gets.chomp
end