//

//  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. 线段树(1)——点修改&建树

    #include<cstdio> #include<algorithm> using namespace std; #define MAX 10000 #define INF ...

  2. C# txt文件操作

    //打开文件到流 FileStream fs=new FileStream(path,FileMode.Open,FileAccess.ReadWrite); //写文件流的方法 StreamWrit ...

  3. C#中DBNull问题

    当数据库中一个字段不是必填项时,在往数据库中插入数据的时候往往会插入一个空字符串就草草了事了.在这里用DBNull可以解决这个问题 /// <summary> /// 插入数据 /// & ...

  4. WindowsNT设备驱动程序开发基础

    一.背景介绍 1.1WindowsNT操作系统的组成1.1.1用户模式(UserMode)与内核模式(KernelMode) 从Intel80386开始,出于安全性和稳定性的考虑,该系列的CPU可以运 ...

  5. 优动漫PAINT是什么?有哪些功能和特色

    优动漫PAINT软件介绍: 优动漫PAINT是一款功能强大的漫画制作软件,该软件可以帮助漫画创作人员制作出完美,惟妙惟肖的漫画作品,它搭载了绘制漫画和插画所需的所有功能--丰富的笔工具.超强的笔压感应 ...

  6. Java常用工具类---XML工具类、数据验证工具类

    package com.jarvis.base.util; import java.io.File;import java.io.FileWriter;import java.io.IOExcepti ...

  7. vue 绑定 HTML Class

    绑定 HTML Class

  8. Project Euler 27 Quadratic primes( 米勒测试 + 推导性质 )

    题意: 欧拉发现了这个著名的二次多项式: f(n) = n2 + n + 41 对于连续的整数n从0到39,这个二次多项式生成了40个素数.然而,当n = 40时402 + 40 + 41 = 40( ...

  9. nmcli 静态方式添加IP地址

    [root@ansible02:/root] > ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state U ...

  10. Tensorflow 之物体检测

    1)安装Protobuf TensorFlow内部使用Protocol Buffers,物体检测需要特别安装一下. # yum info protobuf protobuf-compiler 2.5. ...