//

//  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. php gd

    imagecopy() 函数用于拷贝图像或图像的一部分. imagecopyresized() 函数用于拷贝部分图像并调整大小. imagecopy() imagecopy() 函数用于拷贝图像或图像 ...

  2. Gym-101158J Cover the Polygon with Your Disk 计算几何 求动圆与多边形最大面积交

    题面 题意:给出小于10个点形成的凸多边形 和一个半径为r 可以移动的圆 求圆心在何处的面积交最大,面积为多少 题解:三分套三分求出圆心位置,再用圆与多边形面积求交 #include<bits/ ...

  3. 【Linux】YUM Repositories for CentOS, RHEL & Fedora Systems

    这里是官方wiki:https://wiki.centos.org/AdditionalResources/Repositories 一.简介 YUM(Yellowdog Updater Modifi ...

  4. A - Boy or Girl(set)

    Problem description Those days, many boys use beautiful girls' photos as avatars in forums. So it is ...

  5. WPF使用Winform PDFView控件

    最近开发wpf项目中有一个模块需要显示PDF文件内容.由于WPF本身没有PDF加载控件(似乎有收费的我查到过类似的资料.如果有新的pdf控件也请通知我一下谢谢). 项目使用之前也是从网上获取的资料,因 ...

  6. vue1.0.js的初步学习

    vue.js是一个mvvm框架 {{.....}}   常用模板渲染方式 v-model  :将对应变量的值的变化反映到input的vaule中 vue.js 的一个组件 .vue文件包含<te ...

  7. JDK1.7源码阅读tools包之------ArrayList,LinkedList,HashMap,TreeMap

    1.HashMap 特点:基于哈希表的 Map 接口的实现.此实现提供所有可选的映射操作,并允许使用 null 值和 null 键.(除了非同步和允许使用 null 之外,HashMap 类与 Has ...

  8. Ubuntu win8 小设备版本

    Ubuntu小设备支持列表:https://wiki.ubuntu.com/Touch/Devices win8 小设备 刷ubutntu:tieba.baidu.com/p/2772275438

  9. 8 Python+Selenium操作测试对象

    [环境信息] Python3.6+selenium3.0.2+Firefox50.0+win7 [操作方法] 1.清除输入框内容:clear() 2.单击一个按钮:click() 3.返回元素尺寸:s ...

  10. SPOJ-CRAN02 - Roommate Agreement(前缀和)

    CRAN02 - Roommate Agreement Leonard was always sickened by how Sheldon considered himself better tha ...