//

//  ViewController.m

//  UI-猜拳游戏

//

//  Created by jzq_mac on 15/7/15.

//  Copyright (c) 2015年 jzq_mac. All rights reserved.

//

#import
"ViewController.h"

#define  TIME

@interface
ViewController ()

{

UILabel *timeLable;

UILabel *scoreLable;

UILabel *observeLable;

UIImageView *imgeView;

UIImageView *imgeView1;

UIButton *button;

int score;

int time;

int number;

NSTimer *timer;

NSArray *imageList;

NSArray *buttonImageList;

NSArray *faceList;

BOOL Start;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super
viewDidLoad];

//   
设置背景图

UIImageView *imageView = [[UIImageView
alloc]initWithFrame:[UIScreen
mainScreen].bounds];

imageView.image = [UIImage
imageNamed:@"钱.png"];

[self.view
addSubview:imageView];

imageList =
@[@"石头.png",@"剪刀.png",@"布.png"];

buttonImageList =
@[@"石头1.png",@"剪刀1.png",@"布1.png"];

faceList =
@[@"哭.png",@"笑.png",@"挣扎.png"];

//创建笑脸视图

imgeView1 = [[UIImageView
alloc,
,
)];

imgeView1.image = [UIImage
imageNamed:@"美女1.png"];

[self.view
addSubview:imgeView1];

time = TIME;

//  
调用视图

[self
creatView];

[self
flashView];

[self
creatButon];

//   
定时器

timer = [NSTimer
target:self selector:@selector(flashView) userInfo:
nil repeats:YES];

[[NSRunLoop
currentRunLoop]addTimer:timer forMode:NSDefaultRunLoopMode];

timer.fireDate = [NSDate
distantFuture];

timeLable.text = [NSString
stringWithFormat:@"时间: %d
秒",time];

}

//创建视图

- (void)creatView

{

scoreLable = [[UILabel
alloc,
,
)];

[self.view
addSubview:scoreLable];

scoreLable.text = [NSString
stringWithFormat:@"得分: %d
分",score];

scoreLable.textColor = [UIColor
blueColor];

scoreLable.backgroundColor = [UIColor
grayColor];

scoreLable.textAlignment =
NSTextAlignmentCenter;

scoreLable.alpha =
0.4;

timeLable = [[UILabel
alloc,
,
)];

[self.view
addSubview:timeLable];

timeLable.backgroundColor = [UIColor
grayColor];

timeLable.textColor = [UIColor
blueColor];

timeLable.textAlignment =
NSTextAlignmentCenter;

timeLable.text = [NSString
stringWithFormat:@"时间: %d
秒",time];

timeLable.alpha =
0.4;

observeLable = [[UILabel
alloc,
,
CGRectGetHeight([UIScreen
mainScreen].bounds),
)];

[self.view
addSubview:observeLable];

observeLable.backgroundColor = [UIColor
grayColor];

observeLable.alpha =
0.6;

//    observeLable.textAlignment = NSTextAlignmentCenter;

observeLable.font = [UIFont
boldSystemFontOfSize];

observeLable.text =
@"    ~~~人
机 猜
拳 大
战~~~ ";

}

//闪烁图片

- (void)flashView

{

time--;

timeLable.text = [NSString
stringWithFormat:@"时间: %d
秒",time];

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

imgeView = [[UIImageView
alloc +
*i,
,
)];

imgeView.image = [UIImage
imageNamed:@"美女.png"];

[self.view
addSubview:imgeView ];

int r = arc4random()%imageList.count;

number  = r;

imgeView.image = [UIImage
imageNamed:imageList[r]];

}

if (time ==
) {

timer.fireDate = [NSDate
distantFuture];

UIAlertView *alert = [[UIAlertView
alloc]initWithTitle:@"大家一起猜" message:@"时间到"
delegate:self cancelButtonTitle:nil otherButtonTitles:@"不服就再来啊",
nil];

[alert show];

}

}

//创建button

- (void)creatButon

{

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

button = [[UIButton
alloc +
*i,
,
)];

[self.view
addSubview:button];

[button
setBackgroundImage:[UIImage
imageNamed:buttonImageList[i]] forState:UIControlStateNormal];

button.backgroundColor = [UIColor
redColor];

button.layer.cornerRadius =
;

button.layer.masksToBounds =
YES;

button.alpha =
0.6;

button.;

[button
addTarget:self action:@selector(selectButton:) forControlEvents:UIControlEventTouchUpInside];

}

UIButton *startButton = [[UIButton
alloc,
,
)];

[self.view
addSubview:startButton];

[startButton
setBackgroundImage:[UIImage
imageNamed:@"開始.png"] forState:UIControlStateNormal];

[startButton
setTitle:@"開始" forState:UIControlStateNormal];

[startButton
setTitleColor:[UIColor
blackColor] forState:UIControlStateNormal];

[startButton
addTarget:self action:@selector(startGame:) forControlEvents:UIControlEventTouchUpInside];

}

//開始游戏

- (void)startGame:(UIButton *)sender

{

if (sender.selected !=YES) {

timer.fireDate = [NSDate
distantPast];

[sender
setTitle:@"暂停" forState:UIControlStateNormal];

sender.selected =
YES;

Start = YES;

}else

{

timer.fireDate = [NSDate
distantFuture];

[sender
setTitle:@"開始" forState:UIControlStateNormal];

sender.selected =
NO;

Start = NO;

}

}

//选择button的触发事件

- (void)selectButton:(UIButton *)sender

{

if (Start !=
NO) {

//        sender.showsTouchWhenHighlighted = YES;

if (sender.) {

if () {

imgeView1.image = [UIImage
]];

}else
if(number ==
){

imgeView1.image = [UIImage
]];

score ++;

scoreLable.text = [NSString
stringWithFormat:@"总分: %d
分",score];

}else
if (number ==
){

imgeView1.image = [UIImage
]];

}

}

if (sender.) {

if () {

imgeView1.image = [UIImage
]];

}else
if(number ==
){

imgeView1.image = [UIImage
]];

}else
if (number ==
){

imgeView1.image = [UIImage
]];

