0

これが起こっていることです....私は、チャレンジの終わりまでに、カスタマイズされた UIAlert がプレイヤーの勝敗を示すゲームを作成しています。問題は...そのメッセージが2回表示され、その理由がわかりません....

-(void)checkOnTests{

int p1sc;
int p1t;
int p2sc;
int p2t;

// IN BETWEEN, SCORES ARE CHECKED AND THEY ARE FINE

if (p1sc > p2sc) {
    NSLog(@"P1 Wins");
    winnerIndex = 1; // (INT)
    if (playerIndex == winnerIndex) {
        self.lbl_plyer_score.textColor = [UIColor greenColor]; //WINS
        self.lbl_opponent_score.textColor = [UIColor redColor]; //LOSES
        [self finishChallengeWherePlayer:YES amtOfGold:2];
    }else{
        self.lbl_plyer_score.textColor = [UIColor redColor];
        self.lbl_opponent_score.textColor = [UIColor greenColor];
        [self finishChallengeWherePlayer:NO amtOfGold:0];
    }
}else if (p1sc < p2sc){
    winnerIndex = 2;
    NSLog(@"P2 Wins");
    if (playerIndex == winnerIndex) {
        self.lbl_plyer_score.textColor = [UIColor greenColor];
        self.lbl_opponent_score.textColor = [UIColor redColor];
        [self finishChallengeWherePlayer:YES amtOfGold:2];

    }else{
        self.lbl_plyer_score.textColor = [UIColor redColor];
        self.lbl_opponent_score.textColor = [UIColor greenColor];
        [self finishChallengeWherePlayer:NO amtOfGold:0];

    }
}else if (p1sc == p2sc){
    NSLog(@"We got a tie match");
    winnerIndex = 3;
    if (((p1t == 0) && (p2t == 0)) || (p1t == p2t)) {
        [self finishChallengeWherePlayer:YES amtOfGold:1];
    }else if (p1t < p2t){
       [self finishChallengeWherePlayer:YES amtOfGold:2]; 
    }else if (p1t > p2t){
        [self finishChallengeWherePlayer:YES amtOfGold:1];
    }

  }
}

上記のコードは結果をチェックします。これまでのところ、すべてが正しいです。エラーなし。以下に、プレイヤーがチャレンジに勝ったか負けたかを伝えるメッセージを表示するコードを実装します。

-(void)finishChallengeWherePlayer:(BOOL)wins amtOfGold:(int)amt {
NSString *endMsg;
if (wins) {
    endMsg = [NSString stringWithFormat:@"Congrats! You win the challenge, gaining: %i gold", amt];
}else{
    endMsg = [NSString stringWithFormat:@"Oh No! You have lost the challenge. No gold for you"];
}
GameAlert *alert = [[GameAlert alloc] initWithTitle:@"Results" message:endMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show]; // this is my custom UIAlertView that is working fine throughout the game.
[self.delegate challengeFinished:amt testname:linker];

}

このビュー コントローラーがゲームの他の部分と異なる唯一のことは、以下のボックスにあります。

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
[self dismissViewControllerAnimated:YES completion:nil];
}

私の質問は...このViewControllerを閉じた後にのみ、チャレンジが終了したことをデリゲートに伝える必要がありますか、それともここで何か間違ったことをしていますか? アラートが 2 回表示され、私はばかのように感じます :(

4

0 に答える 0