PDA

View Full Version : button, start a new game




cobolguy
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.



chown33
Sep 30, 2010, 08:52 PM
Post code.

cobolguy
Sep 30, 2010, 09:07 PM
#import "stopgame.h"


@implementation stopgame
-(IBAction)stopgame:(id)sender
{
exit(0);

}
@end

Catfish_Man
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).

robvas
Oct 2, 2010, 06:40 PM
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
}

cobolguy
Oct 4, 2010, 04:05 PM
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