File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kevin Youngblood
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Junilu Lacar
Bartender
Pie
Posts: 6544
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would opt for calling the play() method on a Game object:
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic