您的位置:首页 > 移动开发 > IOS开发

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

2015-10-24 20:27 441 查看
下面修改最为关键的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的情形了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 游戏