All Data Structures Files Functions Variables Enumerations Enumerator Properties Defines
/Projects/Cogito/src/Layers/GameOverLayer.m
Go to the documentation of this file.
00001 //
00002 //  GameOverLayer.m
00003 //  Author: Thomas Taylor
00004 //
00005 //  The game over layer
00006 //
00007 //  16/12/2011: Created class
00008 //
00009 
00010 
00011 #import "GameOverLayer.h"
00012 
00013 @interface GameOverLayer() 
00014 
00015 -(void)onMenuButtonPressed;
00016 
00017 @end
00018 
00019 @implementation GameOverLayer
00020 
00021 #pragma mark -
00022 #pragma mark Initialisation
00023 
00028 -(id)init
00029 {
00030  self = [super init];
00031     
00032  if (self != nil) 
00033  {
00034   CGSize winSize = [CCDirector sharedDirector].winSize;
00035   
00036         // add the bacground image
00037         CCSprite *background = [CCSprite spriteWithFile:@"GameOverBackground.png"];
00038   [background setPosition:ccp(winSize.width/2, winSize.height/2)];
00039   [self addChild:background];
00040   
00041   // Add the text for level complete.
00042         AgentStats* as = [AgentStats sharedAgentStats];
00043         GameManager* gm = [GameManager sharedGameManager];
00044         LemmingManager* lm = [LemmingManager sharedLemmingManager];
00045         NSString *statString = [NSString stringWithFormat:@"> time: %@  \n> saved: %i  killed: %i \n> avg. episode time (secs): \n     before: %i  after: %i \n> avg. actions per episode: \n     before: %i  after: %i", [gm getGameTimeInMins], [lm lemmingsSaved], [lm lemmingsKilled], [as averageTimeLearning], [as averageTimeNonLearning], [as averageActionsLearning], [as averageActionsNonLearning]];
00046   CCLabelBMFont *statTextLeft = [CCLabelBMFont labelWithString:statString fntFile:kFilenameDefFontLarge];
00047   [statTextLeft setAnchorPoint:ccp(0, 1)];
00048         [statTextLeft setPosition:ccp(41, winSize.height-100)];
00049   [self addChild:statTextLeft];
00050         
00051         // add the game rating image
00052         CCSprite *gameRating;
00053         
00054         switch ([[LemmingManager sharedLemmingManager] calculateGameRating]) 
00055         {
00056             case kRatingA:
00057                 gameRating = [CCSprite spriteWithFile:@"GameRating_A.png"];
00058                 break;
00059             
00060             case kRatingB:
00061                 gameRating = [CCSprite spriteWithFile:@"GameRating_B.png"];
00062                 break;
00063                 
00064             case kRatingC:
00065                 gameRating = [CCSprite spriteWithFile:@"GameRating_C.png"];
00066                 break;
00067                 
00068             case kRatingD:
00069                 gameRating = [CCSprite spriteWithFile:@"GameRating_D.png"];
00070                 break;
00071                 
00072             case kRatingF:
00073                 gameRating = [CCSprite spriteWithFile:@"GameRating_F.png"];
00074                 break;
00075                 
00076             default:
00077                 CCLOG(@"Unknown rating: %@", [[LemmingManager sharedLemmingManager] calculateGameRating]);
00078                 break;
00079         }
00080   
00081         [gameRating setPosition:ccp(winSize.width*0.75f, winSize.height*0.45)];
00082   [self addChild:gameRating];
00083         
00084         //create and position the screen buttons
00085         CCMenuItemImage *menuButton = [CCMenuItemImage itemFromNormalImage:@"Menu.png" selectedImage:@"Menu_down.png" disabledImage:nil target:self selector:@selector(onMenuButtonPressed)];
00086         buttons = [CCMenu menuWithItems:menuButton, nil];
00087         [buttons alignItemsVerticallyWithPadding:winSize.height * 0.059f];
00088         [buttons setPosition: ccp(winSize.width * 0.2, winSize.height * 0.1)];
00089         
00090         // add the menu
00091         [self addChild:buttons];
00092  }
00093     
00094  return self;
00095 }
00096 
00100 -(void)onMenuButtonPressed
00101 {
00102  [[GameManager sharedGameManager] runSceneWithID:kMainMenuScene];
00103 }
00104 
00105 @end