On Sun, May 8, 2011 at 12:08 AM, Super Goat <ruby-forum / sgoat.33mail.com>wrote:

>
> Attachments:
> http://www.ruby-forum.com/attachment/6181/meth_100guess.rb
>
>

> attempts = "0".to_i

In the same way you have string literals (the "0"), you also have integer
literals (just 0).
0 == "0".to_i # => true

So just make it `attempts = 0`, same for flag.



> flag = "8".to_i

This seems to record the maximum number of times you can guess. I would call
it something like "max_attempts", "flag" is not a descriptive name.



On Sun, May 8, 2011 at 12:08 AM, Super Goat <ruby-forum / sgoat.33mail.com>wrote:

>
> I was thinking of asking if the player would like to play again and then
> figuring out how to restart the whole thing but I wasn't sure how to do
> this. How can I make prompt to "Play again?" and when answered "Yes"
> restart, whether the person wins or loses (or if "No" just exits)?  Or
> is the way my code is written make this impossible?
>
>
Right now there is no mechanism to get back to the beginning where variables
are set and such. What if you had a method that did everything involved with
a game, then you could play a game by calling that method. That would allow
you to just have a little piece of code that is responsible for handling
whether you should play another game or not.

def play_game
  # ...
end

def play_again?
  # prompt user, return true or false
end

play_game
play_game while play_again?
puts "goodbye!"