24点小游戏ios开发(一)

cocoa社区有很多iOS的小游戏源码(没有24点的大概是因为它落后了...?),我下载了很多来作为参考。游戏源码已传至github:https://github.com/DF-L/24

先是最终的界面:


先是一个计时器的代码,参考了一个touchme的源码。实现按下开始按钮之后开始计时的功能,并记录每次的计时到总时间

.h文件中:
NSTimer *timer;
-(void)subtracTime;
.m文件中:
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f
                                             target:self
                                           selector:@selector(subtracTime)
                                           userInfo:nil
                                            repeats:YES];//计时器
-(void)subtracTime
{//计时器
    if(count!=0){
        second+=1;
        lable18++;
    }
    timerLabel.text = [NSString stringWithFormat:@"Time:%d",second];
    if(second == 30)
    {
        [timer invalidate];
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Times Out"
                                                                       message:[NSString stringWithFormat:@"Score:%d",score] preferredStyle:UIAlertControllerStyleAlert];
        
        scoreLabel.text = [NSString stringWithFormat:@"Score:%d",score];
        
        UIAlertAction *againAction = [UIAlertAction actionWithTitle:@"Again"
                                                              style:UIAlertActionStyleCancel
                                                            handler:nil];
        [alert addAction:againAction];
        [self presentViewController:alert animated:YES completion:nil];
        [self setGame];
    }
}

timerLabel.text = [NSString stringWithFormat:@"倒计时:%d",second];
lable10.text =[NSString stringWithFormat:@"总时间:%d",lable18];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值