2014-12-03 124 views
0

编辑:感谢您的帮助,我正在解决我的问题。我已修复缺少的“@end错误”,并且只剩下一个“Expected identifier or”( “”错误预期标识符或“(”错误

这是代码,错误指出:

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] \ 
compare:v options:NSNumericSearch] == NSOrderedAscending) 


#import "WViewController.h" 
#import <SkillzSDK-iOS/Skillz.h> 

@interface WViewController() 

@end 

@implementation WViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    //create backdrop image 
    NSMutableString *imgFile = [[NSMutableString alloc] init]; 
    if (![globalBackgroundImage isEqualToString:@""]) [imgFile setString:globalBackgroundImage]; //falls back to first image setting for all devices; 
    if ((IS_WIDESCREEN_PHONE)&&(![widescreenBackgroundImage isEqualToString:@""])) [imgFile setString:widescreenBackgroundImage]; //you can specify a different image for 
    if ((IS_IPAD)&&(![iPadBackgroundImage isEqualToString:@""])) [imgFile setString:iPadBackgroundImage]; //widescreen phones & for iPad 
    if (![imgFile isEqualToString:@""]) { 

     UIImage *img = [[UIImage imageNamed:imgFile] retain]; 

     CGSize imgSz = [img size]; 
     CGSize screenSz = [[UIScreen mainScreen] bounds].size; 
     float imgWH = imgSz.width/imgSz.height; 
     float screenWH = screenSz.width/screenSz.height; 

     CGRect backdropFrame; 
     if (imgWH>=screenWH) backdropFrame = CGRectMake((screenSz.width/2)-((screenSz.height*imgWH)/2), 0, screenSz.height*imgWH, screenSz.height); //image wider than screen 
     else backdropFrame = CGRectMake(0, ((screenSz.height/2)-((screenSz.width/imgWH)/2)), screenSz.width, screenSz.width/imgWH); 

     UIImageView *backdropImageView = [[UIImageView alloc] initWithFrame:backdropFrame]; 
     [backdropImageView setImage:img]; 
     [backdropImageView setAlpha:backgroundImageOpacity]; 
     [self.view addSubview:backdropImageView]; 
    } 

    [self.view setBackgroundColor:globalBackgroundColor]; 


    //init GameCenter 
    [[GameCenterManager sharedManager] setupManager]; 
    [[GameCenterManager sharedManager] setDelegate:self]; 

    //initialize the view for when the player is in the game 
    gameView = [[WgameView alloc] initWithFrame:[[UIScreen mainScreen] bounds] fromViewController:self]; 
    [gameView setHidden:YES]; 
    [self.view addSubview:gameView]; 

    //initialize the view for then the player is on the home screen 
    homeView = [[WhomeView alloc] initWithFrame:[[UIScreen mainScreen] bounds] fromViewController:self]; 
    [homeView setHidden:YES]; 
    [self.view addSubview:homeView]; 

} 

- (void) viewDidAppear:(BOOL)animated { 

    //go to home screen right away 
    [self goHome]; 

    //show a RevMob fullscreen ad if we're supposed to 
    if (revMobActive) { 
     if (showRevMobFullscreenOnLaunch) { 
      [[RevMobAds session] showFullscreen]; 
     } 
    } 
    //show a Chartboost ad if we're supposed to 
    if (chartboostActive) { 
     if (showChartboostOnLaunch) { 
      [[Chartboost sharedChartboost] showInterstitial:CBLocationHomeScreen]; 
     } 
    } 

} 


#pragma mark game flow 


-(void) multiplayerButtonPressed:(id)sender 
{ 
    NSLog(@"Multiplayer button pressed, launching Skillz!"); 
    // Launching Skillz in landscape mode 
    [[Skillz skillzInstance] launchSkillzForOrientation:SkillzLandscape 
            launchHasCompleted:^{ 
       // This code is called after the Skillz UI launches. 
       NSLog(@"Skillz just launched."); 
      } tournamentWillBegin:^(NSDictionary *gameRules) { 
       // This code is called when a player starts a game in the Skillz portal. 
       NSLog(@"Tournament with rules: %@", gameRules); 
       NSLog(@"Now starting a game…"); 

             // INCLUDE CODE HERE TO START YOUR GAME 
             // ….. 
             // ….. 
             // ….. 
             // END OF CODE TO START GAME 


            } skillzWillExit:^{ 
             // This code is called when exiting the Skillz portal 
             //back to the normal game. 
             NSLog(@"Skillz exited."); 
            }]; 

} 

