游戏中心结果发布 [英] Game Center Outcome Posting

查看:78
本文介绍了游戏中心结果发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做基于回合的游戏...传递的唯一信息是玩家的得分以及是否已发送回合.

I’m doing a turn based game... the only information transferred is the score of the player and whether a turn has been sent.

下一位玩家转弯时.数据被存储到"scoreToBeat"中并且turnSent = 1.然后玩家轮到他们.之后游戏结束,因为turnSent = 1,因此被调用.我在 http://www.raywenderlich.com/5480/beginning-turn-based-gaming-with-ios-5-part-1 .

When the next player receives the turn. The data gets stored into "scoreToBeat" and turnSent=1. The player then takes their turn. Afterward the game ended gets called because turnSent=1. I used the turn based tutorial by Ray Wenderlich at http://www.raywenderlich.com/5480/beginning-turn-based-gaming-with-ios-5-part-1.

在他的情况下,比赛结束,并列平局.像这样...我似乎无法得到它来显示迷路的人.

In his case the game ends and is a tie. Like this... I can’t seem to get it to show the person that lost.

   for (GKTurnBasedParticipant *part in currentMatch.participants) {           
          part.matchOutcome = GKTurnBasedMatchOutcomeTied;
           }

我似乎无法理解失败的人总是赢球.这是我的最新尝试.在比赛中恰好有2位玩家参加了比赛.任何想法都将不胜感激.

I can’t seem to get it to show the person that lost it always shows a win. This is my latest attempt of many... Exactly 2 players in the match btw... Any ideas would be greatly appreciated.

    for (GKTurnBasedParticipant *part in currentMatch.participants) {           
           if(part==currentMatch.currentParticipant)
           {
               if(points>scoreToBeat)
               {
                   part.matchOutcome=GKTurnBasedMatchOutcomeWon;   
               }
               else {
                   part.matchOutcome=GKTurnBasedMatchOutcomeLost;
               }
           }
           else {
               if(points>scoreToBeat)
               {
                   part.matchOutcome=GKTurnBasedMatchOutcomeLost;   
               }
               else {
                   part.matchOutcome=GKTurnBasedMatchOutcomeWon;
               }

           }

推荐答案

这是我最新项目的节选,适用于2人游戏.当游戏决定要结束时,在sendTurn流程中调用它.我认为,这比上一个答案(第一个代码块)更正确,因为您必须在结束游戏之前为所有参与者设置matchOutcome.

This is an excerpt from my latest project, good for a 2 player game. It's called during the sendTurn process, when the game is decided to be ending. This is more correct than the previous answer (first code block), in my opinion, because you must set the matchOutcome for all participants before ending the game.

如果您有2位以上的玩家,那么您必须遍历所有参与者并相应地设置matchOutcome.

If you had more than 2 players, then you'd have to loop through all participants and set the matchOutcome accordingly.

   GKTurnBasedParticipant *curr = currentMatch.currentParticipant;
    NSUInteger currentIndex = [currentMatch.participants indexOfObject:currentMatch.currentParticipant];
    NSUInteger nextIndex = (currentIndex + 1) % [currentMatch.participants count];
    GKTurnBasedParticipant *next = [currentMatch.participants objectAtIndex:nextIndex];

    if (currScore < otherScore)
    {
        // Curr player lost
        curr.matchOutcome = GKTurnBasedMatchOutcomeLost;
        next.matchOutcome = GKTurnBasedMatchOutcomeWon;
    }
    else if (currScore == otherScore)
    {
        // Tied
        curr.matchOutcome = GKTurnBasedMatchOutcomeTied;
        next.matchOutcome = GKTurnBasedMatchOutcomeTied;
    }
    else 
    {
        // Won
        curr.matchOutcome = GKTurnBasedMatchOutcomeWon;
        next.matchOutcome = GKTurnBasedMatchOutcomeLost;
    }

请注意,根据设计,您将在两种设备上看到成功".

Note that you will see "Won" on both devices by design.

一个人说我",下面带有赢",另一个人说(获胜者姓名)",下面带有赢".

One will say "Me" with "Won" underneath, and the other will say "(Winners Name)" with "Won" underneath.

这篇关于游戏中心结果发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