就是点一下灯 它本身和周围4盏灯会变色

ViewController.m文件

#import "ViewController.h"
#import "UIView+change.h"
@interface ViewController ()
@property(assign,nonatomic)int totalColums; @property(assign,nonatomic)NSInteger tag;
@property(strong,nonatomic)UIButton *btn;
@end
@implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
CGFloat height=;
CGFloat width=;
self.view.tag=;
self.totalColums=; CGFloat marginX=(self.view.frame.size.width-width*self.totalColums)/(self.totalColums+);
CGFloat marginY=;
for (int i=; i<; i++) {
int row=i/self.totalColums;
int col=i%self.totalColums;
CGFloat appX=marginX+col*(width+marginX);
CGFloat appY=marginY+row*(height+marginY);
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(appX, appY, width, height)];
btn.backgroundColor=[UIColor redColor];
[btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchDown];
btn.tag=i;
[self.view addSubview:btn];
} }
/**
* 点击事件
*
*
*/
-(void)onClick:(UIButton *)btn{
[btn change];
self.btn=btn;
self.tag=btn.tag;
[self lie];
[self sigiao];
[self hang];
[self qita];
}
/**
* 最左边一列和最右边一列
*/
-(void)lie{ if ((self.tag%self.totalColums==||self.tag%self.totalColums==)&&(self.tag/self.totalColums!=&&self.tag/self.totalColums!=)) {
[[self.view viewWithTag:self.tag+self.totalColums] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
if (self.tag%self.totalColums==) {
[[self.view viewWithTag:self.tag+] change];
}else if(self.tag%self.totalColums==){
[[self.view viewWithTag:self.tag-] change];
}
}
}
/**
* 最上面一行和最下面一行
*/ -(void)hang{ if ((self.tag/self.totalColums==||self.tag/self.totalColums==)&&(self.tag%self.totalColums!=&&self.tag%self.totalColums!=)) {
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag+] change];
if (self.tag/self.totalColums==) {
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if(self.tag/self.totalColums==){
[[self.view viewWithTag:self.tag-self.totalColums] change];
}
} }
/**
* 四个角
*/
-(void)sigiao{ if (self.tag==) {
[[self.view viewWithTag:self.tag+] change];
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if (self.tag==){
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if(self.tag==-self.totalColums){
[[self.view viewWithTag:self.tag+] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
}else if(self.tag==){
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
}
}
/**
* 其他的
*/
-(void)qita{ if (self.tag/self.totalColums!=&&self.tag/self.totalColums!=&&self.tag%self.totalColums!=&&self.tag%self.totalColums!=) {
[[self.view viewWithTag:self.tag-self.totalColums]change];
[[self.view viewWithTag:self.tag-]change];
[[self.view viewWithTag:self.tag+self.totalColums]change];
[[self.view viewWithTag:self.tag+] change];
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
#import "ViewController.h"
#import "UIView+change.h"
@interface ViewController ()
@property(assign,nonatomic)int totalColums; @property(assign,nonatomic)NSInteger tag;
@property(strong,nonatomic)UIButton *btn;
@end
@implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
CGFloat height=;
CGFloat width=;
self.view.tag=;
self.totalColums=; CGFloat marginX=(self.view.frame.size.width-width*self.totalColums)/(self.totalColums+);
CGFloat marginY=;
for (int i=; i<; i++) {
int row=i/self.totalColums;
int col=i%self.totalColums;
CGFloat appX=marginX+col*(width+marginX);
CGFloat appY=marginY+row*(height+marginY);
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(appX, appY, width, height)];
btn.backgroundColor=[UIColor redColor];
[btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchDown];
btn.tag=i;
[self.view addSubview:btn];
} }
/**
* 点击事件
*
*
*/
-(void)onClick:(UIButton *)btn{
[btn change];
self.btn=btn;
self.tag=btn.tag;
[self lie];
[self sigiao];
[self hang];
[self qita];
}
/**
* 最左边一列和最右边一列
*/
-(void)lie{ if ((self.tag%self.totalColums==||self.tag%self.totalColums==)&&(self.tag/self.totalColums!=&&self.tag/self.totalColums!=)) {
[[self.view viewWithTag:self.tag+self.totalColums] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
if (self.tag%self.totalColums==) {
[[self.view viewWithTag:self.tag+] change];
}else if(self.tag%self.totalColums==){
[[self.view viewWithTag:self.tag-] change];
}
}
}
/**
* 最上面一行和最下面一行
*/ -(void)hang{ if ((self.tag/self.totalColums==||self.tag/self.totalColums==)&&(self.tag%self.totalColums!=&&self.tag%self.totalColums!=)) {
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag+] change];
if (self.tag/self.totalColums==) {
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if(self.tag/self.totalColums==){
[[self.view viewWithTag:self.tag-self.totalColums] change];
}
} }
/**
* 四个角
*/
-(void)sigiao{ if (self.tag==) {
[[self.view viewWithTag:self.tag+] change];
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if (self.tag==){
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if(self.tag==-self.totalColums){
[[self.view viewWithTag:self.tag+] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
}else if(self.tag==){
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
}
}
/**
* 其他的
*/
-(void)qita{ if (self.tag/self.totalColums!=&&self.tag/self.totalColums!=&&self.tag%self.totalColums!=&&self.tag%self.totalColums!=) {
[[self.view viewWithTag:self.tag-self.totalColums]change];
[[self.view viewWithTag:self.tag-]change];
[[self.view viewWithTag:self.tag+self.totalColums]change];
[[self.view viewWithTag:self.tag+] change];
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

类目文件UIView+change.h

#import <UIKit/UIKit.h>

@interface UIView (change)
/**
* 变颜色
*/
-(void)change;
@end

UIView+change.m

#import "UIView+change.h"

@implementation UIView (change)
-(void)change{
if (self.backgroundColor==[UIColor redColor]) {
self.backgroundColor=[UIColor blueColor];
}else{
self.backgroundColor=[UIColor redColor];
}
}
@end

运行效果

关灯游戏源码(iOS)的更多相关文章

  1. ios源码-ios游戏源码-ios源码下载

    游戏源码   一款休闲类的音乐小游戏源码 该源码实现了一款休闲类的音乐小游戏源码,该游戏的源码很简单,而且游戏的玩法也很容易学会,只要我们点击视图中的grid,就可以 人气:2943运行环境:/Xco ...

  2. iOS版打地鼠游戏源码

    打地鼠游戏源码,游戏是一款多关卡基于cocos2d的iPad打地鼠游戏源码,这也是一款高质量的打地鼠游戏源码,可以拥有逐步上升的关卡的设置,大家可以在关卡时设置一些商业化的模式来盈利的,非常完美的一款 ...

  3. ios跑酷游戏源码完整版

    今天在网上看到了一个很流行的ios游戏源码,酷跑游戏源码,个人下载感觉非常不错,运行起来非常不错的,大家可以研究一下吧,由于源码文件较大,没有上传,请大家见谅. 由于文件较大,没有上传了,大家可以到这 ...

  4. 卡通风格的连连看ios游戏源码

    卡通风格的连连看游戏源码,该游戏是一款韩国人做的卡通风格的ios连连看游戏源码,源码设计的效果非常漂亮的,而且运行起来感觉也很好.1.游戏采用倒计时模式2.该游戏是一款社交游戏,需要通过faceboo ...

  5. ios球体弹跳游戏源码

    一款耐玩的ios游戏源码,画面上有很多小星星,球体落下的时候,你需要在画面上画出一条条的线条让球体弹跳起来然后吃掉小星星,如果没借助球体就失败了.游戏有很多关卡.注意: <ignore_js_o ...

  6. 实例源码--IOS高仿微信打飞机游戏(完整功能)

    下载源码 技术要点: 1. IOS游戏开发基础框架 2. 高仿打飞机游戏 3. 游戏背景音频技术 4.源码详细的中文注释 ……. 详细介绍: 1. IOS游戏开发基础框架 此套源码为涉及IOS游戏开发 ...

  7. 比较不错的一个ios找茬游戏源码

    找茬游戏源码 ,这个是一款非常不错的ios找茬游戏源码,该游戏的兼容性非常好的,并且还可以支持ipad和iphone,UI界面设计得也很漂亮,游戏源码真的是一款非常完美,而且又很完整的一款休闲类的游戏 ...

  8. ios版弹珠游戏源码

    这个是我们比较喜欢玩的一直小游戏的,ios版弹珠游戏源码,该游戏源码来着IOS教程网其他网友提供上传的,大家可以了解一下吧. nore_js_op>     <ignore_js_op&g ...

  9. ios水果风暴游戏源码下载

    游戏源码是从那个IOS教程网IOS.662p.com分享给大家的. 这是一款ios水果风暴游戏源码下载,介绍给大家一下,喜欢的朋友可以下载学习一下吧.应用介绍:这是一个以获得高分和挑战更高难度为目的的 ...

随机推荐

  1. RESTful API 设计指南【转】

    网络应用程序,分为前端和后端两个部分.当前的发展趋势,就是前端设备层出不穷(手机.平板.桌面电脑.其他专用设备......). 因此,必须有一种统一的机制,方便不同的前端设备与后端进行通信.这导致AP ...

  2. AssetBundle系列——共享资源打包/依赖资源打包

    有人在之前的博客中问我有关共享资源打包的代码,其实这一块很简单,就两个函数: BuildPipeline.PushAssetDependencies():依赖资源压栈: BuildPipeline.P ...

  3. 【干货分享】Google 的设计准则,素材和资源

    在谷歌,他们说, “专注于用户,所有其它的就会水到渠成 ”.他们遵循设计原则,寻求建立让用户惊喜的用户体验.谷歌一直挑战自己,为他们的用户创造一种视觉语言,综合优秀设计的经典原则和创新.谷歌设计规范是 ...

  4. iOS-UIButton-文字位置,字体大小,边角样式,button种类,点击事件,内容位置

    一. 设置button的文字居左,居中,居右 //设置button居左 button.contentHorizontalAlignment = UIControlContentHorizontalAl ...

  5. LeetCode——Contains Duplicate III

    Description: Given an array of integers, find out whether there are two distinct indices i and j in ...

  6. sqlite3存储格式

    本篇介绍sqlite3数据库文件的存储格式.通过阅读源读源代码可以知道sqlite的设计思想.一个sqlite数据库文件对应着一个数据库.sqlite将数据库文件划分大小一致的存储(以区分内存)页面, ...

  7. iOS 9.2新增API

    CloudKit 新增CKFetchWebAuthTokenOperation类 CKFetchWebAuthTokenOperation对象从使用指定的cloudkit中的APIToken获取一个w ...

  8. 存储过程分页 Ado.Net分页 EF分页 满足90%以上

    存储过程分页: create proc PR_PagerDataByTop @pageIndex int, @pageSize int, @count int out as select top(@p ...

  9. Sql发布订阅设置不初始化订阅库架构的设置

    参考:http://www.cnblogs.com/TeyGao/p/3521231.html

  10. sql where 1=1和 0=1 的作用

    sql where 1=1和 0=1 的作用 摘自: http://www.cnblogs.com/junyuz/archive/2011/03/10/1979646.html where 1=1; ...