- (void) startGame:(UIButton*)sender { 

    //hide RevMob banner ad if we're supposed to 
    if (revMobActive) { 
     if (showRevMobBannerOnHomeScreen) { 
      [[RevMobAds session] hideBanner]; 
     } 
    } 

    //starts game in the mode corresponding to which button was tapped 
    [[WGameModeEngine sharedInstance] setCurrentGameMode:sender.titleLabel.text]; 
    [gameView startGame]; 
    [homeView setHidden:YES]; 
    [gameView setHidden:NO]; 

    //init timer if timed game 
    if ([[WGameModeEngine sharedInstance] isTimedGame]) { 
     timedGameTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(decrementTime) userInfo:nil repeats:YES] retain]; 
    } 

    //notify game engine to play sound if configured 
    [[WGameModeEngine sharedInstance] soundEventDidHappen:@"BeginGame"]; 

} 



- (void) goHomeButtonPressed { 
    [self stopGame]; 
    [self goHome]; 
} 

- (void) stopGame { 

    //stop timer if this was a timed game 
    if (timedGameTimer) { 
     [timedGameTimer invalidate]; 
     [timedGameTimer release]; 
     timedGameTimer=nil; 
    } 
} 


- (void) goHome { 
    [gameView setHidden:YES]; 
    [homeView setHidden:NO]; 

    //show a RevMob banner ad if we're supposed to 
    if (revMobActive) { 
     if (showRevMobBannerOnHomeScreen) { 
      [[RevMobAds session] showBanner]; 
     } 
    } 
} 

- (void) decrementTime { 
    [[WGameModeEngine sharedInstance] timeDecreased]; //report to our game model that time has decreased 
    if ([[WGameModeEngine sharedInstance] timeLeft]<=0) { //if 0 seconds left, 
     [self timedGameEnded]; //game has ended 
    } 
    if (([[WGameModeEngine sharedInstance] timeLeft]<6)&&([[WGameModeEngine sharedInstance] timeLeft]>0)) { 
     //notify game engine to play sound if configured 
     [[WGameModeEngine sharedInstance] soundEventDidHappen:@"FiveSecondCountdown"]; 
    } 
    [gameView updateLabels]; //update gameView's score and time labels 
} 


- (void) timedGameEnded { 
    //game over! 
    [self stopGame]; 

    //notify game engine to play sound if configured 
    [[WGameModeEngine sharedInstance] soundEventDidHappen:@"GameOver"]; 

    //show an alert with score and list of words found (if you want, you can add a whole separate screen for this instead of simple alert!) 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Game Over" message:[NSString stringWithFormat:@"You scored %d points!\n\nWords found:\n%@",[[WGameModeEngine sharedInstance] getScore],[[[WGameModeEngine sharedInstance] getWordsFound] componentsJoinedByString:@" "]] delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert setDelegate:self]; 
    [alert show]; 
    [alert release]; 

    //report score to GameCenter 
    int sc = [[WGameModeEngine sharedInstance] getScore]; 
    if (sc>0) [self reportScore:sc forCategory:[[[[WGameModeEngine sharedInstance] getCurrentGameMode] componentsSeparatedByString:@" "] componentsJoinedByString:@"_"]]; 

    [@"com.bundle.appname" stringByAppendingString:[[[[[WGameModeEngine sharedInstance] getCurrentGameMode] lowercaseString] componentsSeparatedByString:@" "] componentsJoinedByString:@""]]; 
} 


- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 
    //share latest score on Facebook if we're supposed to 
    if (FacebookShareEnabled) {[self facebookShare];} 

    //go to home screen 
    [self goHome]; 

    //show a RevMob fullscreen ad if we're supposed to 
    if (revMobActive) { 
     if (showRevMobFullscreenWhenGameOver) { 
      [[RevMobAds session] showFullscreen]; 
     } 
    } 
    //show a Chartboost ad if we're supposed to 
    if (chartboostActive) { 
     if (showChartboostWhenGameOver) { 
      [[Chartboost sharedChartboost] showInterstitial:CBLocationHomeScreen]; 
     } 
    } 
} 


#pragma mark GameCenter 



- (void)gameCenterManager:(GameCenterManager *)manager authenticateUser:(UIViewController *)gameCenterLoginController { 
    if (revMobActive) { 
     if (showRevMobBannerOnHomeScreen) { 
      [[RevMobAds session] hideBanner]; 
     } 
    } 

    [self presentViewController:gameCenterLoginController animated:YES completion:^(void) 
    {if (revMobActive) { 
     if (showRevMobBannerOnHomeScreen) { 
      [[RevMobAds session] showBanner]; 
     }}}]; 
} 



if (isGameOver) {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<ERROR IS HERE>>>>>>>>>>>>>>> 
    if ([[Skillz skillzInstance] tournamentIsInProgress]) { 
     // The game ended and it was in a Skillz tournament, 
     // so report the score and go back to Skillz. 
     [[Skillz skillzInstance] completeTurnWithGameData:gameData 
               playerScore:playerScore 
            playerCurrentTotalScore:playerCurrentTotalScore 
           opponentCurrentTotalScore:opponentCurrentTotalScore 
              roundOutcome:turnOutcome 
              matchOutcome:matchOutcome 
              withCompletion:^{ 
               // Code in this block is called when exiting to Skillz 
               // and reporting the score. 
               NSLog(@"Reporting score to Skillz…"); 
              }]; 
    } else { 
     // Otherwise single player game, so take the normal action 
    } 
} 

- (void) reportScore: (int64_t) score forCategory: (NSString*) category 

原题:

我真的很新的编码,并希望有人能帮助我什么,我敢肯定是一个非常简单的问题,我看了很多关于这个错误的其他答案,但他们没有似乎适用于我的情况。

以下代码是我正在使用Xcode的游戏应用程序的一部分,尝试将其与名为SKILLZ的第三方系统集成。我没有编写任何代码,并且在继续进行集成时试图理解它。

我已经在那里我得到了错误代码中指出:

#import "WAppDelegate.h" 
    #import "WViewController.h" 
    #import <SkillzSDK-iOS/Skillz.h> 

    @implementation WAppDelegate 

    - (void)dealloc 
    { 
     [_window release]; 
     [_viewController release]; 
     [super dealloc]; 
    } 

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

    { 
     //initialize language engine 
     [WLanguageEngine sharedInstance]; 

     //initialize game mode engine 
     [WGameModeEngine sharedInstance]; 

     //initialize RevMob 
     if (revMobActive) { 
      [RevMobAds startSessionWithAppID:RevMobAppID]; 
     } 

     if (revMobActive&&revMobTestingMode) { 
      [RevMobAds session].testingMode = RevMobAdsTestingModeWithAds; 
      // or 
      //[RevMobAds session].testingMode = RevMobAdsTestingModeWithoutAds; 
     } 

     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
     // Override point for customization after application launch. 
     self.viewController = [[[WViewController alloc] initWithNibName:@"WViewController" bundle:nil] autorelease]; 
     self.window.rootViewController = self.viewController; 
     [self.window makeKeyAndVisible]; 
     return YES; 
    } 


    {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<**<<EXPECTED IDENTIFIER OR "(">> ERROR OCCURS HERE** 
     // INITIALIZE SKILLZ HERE 
     // 940 is the game ID that was given to us by the Skillz Developer Portal. 
     // SkillzSandbox specifies that we will use the sandbox server since we 
     // are still developing the game. 
     // SkillzProduction specifies that we will use the production server since 
     // the game is ready for release to the AppStore 
     [[Skillz skillzInstance] skillzInitForGameId:@"940" 
             environment:SkillzSandbox]; 


I am getting a second occurrence of this error in a different part of the app code, but am hoping that if I can sort this one out that it will help me to understand the other. 

Hoping that this is not off-topic or too specific, and that someone might be able to help. 

Cheers 
Jen 

回答

1

{< < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < <>错误发生时这里 //初始化SKILLZ这里 // 940是由的skillz开发者门户网站给我们的游戏ID。 // SkillzSandbox指定我们将使用沙箱服务器,因为我们的 //仍在开发游戏。 // SkillzProduction指定我们将使用生产服务器,因为 //游戏准备发布到AppStore [[Skillz skillzInstance] skillzInitForGameId:@“940” environment:SkillzSandbox];

return YES; 

}

此块是- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 外面也许你忘了申报或添加了外来}某处

+0

感谢@Antzi。我把这个块移到我认为合适的地方,并解决了这个问题。除了现在我在代码的末尾发现了一个“Missing @end”错误,那里显然有一个“@end”。当我把另一个插入时,它给了我另一个错误,说“@end必须出现在和ObcjectiveC上下文中”。有任何想法吗? – 2014-12-03 07:27:18

+0

好吧,我正在关闭它。我已经修复了缺失的结束错误,并且剩下一个预期标识符或“(”错误。 – 2014-12-03 07:51:10

+0

@JenCooper缩进代码(选择全部文本,然后菜单编辑器=>结构=>缩进)。您应该能够看到这个问题很容易(可能是一个额外的'}') – Antzi 2014-12-03 10:40:38