zoukankan      html  css  js  c++  java
  • 贪吃蛇

    //

    //  ViewController.m

    //  119textSix

    //

    //  Created by FuHeXiang on 16/1/19.

    //  Copyright (c) 2016年 XinZhongZhi. All rights reserved.

    //

    #import "ViewController.h"

    #import "UIView+Ext.h"

    NSInteger const Ktag=100;

    //宏定义 长 宽

    #define DEF_SCR_WIDTH [UIScreen maiScreen].bound.size.width

    #define DEF_SCR_HEIGHT [UIScreen maiScreen].bound.size.height

    @interface ViewController ()

    {

        UIView * _redView;

    }

    @property (weak, nonatomic) IBOutlet UILabel *label;

    @property (weak, nonatomic) IBOutlet UIButton *ladel;

    @end

    @implementation ViewController

    - (IBAction)botton:(id)sender {

        //这个实现的是红色方块向斜下方慢慢移动

        self. label .text =@"已经打开";

                    [UIView animateWithDuration:2 delay:0 usingSpringWithDamping:5 initialSpringVelocity:20 options:UIViewAnimationOptionCurveEaseInOut animations:^{

                        CGRect frame=_redView.frame;

                        frame.origin.y +=10;

                        frame.origin.x +=10;

                        _redView .frame =frame;

                        _redView .tag +=10;

                        _redView .bottom;

                    } completion:nil];

        

        

        //功能分别是 是持续时间  延迟  弹性  速度

        [UIView animateWithDuration:2 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:20 options:UIViewAnimationOptionCurveEaseInOut animations:^{

            _redView .frame = CGRectMake(100, 100, 100, 100);

        } completion:^(BOOL finished) {

            if (finished) {

                [UIView animateWithDuration:3 delay:0 usingSpringWithDamping:5 initialSpringVelocity:10 options:UIViewAnimationOptionCurveEaseOut animations:^{

                    _redView .frame=CGRectMake(100, 100, 100, 100);

                    _redView .backgroundColor =[UIColor yellowColor ];

                    _redView .alpha=0.2;

                } completion:nil];

            }

            

        }];

    }

    int i=0;

    -(void)text:(NSTimer *)timer{

        //1 获取传递的时间

        //timer.userinfo

        // 2 可以让时间停止

        i++;

        if (i%5==0) {

            [timer invalidate];

        }

        NSLog(@"%d",i);

    }

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        //下面创建一个方块

        _redView=[[UIView alloc ] init ];

        _redView .frame = CGRectMake(0, 0, 100, 100);

        [self.view addSubview:_redView];

        _redView .backgroundColor = [UIColor redColor];

        

        //创建第二个方块

        UIView * view = [[UIView alloc ]init ];

        view .frame=CGRectMake(30, 30, 100, 100);

        [self .view addSubview:view];

        view.backgroundColor =[UIColor greenColor];

        

        //创建第三个方块

        UIView * view2 = [[UIView alloc] init];

        view2 .frame =CGRectMake(60, 60, 100, 100);

        [self .view addSubview:view2];

        view2.backgroundColor = [UIColor blueColor];

        

        //下面设置新建小方块来循环的贪吃蛇

        //UIView * view3= [[UIView alloc ] init];

       // view3 .frame =CGRectMake(150,200, 20, 20);

       //把头一个小方块变成其他颜色

           for (int i=0; i<10; i++) {

            UIView * view3=[[UIView alloc] initWithFrame:CGRectMake(i*10+100, 0+200, 20, 20)];

              [self .view addSubview:view3];

             view3 .backgroundColor =[UIColor blackColor];

            view3 .tag = i +100;

            

        }

        UIView *view3=[self .view viewWithTag:Ktag+9];

        view3 .backgroundColor =[ UIColor  yellowColor];

        

        _redView =[[UIView alloc] initWithFrame: CGRectMake((DEF_SCR_WIDTH/2-100), DEF_SCR_HEIGHT/2-50, 200, 100)];

        _redView .backgroundColor =[UIColor redColor ];

        

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

       

    }

    @end

  • 相关阅读:
    【转】滑动窗口与拥塞控制
    LeetCode 34 :Find First and Last Position of Element in Sorted Array
    主要电商模式介绍
    使用springboot创建邮件服务器
    解决Windows下端口占用问题
    [leetcode]给定二维平面上的n个点,找出位于同一直线上的点的最大数目
    获得超类的泛型参数在子类实例化传入的实际类型
    构造单例的五种方法
    20162308 2017-2018-2 《程序设计与数据结构》第11周学习总结
    20162308 2017-2018-2 《程序设计与数据结构》第十周学习总结
  • 原文地址:https://www.cnblogs.com/xzz5211314/p/5142953.html
Copyright © 2011-2022 走看看