Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kevin Youngblood
Greenhorn
Posts: 1
  • 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
Posts: 2952
59
  • 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: 12097
30
Chrome Java Linux
  • 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: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would opt for calling the play() method on a Game object:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic