2014-12-03 118 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