aspose file tools*
The moose likes Beginning Java and the fly likes Same ol' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Same ol Watch "Same ol New topic
Author

Same ol' "do you want to play again?" question

Kevin Youngblood
Greenhorn

Joined: Feb 01, 2013
Posts: 1
Hello all, this is my first post of I'm sure what will be many as I'm getting into this game at an "older" age. I am attempting the "number guessing game" that it seems just about everybody has done at one time or another and have just about everything completed (besides "prettying" it up) except the option to play again or exit the game. I've tried a do/while loop, and a while loop but can not get it to work. Obviously the working program would give the user the option to play again, but for trying to figure out where that option should go, I've simply stated that the boolean "gameOver" is false which I feel should reset the game. Any help would be greatly appreciated. Thanks in advance.



I hope I posted the code correctly.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2359
    
  50
For a start be consistent with your formatting. It becomes increasingly difficult to read code and, hence easier to make mistakes, if you aren't consistent with things like indenting, use/placement of curly braces etc.
Also never test if a boolean is equal to true or false or you could make a typing mistake (as you have) and end up assigning a value. For example for booleans you can you use the following to test for true and the following to test for false
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11471
    
  16

personally, I'd write it in such a way that "playing a game" is done by calling a method. So I'd have a method like:



Then, you'd simply do this:



There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4989
    
    8

I would opt for calling the play() method on a Game object:


Junilu - [How to Ask Questions] [How to Answer Questions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Same ol' "do you want to play again?" question