首页 / IOS / 关灯游戏源码(iOS)
关灯游戏源码(iOS)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了关灯游戏源码(iOS),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含6589字,纯文字阅读大概需要10分钟。
内容图文
就是点一下灯 它本身和周围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=50; CGFloat width=50; self.view.tag=1000; self.totalColums=5; CGFloat marginX=(self.view.frame.size.width-width*self.totalColums)/(self.totalColums+1); CGFloat marginY=30; for (int i=0; i<45; 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==0||self.tag%self.totalColums==4)&&(self.tag/self.totalColums!=0&&self.tag/self.totalColums!=8)) { [[self.view viewWithTag:self.tag+self.totalColums] change]; [[self.view viewWithTag:self.tag-self.totalColums] change]; if (self.tag%self.totalColums==0) { [[self.view viewWithTag:self.tag+1] change]; }elseif(self.tag%self.totalColums==4){ [[self.view viewWithTag:self.tag-1] change]; } } } /** * 最上面一行和最下面一行 */ -(void)hang{ if ((self.tag/self.totalColums==0||self.tag/self.totalColums==8)&&(self.tag%self.totalColums!=0&&self.tag%self.totalColums!=4)) { [[self.view viewWithTag:self.tag-1] change]; [[self.view viewWithTag:self.tag+1] change]; if (self.tag/self.totalColums==0) { [[self.view viewWithTag:self.tag+self.totalColums] change]; }elseif(self.tag/self.totalColums==8){ [[self.view viewWithTag:self.tag-self.totalColums] change]; } } } /** * 四个角 */ -(void)sigiao{ if (self.tag==0) { [[self.view viewWithTag:self.tag+1] change]; [[self.view viewWithTag:self.tag+self.totalColums] change]; }elseif (self.tag==4){ [[self.view viewWithTag:self.tag-1] change]; [[self.view viewWithTag:self.tag+self.totalColums] change]; }elseif(self.tag==45-self.totalColums){ [[self.view viewWithTag:self.tag+1] change]; [[self.view viewWithTag:self.tag-self.totalColums] change]; }elseif(self.tag==44){ [[self.view viewWithTag:self.tag-1] change]; [[self.view viewWithTag:self.tag-self.totalColums] change]; } } /** * 其他的 */ -(void)qita{ if (self.tag/self.totalColums!=0&&self.tag/self.totalColums!=8&&self.tag%self.totalColums!=0&&self.tag%self.totalColums!=4) { [[self.view viewWithTag:self.tag-self.totalColums]change]; [[self.view viewWithTag:self.tag-1]change]; [[self.view viewWithTag:self.tag+self.totalColums]change]; [[self.view viewWithTag:self.tag+1] 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=50; CGFloat width=50; self.view.tag=1000; self.totalColums=5; CGFloat marginX=(self.view.frame.size.width-width*self.totalColums)/(self.totalColums+1); CGFloat marginY=30; for (int i=0; i<45; 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==0||self.tag%self.totalColums==4)&&(self.tag/self.totalColums!=0&&self.tag/self.totalColums!=8)) { [[self.view viewWithTag:self.tag+self.totalColums] change]; [[self.view viewWithTag:self.tag-self.totalColums] change]; if (self.tag%self.totalColums==0) { [[self.view viewWithTag:self.tag+1] change]; }elseif(self.tag%self.totalColums==4){ [[self.view viewWithTag:self.tag-1] change]; } } } /** * 最上面一行和最下面一行 */ -(void)hang{ if ((self.tag/self.totalColums==0||self.tag/self.totalColums==8)&&(self.tag%self.totalColums!=0&&self.tag%self.totalColums!=4)) { [[self.view viewWithTag:self.tag-1] change]; [[self.view viewWithTag:self.tag+1] change]; if (self.tag/self.totalColums==0) { [[self.view viewWithTag:self.tag+self.totalColums] change]; }elseif(self.tag/self.totalColums==8){ [[self.view viewWithTag:self.tag-self.totalColums] change]; } } } /** * 四个角 */ -(void)sigiao{ if (self.tag==0) { [[self.view viewWithTag:self.tag+1] change]; [[self.view viewWithTag:self.tag+self.totalColums] change]; }elseif (self.tag==4){ [[self.view viewWithTag:self.tag-1] change]; [[self.view viewWithTag:self.tag+self.totalColums] change]; }elseif(self.tag==45-self.totalColums){ [[self.view viewWithTag:self.tag+1] change]; [[self.view viewWithTag:self.tag-self.totalColums] change]; }elseif(self.tag==44){ [[self.view viewWithTag:self.tag-1] change]; [[self.view viewWithTag:self.tag-self.totalColums] change]; } } /** * 其他的 */ -(void)qita{ if (self.tag/self.totalColums!=0&&self.tag/self.totalColums!=8&&self.tag%self.totalColums!=0&&self.tag%self.totalColums!=4) { [[self.view viewWithTag:self.tag-self.totalColums]change]; [[self.view viewWithTag:self.tag-1]change]; [[self.view viewWithTag:self.tag+self.totalColums]change]; [[self.view viewWithTag:self.tag+1] 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
运行效果
原文:http://www.cnblogs.com/qianLL/p/5256092.html
内容总结
以上是互联网集市为您收集整理的关灯游戏源码(iOS)全部内容,希望文章能够帮你解决关灯游戏源码(iOS)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。