Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – using the text field


What's the purpose of the highscores table if you can't beat any of the highscores? Let's change that and replace the test data with the actual highscores. To do this, we're going to need the player to enter their name when they beat a highscore:

  1. Create a new Objective-C class in the Common group. Name the class HighscoreManager and make it a subclass of NSObject.

  2. Open the HighscoreManager.h file and replace its contents with the following code:

    #import "GameStats.h"
    
    #define kMaxHighscores 5
    
    @interface HighscoreManager: NSObject
    
    -(NSArray *)getHighScores;
    
    -(BOOL)isHighscore:(int)score;
    
    -(void)addHighScore:(GameStats *)newHighscore;
    
    +(HighscoreManager *)sharedHighscoreManager;
    
    @end
  3. Then, open the HighscoreManager.h file and replace its contents with the following code:

    #import "HighscoreManager.h"
    
    @implementation HighscoreManager
    {
        NSMutableArray *_highScores;
    }
    
    -(instancetype)init
    {
        if (self = [super init])
        {
            _highScores = [NSMutableArray...