关灯游戏java代码_关灯游戏源码(iOS)

#import "ViewController.h"

#import "UIView+change.h"

@interfaceViewController ()

@property(assign,nonatomic)inttotalColums;

@property(assign,nonatomic)NSInteger tag;

@property(strong,nonatomic)UIButton*btn;@end

@implementationViewController- (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];

}else if(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];

}else if(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];

}else if (self.tag==4){

[[self.view viewWithTag:self.tag-1] change];

[[self.view viewWithTag:self.tag+self.totalColums] change];

}else if(self.tag==45-self.totalColums){

[[self.view viewWithTag:self.tag+1] change];

[[self.view viewWithTag:self.tag-self.totalColums] change];

}else if(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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值