简单的猜拳游戏
2015-07-29 11:21
323 查看
<span style="font-size:24px;">// // ZYAppDelegate.m // CaiGame // // Created by mac on 15-7-29. // Copyright (c) 2015年 zhiyou. All rights reserved. // #import "ZYAppDelegate.h" @implementation ZYAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; // 创建一个试图并初始化,让其背景图片为1.jpg UIImageView *imageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.jpg"]]; imageView.frame=self.window.frame; [self.window addSubview:imageView]; // label全局变量 label=[[UILabel alloc] initWithFrame:CGRectMake(90, 20, 160, 30)]; label.text=@"欢迎来到猜拳游戏"; label.textColor=[UIColor greenColor]; [imageView addSubview:label]; btn1=[UIButton buttonWithType:UIButtonTypeCustom]; btn1.frame=CGRectMake(20, 100, 80, 100); btn1.backgroundColor=[UIColor whiteColor]; [imageView addSubview:btn1]; UIButton *btn2=[UIButton buttonWithType:UIButtonTypeCustom]; btn2.frame=CGRectMake(120, 100, 80, 100); btn2.backgroundColor=[UIColor whiteColor]; [btn2 setImage:[UIImage imageNamed:@"vs.gif"] forState:UIControlStateNormal]; [imageView addSubview:btn2]; btn3=[UIButton buttonWithType:UIButtonTypeCustom]; btn3.frame=CGRectMake(220, 100, 80, 100); btn3.backgroundColor=[UIColor whiteColor]; [imageView addSubview:btn3]; UIButton *jianDao=[UIButton buttonWithType:UIButtonTypeCustom]; jianDao.frame=CGRectMake(90, 350, 35, 70); [jianDao setImage:[UIImage imageNamed:@"jiandao.gif"] forState:UIControlStateNormal]; jianDao.backgroundColor=[UIColor redColor]; jianDao.tag=10086; [jianDao addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside]; [self.window addSubview:jianDao]; UIButton *bu=[UIButton buttonWithType:UIButtonTypeCustom]; bu.frame=CGRectMake(130, 350, 35, 70); [bu setImage:[UIImage imageNamed:@"bu.gif"] forState:UIControlStateNormal]; bu.backgroundColor=[UIColor redColor]; bu.tag=100861; [bu addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside]; [self.window addSubview:bu]; UIButton *shitou=[UIButton buttonWithType:UIButtonTypeCustom]; shitou.frame=CGRectMake(170, 350, 35, 70); [shitou setImage:[UIImage imageNamed:@"shitou.gif"] forState:UIControlStateNormal]; shitou.backgroundColor=[UIColor blueColor]; shitou.tag=100862; [shitou addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside]; [self.window addSubview:shitou]; return YES; } -(void)onClick:(UIButton *)btn { int num=arc4random()%3; if (btn.tag==10086) { [btn3 setImage:[UIImage imageNamed:@"jiandao.gif"] forState:UIControlStateNormal]; switch (num) { case 0: [btn1 setImage:[UIImage imageNamed:@"jiandao.gif"] forState:UIControlStateNormal]; label.text=@"你居然猜的一样"; break; case 1: [btn1 setImage:[UIImage imageNamed:@"shitou.gif"] forState:UIControlStateNormal]; label.text=@"小猪你输了"; break; case 2: [btn1 setImage:[UIImage imageNamed:@"bu.gif"] forState:UIControlStateNormal]; label.text=@"小样儿你真棒"; break; } } if (btn.tag==100861) { [btn3 setImage:[UIImage imageNamed:@"bu.gif"] forState:UIControlStateNormal]; switch (num) { case 0: [btn1 setImage:[UIImage imageNamed:@"jiandao.gif"] forState:UIControlStateNormal]; label.text=@"小猪你输了"; break; case 1: [btn1 setImage:[UIImage imageNamed:@"shitou.gif"] forState:UIControlStateNormal]; label.text=@"小样儿你真棒"; break; case 2: [btn1 setImage:[UIImage imageNamed:@"bu.gif"] forState:UIControlStateNormal]; label.text=@"你居然猜的一样"; break; } } if (btn.tag==100862) { [btn3 setImage:[UIImage imageNamed:@"shitou.gif"] forState:UIControlStateNormal]; switch (num) { case 0: [btn1 setImage:[UIImage imageNamed:@"jiandao.gif"] forState:UIControlStateNormal]; label.text=@"小样儿你真棒"; break; case 1: [btn1 setImage:[UIImage imageNamed:@"shitou.gif"] forState:UIControlStateNormal]; label.text=@"你居然猜的一样"; break; case 2: [btn1 setImage:[UIImage imageNamed:@"bu.gif"] forState:UIControlStateNormal]; label.text=@"小猪你输了"; break; } } } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end </span>
相关文章推荐
- Lua 基础:调用函数时用点号还是用冒号
- CSS中让一个div的高度随着另外个一个统计的div的高度变化而变化的代码
- 浏览器下的网页全屏尺寸
- CSS中让一个div的高度随着另外个一个统计的div的高度变化而变化的代码
- POJ 1961
- 自定义可以滑动的RelativeLayout, 可以右滑退出activity ,左滑进入新的activity
- LeetCode_114 Flatten Binary Tree to Linked List
- ubuntu14.10搭建NDK环境
- JavaScript学习要点(十一)
- AD架构设计的一些笔记
- 在线编辑器CKEditor,多图上传功能实现
- LeetCode Reverse Linked List II 反置链表2
- Android-async-http 例子
- iOS 手势识别器概述
- Js解决ie6不支持fixed的方法
- [c++]MFC学习
- poj 2175 最小费用最大流TLE
- OC完全解读:Foundation框架下的NSValue,NSNumber ,NSNull,NSData,NSCalendarDate
- Cocos2dx之精灵创建
- 华为机试2013届上机--子串分离