#import "RootViewController.h"

@interface RootViewController ()
{
    UILabel *scoreLabel;

}

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //longSlider
    UISlider *longSlider = [[UISlider alloc] initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, 40)];
    longSlider.tag = 101;
    longSlider.maximumValue = 100;
    longSlider.minimumValue = 0;
    longSlider.userInteractionEnabled = NO;
    longSlider.value = arc4random() % 101;
    //[longSlider addTarget:self action:@selector(longSlider:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:longSlider];
    [longSlider release];
    
    //shortSlider
    UISlider *shortSlider = [[UISlider alloc] initWithFrame:CGRectMake(0, 120, self.view.frame.size.width - 100, 40)];
    shortSlider.tag = 102;
    shortSlider.maximumValue = 100;
    shortSlider.minimumValue = 0;
    [self.view addSubview:shortSlider];
    [shortSlider release];
    
    
    UILabel *showLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 200, 40, 40)];
    showLabel.text = @"得分";
    [self.view addSubview:showLabel];
    [showLabel release];
    
    scoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 200, 40)];
    scoreLabel.tag = 103;
    scoreLabel.layer.borderWidth = 2;
    scoreLabel.layer.borderColor = [UIColor redColor].CGColor;
    scoreLabel.layer.cornerRadius = 10;
    [self.view addSubview:scoreLabel];
    [scoreLabel release];
    
    UIButton *okButton = [UIButton buttonWithType:UIButtonTypeSystem];
    okButton.frame = CGRectMake(40, 300, 100, 50);
    [okButton setTitle:@"OK" forState:UIControlStateNormal];
    okButton.layer.borderWidth = 2;
    okButton.layer.cornerRadius = 10;
    [okButton addTarget:self action:@selector(okButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:okButton];
    
    
    UIButton *againButton = [UIButton buttonWithType:UIButtonTypeSystem];
    againButton.frame = CGRectMake(220, 300, 100, 50);
    [againButton setTitle:@"重新" forState:UIControlStateNormal];
    againButton.layer.borderWidth = 2;
    againButton.layer.cornerRadius = 10;
    [againButton addTarget:self action:@selector(pressButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:againButton];
    
    
    
    // Do any additional setup after loading the view.
}

- (void)okButton:(UIButton *)aButton
{
    UISlider *lSlider = (UISlider *)[self.view viewWithTag:101];
    UISlider *sSlider = (UISlider *)[self.view viewWithTag:102];
    UILabel *lable = (UILabel *)[self.view viewWithTag:103];
    sSlider.userInteractionEnabled = NO;
    if (lSlider.value == sSlider.value) {
        lable.text = @"100";
        UIAlertView *aa = [[UIAlertView alloc] initWithTitle:@"提示" message:@"不是人" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [aa show];
        [aa release];
    } else {
    
        float temp = 100 - abs((int)(lSlider.value - sSlider.value)) * 5;
        if (temp > 90 && temp < 100) {
            UIAlertView *aa = [[UIAlertView alloc] initWithTitle:@"提示" message:@"牛人" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [aa show];
            [aa release];
        } else if (temp > 80 && temp < 90) {
        
            UIAlertView *aa = [[UIAlertView alloc] initWithTitle:@"提示" message:@"眼力不错" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [aa show];
            [aa release];
        
        } else if (temp > 60 && temp < 80) {
        
            UIAlertView *aa = [[UIAlertView alloc] initWithTitle:@"提示" message:@"一般" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [aa show];
            [aa release];

} else {
        
            UIAlertView *aa = [[UIAlertView alloc] initWithTitle:@"提示" message:@"眼瞎了吧!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [aa show];
            [aa release];

}
    
        scoreLabel.text = [NSString stringWithFormat:@"%.2f", temp];
    }

}
- (void)pressButton
{
    
    UISlider *slider = (UISlider *)[self.view viewWithTag:101];
    //slider.value = arc4random() % 101;
    [slider setValue:arc4random() % 61 + 20 animated:YES];
    UISlider *sSlider = (UISlider *)[self.view viewWithTag:102];
    sSlider.userInteractionEnabled = YES;
    sSlider.value = 0;
    
    UILabel *lable = (UILabel *)[self.view viewWithTag:103];
    lable.text = @"0";
   // [slider setValue:arc4random() animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

UI通过UISlider编写游戏第六感的更多相关文章

  1. OCulus Rift 游戏开发六原则

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/46685477 作者:car ...

  2. 使用 jQuery UI Widget Factory 编写有状态的插件(Stateful Plugins)

    使用 jQuery UI Widget Factory 编写有状态的插件(Stateful Plugins) Note 这一章节的内容是基于 Scott Gonzalez 一篇博客 Building ...

  3. Python turtle 模块可以编写游戏,是真的吗?

    1. 前言 turtle (小海龟) 是 Python 内置的一个绘图模块,其实它不仅可以用来绘图,还可以制作简单的小游戏,甚至可以当成简易的 GUI 模块,编写简单的 GUI 程序. 本文使用 tu ...

  4. jQuery 使用 jQuery UI 部件工厂编写带状态的插件(翻译)

    首先,我们要创建一个progress bar,它只允许我们简单的设置进度值.正如我们接下来将要看到的,我们需要通过调用 jQuery.widget 及其两个参数来实现这一操作,这两个参数分别是:将要创 ...

  5. UGUI世界坐标转换为UI本地坐标(游戏Hud的实现)

    实现世界坐标的原理是: 世界坐标和UGUI的坐标分属两个坐标系,他们之间是无法进行转换的,需要通过屏幕坐标系来进行转换(因为屏幕坐标是固定的),即先将游戏场景中的世界坐标通过游戏场景Camera转化为 ...

  6. python基础----以面向对象的思想编写游戏技能系统

    1. 许多程序员对面向对象的思想都很了解,并且也能说得头头是道,但是在工作运用中却用的并不顺手. 当然,我也是其中之一. 不过最近我听了我们老师的讲课,对于面向对象的思想有了更深的理解,今天决定用一个 ...

  7. AJ学IOS(06)UI之iOS热门游戏_超级猜图

    AJ分享,必须精品 先看效果图 思路 需求分析 1,搭建界面 1>上半部分,固定的,用Storyboard直接连线(OK) 2>下半部分,根据题目的变化,不断变化和调整,用代码方式实现比较 ...

  8. 使用Xamarin开发移动应用示例——数独游戏(六)使用数据库

    项目代码可以从Github下载:https://github.com/zhenl/ZL.Shudu .代码随项目进度更新. 现在我们希望为应用增加更多的功能,比如记录每个完成的游戏,可以让用户自己添加 ...

  9. 解读Unity中的CG编写Shader系列六(漫反射)

    转自 http://www.itnose.net/detail/6116553.html 如果前面几个系列文章的内容过于冗长缺乏趣味着实见谅,由于时间原因前面的混合部分还没有写完,等以后再补充,现在开 ...

随机推荐

  1. 服务端渲染 SSR

    1.概述 SSR:网站内容由服务端渲染,然后返回客户端(查看网页源代码,所有内容都在源代码里面). 2.SSR优势 (1)SSR利于SEO. (2)SSR减少请求量和客户端渲染时间.

  2. C语言字符串操作总结大全(超具体)

    1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, p1) 附加字符串 strncat(p, p1, n) 附加指定长度 ...

  3. 解决安装Ubuntu之后找不到无线网卡驱动的问题

    为了不浇灭大家尝试ubuntu的冲动,昨天我安装了ubuntu 14.04 LTS版本号,从安装到又一次开机都非常顺利.PS:不会安装的请找教程区把,网上非常多,CSDN论坛都有. 安装之后当你奇妙的 ...

  4. cookie 与 session 的差别、联系

    1.存放位置: Session 存放在server端. Cookie 存放在client: 2.保存形式: Session保存在server的内存中(在server端设置超时时间,与浏览器设置无关): ...

  5. Eclipse安装Properties Editore插件

    Properties Editor for Eclipse3[1].0-3.2安装使用-http://jzgl-javaeye.iteye.com/blog/386010 PropertiesEdit ...

  6. linux 查看cpu相关信息命令

  7. atitit.Atitit.检测文本文件的编码 java  与php版  。Net

    atitit.Atitit.检测文本文件的编码 java  与php版  .Net 1 检测编码原理 Utf8>>gbk 在此转会gbk>>utf 2 工具检测编码 不能使用l ...

  8. Eclipse RCP应用开发(概念)

    学习Eclipse RCP应用开发,对其中一些相关的概念需要了解. 让我们在讲解概念前先思考两个问题. 问题一.什么是Eclipse 大部分同学会回答eclipse是IBM公司开发的java集成开发环 ...

  9. 60. Search Insert Position 【easy】

    60. Search Insert Position [easy] Given a sorted array and a target value, return the index if the t ...

  10. 封装ShareSDK中的分享功能封以及对类似第三方功能封装的心得【原创】

    本篇的主题有三个: 1.封装思想的介绍 2.我的封装代码 3.我在封装sharesdk(采用的是简洁版本)分享功能是碰到的问题,以及解决方法. PS:其实这个我之前封装过一次,不过最近在重构项目时发现 ...