#在蓝懿学习iOS的日子#Day3

#在蓝懿学习iOS的日子#Day3,今天学习的内容不是很多,先是讲解昨天的作业,之后又学习了3个知识点:

一、打飞机游戏实现步骤:

1.搭建界面 把该关联的和代码进行关联

2.在点击按钮的时候 创建一个全局变量的子弹(uiimageView)

3.在viewDidLoad里面创建一个Timer 每隔一段时间去执行moveAction方法

例:[NSTimer scheduledTimerWithTimeInterval:0.1/2 target:self selector:@selector(moveAtion) userInfo:nil repeats:YES];

}

-(void)moveAtion{

    a +=1.2;

    bulletIV.center = CGPointMake(bulletIV.center.x, bulletIV.center.y-a);

}

4.在moveAction里面写改变子弹center的代码

例:bulletIV.center = CGPointMake(bulletIV.center.x+x, bulletIV.center.y);

5.在停止按钮中 让子弹等于空

例:bulletIV = nil;

6.在停止按钮中 子弹等于空之前 让子弹和三个目标判断是否交叉 如果打到目标得分1、2、3分 取出之前的得分 把本次得分加上 label显示

例:int fenShu = 0 ;

    if (CGRectIntersectsRect(bulletIV.frame, self.iv1.frame)) {

        fenShu=1;

        

    }else if (CGRectIntersectsRect(bulletIV.frame, self.iv2.frame)) {

        fenShu=2;

    }else if (CGRectIntersectsRect(bulletIV.frame, self.iv3.frame)) {

        fenShu=3;

    }else  {

        [bulletIV removeFromSuperview];

    }

7.在发射子弹的时候让子弹数量-1 如果子弹数量为0 则不能再发射

例:int d =self.ziDan.text.intValue;

    if (d>0) {

添加要运行的内容

}

二、break:跳出当前的循环;

continue:结束本次循环,进入下次循环;

return:结束当前的方法

三、讲了while语句

例:

 int totalCount = 100;

    int selledCount = 0;

    while (selledCount<totalCount) {

        NSLog(@"开始卖%d号票",selledCount+1);

        selledCount++;

        NSLog(@"卖了%d号票 还剩%d",selledCount,totalCount-selledCount);

四、学习了方法:

-(返回值类型)方法名称参数介绍:(参数类型)参数名称 and参数介绍:(参数类型)参数名称{

如果有返回值,要加return

}

 

调用方法

例:[self  方法名称]

1、无参数无返回值

2、无参数有返回值

3、有参数有返回值

4、有参数无返回值

例:3、有参数有返回值//调用方法

    int m =[self getNumberWithCoumt:10];

    NSLog(@"%d",m);

 

//方法

-(int)getNumberWithCoumt:(int)n{

    return arc4random()%n;

}

大家一起加油了,现在每一天都在加速了!

原文地址:https://www.cnblogs.com/odileye/p/4905446.html