score ++;

scoreLable.text = [NSString
stringWithFormat:@"总分: %d
分",score];

}

}

if (sender.) {

if () {

imgeView1.image = [UIImage
]];

score ++;

scoreLable.text = [NSString
stringWithFormat:@"总分: %d
分",score];

}else
if(number ==
){

imgeView1.image = [UIImage
]];

}else
if (number ==
){

imgeView1.image = [UIImage
]];

}

}

}

}

//弹窗事件

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

if (buttonIndex ==
) {

score = ;

time = TIME;

scoreLable.text = [NSString
stringWithFormat:@"总分: %d
分",score];

timeLable.text = [NSString
stringWithFormat:@"时间:%d
秒",time];

timer.fireDate = [NSDate
distantPast];

}else{

timer.fireDate = [NSDate
distantPast];

}

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end


ios-UI-汤姆猫德游戏实现的更多相关文章

  1. [UI基础][不会说话的汤姆猫]

    会说话的汤姆猫这个APP层级风靡一时,其UI部分就是利用了序列动画的技术, 接下来 我们用汤姆猫来演示怎么制作序列动画. [要求]: 1.学会使用序列动画的方法 2.学会分析动画播放中内存占用高的问题 ...

  2. [iOS基础控件 - 3.4] 汤姆猫

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...

  3. 声音变调算法PitchShift(模拟汤姆猫) 附完整C++算法实现代码

    上周看到一个变调算法,挺有意思的,原本计划尝试用来润色TTS合成效果的. 实测感觉还需要进一步改进,待有空再思考改进方案. 算法细节原文,移步链接: http://blogs.zynaptiq.com ...

  4. iOS- 利用UIImageView自己整了个不会说话的汤姆猫

    1.实现思路 先说说我实现它的主要思路,很简单,主要利用UIImageView连续动画播放,和按钮的点击事件,就可以完成了这么一个简单的不会说话的汤姆猫. 2.实现细节 2.1.加载本地字典里保存的本 ...

  5. IOS 汤姆猫核心代码

    // // MJViewController.m // 03-Tom // // Created by apple on 13-11-24. // Copyright (c) 2013年 itcast ...

  6. 156 UIImageView 和 CADisplayLink 实现 Tom 汤姆猫动画效果的区别(扩展知识:分组(黄色文件夹)和文件夹引用(蓝色文件夹)区别)

    (1)UIImageView 的动画操作,来自定义循环播放动画(不建议使用,内存消耗大) (2)CADisplayLink 是一个计时器,但是同 NSTimer 不同的是,CADisplayLink ...

  7. 使用UISegementControl实现简易汤姆猫程序

    // // TomViewController.m #import "TomViewController.h" #import <AVFoundation/AVFoundat ...

  8. iOS_5_汤姆猫

    终于效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill ...

  9. 【Web网站服务器开发】apache和tomcat 阿帕奇和汤姆猫

    经常在用apache和tomcat等这些服务器,可是总感觉还是不清楚他们之间有什么关系,在用tomcat的时候总出现apache,总感到迷惑,到底谁是主谁是次,因此特意在网上查询了一些这方面的资料,总 ...

随机推荐

  1. HTTP请求与请求头

    HTTP 的请求报文分为三个部分 请求行.请求头和请求体,格式如图:一个典型的请求消息头域,如下所示: POST/GET http://download.microtool.de:80/somedat ...

  2. ROW_NUMBER() OVER()函数用法;(分组,排序),partition by (转)

    1.row_number() over()排序功能: (1) row_number() over()分组排序功能: 在使用 row_number() over()函数时候,over()里头的分组以及排 ...

  3. webpack-1

    1.webpack 安装新项目npm install --save-dev webpack如果版本较老,在package,json中找到版本号,修改成你要的版本号,在删除node-model文件夹,执 ...

  4. IP地址与十进制相互转换

    1.IP 转成10进制 function ipToInt(ip){ var REG =/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4] ...

  5. 记一个男默女泪的 BUG

    姗姗来迟的词频统计代码 BUG 的发现 1. 此前提交的第一次代码作业总结博客 http://www.cnblogs.com/ustczwq/p/8680704.html 2. BUG 本天成,妙手偶 ...

  6. sphinx with discuz

    安装sphinx: sudo apt-get install sphinxsearch 配置: source discuz { type = mysql sql_host = xx.xx.xx.xx ...

  7. Ext未定义问题解决

    做的项目用到EXT.NET,调试时候没问题,发布到IIS上出现EXT未定义,把项目的应用程序池改为Classic 模式就可以了.

  8. 避免关注底层硬件,Nvidia将机器学习与GPU绑定

    Nvidia释放的一组cuDNN的库,有效的实现了其与多种深度学习框架的整合.基于cuDNN,加速了代码的运行,同时让研究员避免去关心底层硬件性能. 关键字: 编程语言语音识别Nvidia 原文链接: ...

  9. OpenCV_Python教程 系列!

    这个是作者的总结系列!赞一个! 原文链接:http://blog.csdn.net/sunny2038/article/details/9057415 在python中使用OpenCV:http:// ...

  10. 如何修改wifi为家庭网络

    一不小心手快,把新链接的 wifi 选择成“公用网络”了,使用过程中导致某些应用无法联网,那个恨呐!!! 幸好,咱们可以进行手工更改,哈哈,跟哥一起来操作: 进入”网络与共享中心界面": 选 ...