• Post Reply Bookmark Topic Watch Topic
  • New Topic

In search of a method to call a section of code to run again  RSS feed

 
Vincent Tyson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't even know what the method is called, but basically after my Blackjack game is over, I would like the game to ask me if I want to play again y || n.
and then initiate a new game prompted by the keystroke y.

I've seen it done in a few games, and I'm getting a little jealous, could someone tell me the name of the method I need and a short description on how it functions I would be grateful.

or as an alternative just the method type and a tutorial page.

Either is fine, thanks for the help.

Vincent
 
Stefan Evans
Bartender
Posts: 1837
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is simple enough.

Create a method called "playGame()" which plays one game of blackjack

And then put a loop around that method
 
Vincent Tyson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Stefan

I was actually pretty close to something like that, only I didn't use void.

So if I'm picking this up right, the void playgame() is skipped over entirely until the playgame(); line at the end has it's condition met, but following the logic in that, (I'm almost always wrong with the logic) wouldn't the game start with "would you like to play again? Y /N" since the entire game is skipped over on the first iteration of the game until the condition for void playgame = true?

I'll need to play around with the code and try to see for myself how this works. you also have a while (!done), my understanding is ! = not, ... so while not "done" execute this order. I just can't follow the logic in the code section.

I'll give it a try and see how it goes, I won't be around for the next day or so, but I'll be back with more questions I'm sure of it !!

Thanks
Vincent
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you go back to your other thread, the code that I gave to illustrate the strategy of decomposing a large problem into smaller problems has the loop you need, similar to the example given here. Negations like !done are a little bit more confusing than something like keepPlaying, which is what I had in the example I gave. It gets even trickier when you use double negatives like !incomplete. It can take a bit of effort to find the right name to eliminate negation but I find that it's worth spending a few minutes to make your code less likely to cause confusion.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!