您当前的位置: 首页 >  游戏

(NO.00001)iOS游戏SpeedBoy Lite成形记(二十)

发布时间:2015-10-24 20:27:33 ,浏览量:0

下面修改最为关键的matchRun方法里的代码:

CCActionCallBlock *blk = [CCActionCallBlock actionWithBlock:^{
            _finishedCount++;
            [player endMatch];
            [player stopAction:repeatJump];
            [player stopAction:repeatSkew];
            [self removeChild:player.streak]; if (_finishedCount == 1) {
                _bestElapsedTime = player.elapsedTime;
                GameState *gameState = [GameState sharedInstance]; NSInteger money = gameState.money; if (player.playerNumber == _betPlayer) {
                    gameState.totalMoney += money;
                    [_interface updateStatusLabel:[NSString stringWithFormat:@"资金 +%d",money] withColor:[CCColor greenColor]];
                }else{
                    gameState.totalMoney -= money;
                    [_interface updateStatusLabel:[NSString stringWithFormat:@"资金 -%d",money] withColor:[CCColor redColor]];
                }
            }

            CCLabelTTF* label = (CCLabelTTF*)_labelArray[player.playerNumber-1]; NSTimeInterval intervalOffset = player.elapsedTime - _bestElapsedTime; if (intervalOffset > 0) {
                label.string = [NSString stringWithFormat:@"NO.%d +%.4f s",_finishedCount,intervalOffset];
            }else{
                label.string = [NSString stringWithFormat:@"NO.%d %.4f s",_finishedCount,player.elapsedTime];
                label.color = [CCColor greenColor];
            }

            label.visible = YES; if (_finishedCount == PlayerCount) {
                _finishedCount = 0;
                _matching = NO;

                _betPlayer = 0;
                _isBeted = NO;

                GameState *gameState = [GameState sharedInstance];
                gameState.money = 0;

                [self updateGambleState];
            }
        }];

主要变化都在block回调里,所以只贴出其中的内容. 主要逻辑是在比赛完毕后更新游戏状态.如果玩家赌对了则资金总数加上押注的数目,否则减去该数目.

为了区分出赢钱和输钱,我们在GameInterface类中添加新实例方法,首先改动接口声明:

-(void)updateStatusLabel:(NSString *)msg withColor:(CCColor*)color;

然后再到GameInterface.m中实现该方法:

-(void)updateStatusLabel:(NSString *)msg withColor:(CCColor*)color{
    CCColor *orgColor = _statusLabel.color;
    CCActionTintTo  *tintAction = [CCActionTintTo actionWithDuration:1 color:color];
    CCActionCallBlock *block = [CCActionCallBlock actionWithBlock:^{
        _statusLabel.color = orgColor;
    }];
    CCActionDelay *delayAction = [CCActionDelay actionWithDuration:4];
    CCActionSequence *seqAction = [CCActionSequence actions:tintAction,delayAction,block,nil];
    [self updateStatusLabel:msg];
    [_statusLabel runAction:seqAction];
}

大体上是根据color参数动态改变状态标签的颜色,最后复原原来的颜色.

这一阶段新增的游戏逻辑完成的差不多了,下面就是实现GameOver的情形了.

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108697博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0474s