0

我终于让我的排行榜出现了。现在我只需要实现我的分数就会弹出。
我的分数保存NSStringNSUserDefaults名称下score

这是一些代码:

Game_CenterViewController.h

#import <UIKit/UIKit.h>
#import <GameKit/GameKit.h>
#import "GameCenterManager.h"

@class GameCenterManager;

@interface Game_CenterViewController : UIViewController <UIActionSheetDelegate, GKLeaderboardViewControllerDelegate, GKAchievementViewControllerDelegate, GameCenterManagerDelegate> {
    GameCenterManager *gameCenterManager;
    int64_t  currentScore;
    NSString *currentLeaderBoard;
}

@property (nonatomic, retain) GameCenterManager *gameCenterManager;
@property (nonatomic, assign) int64_t currentScore;
@property (nonatomic, retain) NSString* currentLeaderBoard;
@end

Game_CenterViewController.m

#import "Game_CenterViewController.h"
#import "AppSpecificValues.h"
#import "GameCenterManager.h"

@implementation Game_CenterViewController
@synthesize gameCenterManager;
@synthesize currentScore;
@synthesize currentLeaderBoard;

- (void)dealloc {
    [gameCenterManager release];
    [currentLeaderBoard release];
    [currentScoreLabel release];
    [super dealloc];
}

#pragma mark - View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
    self.currentLeaderBoard = thescore101;
    self.currentScore = score    
    if ([GameCenterManager isGameCenterAvailable]) {
        self.gameCenterManager = [[[GameCenterManager alloc] init] autorelease];
        [self.gameCenterManager setDelegate:self];
        [self.gameCenterManager authenticateLocalUser];
    } else {
        // The current device does not support Game Center.
    }
}

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController {
    [self dismissModalViewControllerAnimated: YES];
    [viewController release];
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.gameCenterManager = nil;
    self.currentLeaderBoard = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

目前的分数是我试图输入的地方NSString

4

1 回答 1

0

已编辑:我认为将 int 用于 currentScore 会更好。

这是你想要的?

- (void)submitMyScore:(int64_t)score
{

    GKScore *myScoreValue = [[[GKScore alloc] initWithCategory:@"yourCat"] autorelease];
    myScoreValue.value = (int)score;

    [myScoreValue reportScoreWithCompletionHandler:^(NSError *error){
        if(error != nil){
            NSLog(@"Score Submission Failed");
        } else {
            NSLog(@"Score Submitted: %d",(int)score);
        }

    }];
}

所以你应该添加一个IBAction

- (IBAction)buttonPressed
{
    [self submitMyScore:currentScore];
}

有了这个并将发送我的分数按钮连接到这个 IBAction,您将提交您的分数。

我希望这对你有用。

于 2012-07-21T15:10:26.013 回答