//

//  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. 小程序:前端防止用户重复提交&即时消息(IM)重复发送问题解决

    背景: 最近参与开发的小程序,涉及到即时消息(IM)发送的功能: 聊天界面如下,通过键盘上的[发送]按钮,触发消息发送功能 问题发现: 功能开发完毕,进入测试流程:测试工程师反馈说: 在Android ...

  2. 为什么用Mysql?

    阅读目录 楔子 初识数据库 为什么要用数据库 认识数据库 初识mysql mysql概念 下载和安装 初识sql语句 楔子 假设现在你已经是某大型互联网公司的高级程序员,让你写一个火车票购票系统,来h ...

  3. 浅谈Python Web 框架:Django, Twisted, Tornado, Flask, Cyclone 和 Pyramid

    Django Django 是一个高级的 Python Web 框架,支持快速开发,简洁.实用的设计.如果你正在建一个和电子商务网站相似的应用,那你应该选择用 Django 框架.它能使你快速完成工作 ...

  4. POJ 1654 乱搞题?

    题意: 从一个点出发,8个方向,给出每一步的方向,求出走过的路径形成的多边形的面积. 思路: 先普及一下向量叉乘.. (摘自度娘) 也就是x1y2-x2y1. 那这不就好说了嘛. 一个经过原点的闭合多 ...

  5. lz的第一个RN项目

    这是lz 成功在原有项目上集成的第一个ReactNative 项目. 参考官方网址: http://reactnative.cn/docs/0.43/integration-with-existing ...

  6. Goldengate升级之目标端(replicat端)升级

    转自红黑联盟Goldengate升级之目标端(replicat端升级 要升级replicat端的原因为:目标端OGG软件版本与源端OGG软件版本不同,在实际生产应用中,经常发现replicat端事务丢 ...

  7. MemCached总结二:数据管理指令

    管理memcached中的数据包括添加(add).修改(set).删除(delete)及获取(get)等操作. 命令格式: 1.set set userId 0 0 5 12345 STORED ge ...

  8. C# 4.0新加特性

    协变和逆变 这个在C#2.0中就已经支持委托的协变和逆变了,C#4.0开始支持针对泛型接口的协变和逆变: IList<string> strings = new List<strin ...

  9. CorelDRAW快速制作绚丽的彩色透明心形

    今天小编分享给小伙伴们用CorelDRAW打造绚丽的彩色透明心形.主要使用完美形状组中的心形造型制作出心形图案,经过对图形的模糊操作,再经过图框精确剪裁,最后添加一个彩虹渐变色实现绚丽的彩色透明效果. ...

  10. JavaScript数组操作函数

    A: 购物车会有这样的情况,购物车是一个数组,每一个商品是一个对象,分别对应一个id,和一个num ,然后改变商品的时候需要和购物车对比,如果购物车中有这个商品的话,就只改变这个商品对应的id的num ...