From b090d12d637e5cfbf0ac6955fa6c8d401de657b5 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Fri, 9 Sep 2011 19:57:25 -0400 Subject: Added play again button to game over screen Closes #218 --- Classes/GameOverScene.h | 4 +++- Classes/GameOverScene.m | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) (limited to 'Classes') diff --git a/Classes/GameOverScene.h b/Classes/GameOverScene.h index a91286e..f596211 100755 --- a/Classes/GameOverScene.h +++ b/Classes/GameOverScene.h @@ -17,13 +17,15 @@ UISwitch* submitSwitch; UIActivityIndicatorView* activityIndicator; UIButton* backButton; + UIButton* playButton; int score; NSString* gameMode; + BOOL playAgain; } + (GameOverScene*)sceneWithScore:(int)score gameMode:(NSString*)gameMode; - (id)initWithScore:(int)score gameMode:(NSString*)gameMode; -- (void)newgame; +- (void)newgame:(id)sender; - (void)submitScore; - (void)exit; diff --git a/Classes/GameOverScene.m b/Classes/GameOverScene.m index cfbb446..a56aeac 100755 --- a/Classes/GameOverScene.m +++ b/Classes/GameOverScene.m @@ -11,6 +11,8 @@ #import #import "cocoslive.h" #import "MainMenuLayer.h" +#import "ClassicGameMode.h" +#import "JumpGameMode.h" @implementation GameOverScene @@ -64,11 +66,19 @@ activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(480-20-10, 320-20-10, 20, 20)]; [movingLayer addSubview:activityIndicator]; + + playButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + [playButton setFrame:CGRectMake(480/3-105/2, 320-60-15, 105, 31)]; + [playButton setTitle:@"Play Again" forState:UIControlStateNormal]; + [playButton addTarget:self action:@selector(newgame:) forControlEvents:UIControlEventTouchUpInside]; + [playButton.titleLabel setFont:[UIFont systemFontOfSize:16.0]]; + [playButton.titleLabel setTextColor:[UIColor blackColor]]; + [movingLayer addSubview:playButton]; backButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; - [backButton setFrame:CGRectMake(240-154/2, 320-60-15, 154, 31)]; + [backButton setFrame:CGRectMake(480/3*2-154/2, 320-60-15, 154, 31)]; [backButton setTitle:@"Back to Main Menu" forState:UIControlStateNormal]; - [backButton addTarget:self action:@selector(newgame) forControlEvents:UIControlEventTouchUpInside]; + [backButton addTarget:self action:@selector(newgame:) forControlEvents:UIControlEventTouchUpInside]; [backButton.titleLabel setFont:[UIFont systemFontOfSize:16.0]]; [backButton.titleLabel setTextColor:[UIColor blackColor]]; [movingLayer addSubview:backButton]; @@ -83,8 +93,12 @@ movingLayer.center = CGPointMake(240, 160-position.y); } -- (void)newgame +- (void)newgame:(id)sender { + // Play again if the user pressed the play again button + playAgain = (sender == playButton); + + playButton.enabled = NO; backButton.enabled = NO; textField.enabled = NO; submitSwitch.enabled = NO; @@ -198,6 +212,9 @@ [activityIndicator release]; activityIndicator = nil; + [playButton removeFromSuperview]; + playButton = nil; + [backButton removeFromSuperview]; backButton = nil; @@ -205,7 +222,18 @@ [movingLayer release]; movingLayer = nil; - [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; + if (playAgain) + { + if ([gameMode isEqual:@"Collect"]) + { + [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[ClassicGameMode scene] withColor:ccc3(0, 0, 0)]]; + } else if ([gameMode isEqual:@"Jump"]) + { + [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[JumpGameMode scene] withColor:ccc3(0, 0, 0)]]; + } + } else { + [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; + } } @end -- cgit 1.4.1