View Full Version : button, start a new game
Sep 30, 2010, 08:31 PM
Newbie, just learning xcode, cocoa (25 years Cobol programming).
Wrote a small game, cannot figure out how, when game is won, to click a button and start a new game?
Also, I have a 'Quit' button that goes to code that does "exit(0)" - Is this the easiest way to exit (besides red button at top)?
Thanks, I know the answer must be something very basic.
Sep 30, 2010, 08:52 PM
Sep 30, 2010, 09:07 PM
Oct 1, 2010, 12:44 AM
[NSApp terminate:nil]; is a slightly less forceful way to say quit. As for a new game... that's not really a Cocoa thing. You just need to set all your game's data structures back to their initial state (perhaps by instantiating new ones).
Oct 2, 2010, 06:40 PM
What's your game control loop look like?
It should be something like
while (game_over ==0)
// game is over now
// get input and either quit, or start back over at init_game
Oct 4, 2010, 04:05 PM
Thanks to everyone who replied to this question;
I found the following website:
and used the code in it and my 'Play Again' button works.
Also, I changed the 'Quit' key as recommended.
The 'back and forth' concept, still working on it; will post the code - (question: how does one get the code in the correct format for this site, the rectangle thing?
Thanks for helping