Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cobolguy

macrumors newbie
Original poster
Sep 30, 2010
4
0
Penna
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.
 
code for 'quit' button

Code:
#import "stopgame.h"


@implementation stopgame
-(IBAction)stopgame:(id)sender
{
	 exit(0);
	
}
@end
 
[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).
 
What's your game control loop look like?

It should be something like

main()
{
loadgraphics()
init_game()
startgame()
while (game_over ==0)
{
drawgraphics()
movecharacters()
getinput()
etc()
}
// game is over now

// get input and either quit, or start back over at init_game
}
 
'Play Again' code

Thanks to everyone who replied to this question;

I found the following website:
http://13bold.com/tutorials/relaunching-your-application/

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.